Making WordPress.org


Ignore:
Timestamp:
05/24/2016 04:49:07 AM (9 years ago)
Author:
dd32
Message:

Plugin Directory: Rename Tags to Categories and add the extra taxonomies we plan on using.

See #1573

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r3221 r3225  
    2424        add_action( 'widgets_init', array( $this, 'register_widgets' ) );
    2525        add_filter( 'post_type_link', array( $this, 'package_link' ), 10, 2 );
     26        add_filter( 'term_link', array( $this, 'term_link' ), 10, 3 );
    2627        add_filter( 'pre_insert_term', array( $this, 'pre_insert_term_prevent' ) );
    2728        add_action( 'pre_get_posts', array( $this, 'use_plugins_in_query' ) );
     
    9596        ) );
    9697
    97         register_taxonomy( 'plugin_category', 'plugin', array(
     98        register_taxonomy( 'plugin_section', 'plugin', array(
    9899            'hierarchical'      => true,
    99             'query_var'         => 'plugin_category',
     100            'query_var'         => 'plugin_section',
    100101            'rewrite'           => false,
    101102            'public'            => true,
    102             'show_ui'           => current_user_can( 'plugin_set_category' ),
    103             'show_admin_column' => current_user_can( 'plugin_set_category' ),
     103            'show_ui'           => current_user_can( 'plugin_set_section' ),
     104            'show_admin_column' => current_user_can( 'plugin_set_section' ),
    104105            'meta_box_cb'       => 'post_categories_meta_box',
    105106            'capabilities'      => array(
    106                 'assign_terms' => 'manage_categories',
    107             )
    108         ) );
    109 
    110         register_taxonomy( 'plugin_tag', 'plugin', array(
     107                'assign_terms' => 'plugin_set_section',
     108            ),
     109            'labels'            => array(
     110                'name'          => __( 'Plugin Sections',  'wporg-plugins' ),
     111            ),
     112        ) );
     113
     114        register_taxonomy( 'plugin_category', 'plugin', array(
    111115            'hierarchical'      => true, /* for tax_input[] handling on post saves. */
    112             'query_var'         => 'plugin_tag',
     116            'query_var'         => 'plugin_category',
    113117            'rewrite'           => array(
    114118                'hierarchical' => false,
    115                 'slug'         => 'tags',
     119                'slug'         => 'category',
    116120                'with_front'   => false,
    117121                'ep_mask'      => EP_TAGS,
    118122            ),
    119123            'labels'            => array(
    120                 'name'          => __( 'Plugin Tags',  'wporg-plugins' ),
    121                 'singular_name' => __( 'Plugin Tag',   'wporg-plugins' ),
    122                 'edit_item'     => __( 'Edit Tag',     'wporg-plugins' ),
    123                 'update_item'   => __( 'Update Tag',   'wporg-plugins' ),
    124                 'add_new_item'  => __( 'Add New Tag',  'wporg-plugins' ),
    125                 'new_item_name' => __( 'New Tag Name', 'wporg-plugins' ),
    126                 'search_items'  => __( 'Search Tags',  'wporg-plugins' ),
     124                'name'          => __( 'Plugin Categories',  'wporg-plugins' ),
     125                'singular_name' => __( 'Plugin Category',   'wporg-plugins' ),
     126                'edit_item'     => __( 'Edit Category',     'wporg-plugins' ),
     127                'update_item'   => __( 'Update Category',   'wporg-plugins' ),
     128                'add_new_item'  => __( 'Add New Category',  'wporg-plugins' ),
     129                'new_item_name' => __( 'New Category Name', 'wporg-plugins' ),
     130                'search_items'  => __( 'Search Categories',  'wporg-plugins' ),
    127131            ),
    128132            'public'            => true,
    129133            'show_ui'           => true,
    130134            'show_admin_column' => true,
    131             'meta_box_cb'       => array( __NAMESPACE__ . '\Admin\Metabox\Plugin_Tags', 'display' ),
     135            'meta_box_cb'       => array( __NAMESPACE__ . '\Admin\Metabox\Plugin_Categories', 'display' ),
    132136            'capabilities'      => array(
    133                 'assign_terms' => 'plugin_set_tags'
     137                'assign_terms' => 'plugin_set_category'
     138            )
     139        ) );
     140
     141        register_taxonomy( 'plugin_built_for', 'plugin', array(
     142            'hierarchical'      => true, /* for tax_input[] handling on post saves. */
     143            'query_var'         => 'plugin_built_for',
     144            'rewrite'           => false,
     145            'labels'            => array(
     146                'name'          => __( 'Built For',  'wporg-plugins' ),
     147            ),
     148            'public'            => true,
     149            'show_ui'           => true,
     150            'show_admin_column' => false,
     151            //'meta_box_cb'       => array( __NAMESPACE__ . '\Admin\Metabox\Plugin_Categories', 'display' ),
     152            'capabilities'      => array(
     153                'assign_terms' => 'plugin_set_category'
     154            )
     155        ) );
     156
     157        register_taxonomy( 'plugin_business_model', 'plugin', array(
     158            'hierarchical'      => true, /* for tax_input[] handling on post saves. */
     159            'query_var'         => 'plugin_business_model',
     160            'rewrite'           => false,
     161            'labels'            => array(
     162                'name'          => __( 'Business Model',  'wporg-plugins' ),
     163            ),
     164            'public'            => true,
     165            'show_ui'           => true,
     166            'show_admin_column' => false,
     167            //'meta_box_cb'       => array( __NAMESPACE__ . '\Admin\Metabox\Plugin_Categories', 'display' ),
     168            'capabilities'      => array(
     169                'assign_terms' => 'plugin_set_category'
    134170            )
    135171        ) );
     
    231267        $wp_rewrite->set_permalink_structure( '/%postname%/' );
    232268
    233         // /tags/%slug% is required for tags.
    234         $wp_rewrite->set_tag_base( '/tags' );
     269        // /tags/ & /category/ shouldn't conflict
     270        $wp_rewrite->set_tag_base( '/post-tags' );
     271        $wp_rewrite->set_category_base( '/post-categories' );
     272
     273        // Add our custom capabilitie and roles.
     274        Capabilities::add_roles();
    235275
    236276        // We require the WordPress.org Ratings plugin also be active.
     
    319359
    320360    /**
     361     * Filter the permalink for terms to be more useful.
     362     *
     363     * @param string   $termlink The generated term link.
     364     * @param \WP_Term $term     The term the link is for.
     365     * @param string   $taxonomy The taxonomy the term is in.
     366     */
     367    public function term_link( $termlink, $term, $taxonomy ) {
     368        if ( 'plugin_business_model' == $taxonomy ) {
     369            return false;
     370        }
     371        if ( 'plugin_built_for' == $taxonomy ) {
     372            return $this->package_link( false, $this->get_plugin_post( $term->slug ) );
     373        }
     374
     375        return $termlink;
     376    }
     377
     378    /**
    321379     * Checks if the current users is a super admin before allowing terms to be added.
    322380     *
     
    351409        switch ( get_query_var( 'browse' ) ) {
    352410            case 'beta':
    353                 $wp_query->query_vars['plugin_category'] = 'beta';
     411                $wp_query->query_vars['plugin_section'] = 'beta';
    354412                break;
    355413
    356414            case 'featured':
    357                 $wp_query->query_vars['plugin_category'] = 'featured';
     415                $wp_query->query_vars['plugin_section'] = 'featured';
    358416                break;
    359417
Note: See TracChangeset for help on using the changeset viewer.