Making WordPress.org

Changeset 3324


Ignore:
Timestamp:
06/09/2016 07:34:35 PM (8 years ago)
Author:
obenland
Message:

Plugin Directory: Limit the amount of assignable categories to 3.

See #1573.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin
Files:
2 edited

Legend:

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

    r3157 r3324  
    2929        add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
    3030        add_action( 'save_post_plugin', array( $this, 'save_plugin_post' ) );
     31        add_filter( 'tax_input_pre', array( $this, 'filter_tax_input' ) );
    3132
    3233        add_action( 'load-edit.php', array( $this, 'bulk_reject_plugins' ) );
     
    448449            update_post_meta( $post_id, 'tested', wp_slash( wp_unslash( $_POST['tested_with'] ) ) );
    449450        }
     451    }
     452
     453    /**
     454     * Filters the value of tax_inputs before saving.
     455     *
     456     * @param array $tax_input Array of taxonomies with selected terms.
     457     * @return array
     458     */
     459    public function filter_tax_input( $tax_input ) {
     460
     461        // Limit the amount of assignable categories to 3.
     462        if ( isset( $tax_input['plugin_category'] ) ) {
     463            $tax_input['plugin_category'] = array_slice( array_filter( $tax_input['plugin_category'] ), 0, 3 );
     464        }
     465
     466        return $tax_input;
    450467    }
    451468
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-plugin-categories.php

    r3225 r3324  
    88 */
    99class Plugin_Categories {
     10
    1011    /**
    1112     * Displays the categories metabox for plugins.
     
    1718        ?>
    1819        <div id="taxonomy-plugin_category" class="categorydiv">
     20            <div class="notice notice-info inline">
     21                <p><?php _e( 'You can assign up to 3 categories.', 'wporg-plugins' ); ?></p>
     22            </div>
     23
    1924            <div id="plugin_category-all" class="tabs-panel">
    2025                <?php // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. ?>
     
    2833    }
    2934}
    30 
Note: See TracChangeset for help on using the changeset viewer.