Plugin Directory

Changeset 1210109


Ignore:
Timestamp:
07/31/2015 02:51:39 AM (11 years ago)
Author:
postpostmodern
Message:

version 0.6.1

Location:
taxonomy-taxi-2-electric-boogaloo/trunk
Files:
1 added
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • taxonomy-taxi-2-electric-boogaloo/trunk/_plugin.php

    r977975 r1210109  
    44Plugin URI:     
    55Description:   
    6 Version:        .3
     6Version:        .5
    77Author:         postpostmodern, pinecone-dot-io
    88Author URI:
     
    1111register_activation_hook( __FILE__, create_function("", '$ver = "5.3"; if( version_compare(phpversion(), $ver, "<") ) die( "This plugin requires PHP version $ver or greater be installed." );') );
    1212
    13 register_activation_hook( __FILE__, 'taxonomytaxi\electric_boogaloo\activate' );
    14 register_deactivation_hook( __FILE__, 'taxonomytaxi\electric_boogaloo\deactivate' );
     13register_activation_hook( __FILE__, '\taxonomytaxi\electric_boogaloo\activate' );
     14register_deactivation_hook( __FILE__, '\taxonomytaxi\electric_boogaloo\deactivate' );
    1515
    1616require __DIR__.'/index.php';
  • taxonomy-taxi-2-electric-boogaloo/trunk/index.php

    r977975 r1210109  
    33namespace taxonomytaxi\electric_boogaloo;
    44
    5 require __DIR__.'/taxo-taxi-2.php';
     5require __DIR__.'/activation.php';
    66
    77/*
    8 *   called on activation hook
     8*
     9*   @param string
     10*   @param int|object
     11*   @param string
     12*   @param string
    913*/
    10 function activate(){
    11     \TaxoTaxi2ElecBoog::setup();
    12     flush_rewrite_rules( FALSE );
     14function get_edit_term_link( $location, $term_id, $taxonomy, $object_type ){
     15    if( !is_object($term_id) || $term_id->term_id != 0 )
     16        return $location;
     17   
     18    $args = array(
     19        'taxonomy' => $taxonomy,
     20    );
     21   
     22    if( trim($object_type) )
     23        $args['post_type'] = $object_type;
     24       
     25    $location = add_query_arg( $args, admin_url('edit-tags.php') );
     26   
     27    return $location;
     28}
     29add_filter( 'get_edit_term_link', __NAMESPACE__.'\get_edit_term_link', 10, 4 );
     30
     31/*
     32*
     33*   @param string
     34*   @return string
     35*/
     36function queried_taxonomy( $query = NULL ){
     37    static $queried_taxonomy = NULL;
     38   
     39    if( $query )
     40        $queried_taxonomy = $query;
     41   
     42    return $queried_taxonomy;
    1343}
    1444
    1545/*
    16 *   called on deactivation hook
     46*   
     47*   @param WP_Query
     48*   @return string 
    1749*/
    18 function deactivate(){
    19     flush_rewrite_rules( FALSE );
     50function parse_query( &$wp_query ){
     51    if( isset($wp_query->tax_query->queries[0]) ){
     52        queried_taxonomy( $wp_query->tax_query->queries[0]['taxonomy'] );
     53    }
     54   
     55    return $wp_query;
    2056}
     57add_filter( 'parse_query', __NAMESPACE__.'\parse_query' );
     58
     59/*
     60*
     61*/
     62function posts_request( $sql, $wp_query ){
     63    //dbug( $sql );
     64    return $sql;
     65}
     66add_filter( 'posts_request', __NAMESPACE__.'\posts_request', 10, 2 );
     67
     68/*
     69*
     70*/
     71function pre_get_posts( $wp_query ){
     72    $queried_taxonomy = queried_taxonomy();
     73
     74    if( isset($wp_query->query_vars[$queried_taxonomy]) && ($wp_query->query_vars[$queried_taxonomy] == 'show-all-terms') ){
     75        global $wpdb;
     76
     77        $sql = $wpdb->prepare( "SELECT $wpdb->term_taxonomy.term_id
     78                                FROM $wpdb->term_taxonomy
     79                                WHERE taxonomy = %s", $queried_taxonomy );
     80
     81        $slugs = $wpdb->get_col( $sql );
     82
     83        $wp_query->query_vars[$queried_taxonomy] = '';
     84        $wp_query->query_vars['tax_query'] = array(
     85            array(
     86                'taxonomy' => $queried_taxonomy,
     87                'field' => 'term_id',
     88                'terms' => $slugs,
     89            )
     90        );
     91    }
     92
     93    return $wp_query;
     94}
     95add_filter( 'pre_get_posts', __NAMESPACE__.'\pre_get_posts', 10, 1 );
     96
     97/*
     98*   filter for `rewrite_rules_array` to add taxonomy base slugs directly before last catch alls
     99*   calls `{slug}_taxonomytaxi-two_rewrite_rules` filters
     100*   @param array
     101*   @return array   
     102*/
     103function rewrite_rules_array( $r ){
     104    $new_rules = array();
     105   
     106    $taxonomies = get_taxonomies( '', 'objects' );
     107   
     108    // dont duplicate defaults
     109    unset( $taxonomies['category'] );
     110    unset( $taxonomies['post_tag'] );
     111    unset( $taxonomies['post_format'] );
     112   
     113    foreach( $taxonomies as $taxonomy => $properties ){
     114        if( !$properties->rewrite )
     115            continue;
     116           
     117        $slug = $properties->rewrite['slug'];
     118       
     119        $taxonomy_rules = array(
     120            $slug.'/page/?([0-9]{1,})' => 'index.php?'.$taxonomy.'=show-all-terms&paged=$matches[1]',
     121            $slug => 'index.php?'.$taxonomy.'=show-all-terms'
     122        );
     123       
     124        $taxonomy_rules = apply_filters( $slug.'_taxonomytaxi-two_rewrite_rules', $taxonomy_rules );
     125       
     126        $new_rules = array_merge( $new_rules, $taxonomy_rules );
     127    }
     128   
     129    // insert new rewrite rules directly before the catch alls
     130    $k = array_keys( $r );
     131    $p = array_search( '(.+?)/page/?([0-9]{1,})/?$', $k );
     132   
     133    // @TODO figure out a better way of finding this
     134    if( !$p )
     135        $p = array_search( 'page/?([0-9]{1,})/?$', $k );
     136       
     137    $a = array_slice( $r, 0, $p );
     138    $b = array_slice( $r, $p );
     139   
     140    $r = array_merge( $a, $new_rules, $b );
     141       
     142    return $r;
     143}
     144add_filter( 'rewrite_rules_array', __NAMESPACE__.'\rewrite_rules_array' );
  • taxonomy-taxi-2-electric-boogaloo/trunk/readme.txt

    r977973 r1210109  
    44Tags: custom taxonomies, taxonomy
    55Requires at least: 3.1.3
    6 Tested up to: 3.9
     6Tested up to: 4.1.4
    77Stable tag: trunk
    88
     
    1818
    1919== Changelog ==
     20= 0.5 =
     21* Start on fix for wp 4.2 which fixed the exploited sql
     22
     23= 0.45 =
     24* Fix undefined term_id when admin bar is showing
     25
     26= 0.4 =
     27* Finish namespace refactor
     28
    2029= 0.3 =
    2130* Start on namespace refactor
Note: See TracChangeset for help on using the changeset viewer.