Making WordPress.org


Ignore:
Timestamp:
03/01/2016 07:51:16 AM (9 years ago)
Author:
dd32
Message:

Plugin Directory: Add several metaboxes for the Plugin Review/Admin.
This change includes switching to custom taxonomies, a custom publish metabox, a custom tags metabox, and the start of a plugin-reviewer metabox.

See #1570, #1584

File:
1 edited

Legend:

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

    r2639 r2655  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory\Admin;
     3use \WordPressdotorg\Plugin_Directory;
    34
    45/**
     
    1011
    1112    /**
    12      * Fetch the instance of the Plugin_Directory class.
     13     * Fetch the instance of the Admin Customizations class.
    1314     */
    1415    public static function instance() {
     
    1819    }
    1920
     21    private function __construct() {
     22        // Admin Metaboxes
     23        add_action( 'add_meta_boxes', array( $this, 'register_admin_metaboxes' ), 10, 1 );
     24        add_action( 'do_meta_boxes', array( $this, 'replace_title_global' ) );
     25
     26        add_action( 'save_post_plugin', array( $this, 'save_plugin_post' ), 10, 2 );
     27
     28        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
     29    }
     30
    2031    /**
     32     * Adds the plugin name into the post editing title.
    2133     *
     34     * @global $title The wp-admin title variable.
     35     *
     36     * @param string $post_type The post type of the current page
     37     * @return void.
    2238     */
    23     private function __construct() {
    24         add_action( 'add_meta_boxes', array( $this, 'register_admin_metaboxes' ) );
    25         add_action( 'edit_form_after_title', array( $this, 'edit_form_after_title' ) );
     39    public function replace_title_global( $post_type ) {
     40        global $title;
     41        if ( 'plugin' === $post_type ) {
     42            $title = sprintf( $title, get_the_title() ); // esc_html() on output
     43        }
     44    }
     45
     46    /**
     47     * Enqueue JS and CSS assets needed for any wp-admin screens.
     48     *
     49     * @param string $hook_suffix The hook suffix of the current screen.
     50     * @return void.
     51     */
     52    public function enqueue_assets( $hook_suffix ) {
     53        global $post_type;
     54
     55        if ( 'post.php' == $hook_suffix && 'plugin' == $post_type ) {
     56            wp_enqueue_style( 'plugin-admin-edit-css', plugins_url( 'css/edit-form.css', Plugin_Directory\PLUGIN_FILE ), array( 'edit' ), 1 );
     57            wp_enqueue_script( 'plugin-admin-edit-js', plugins_url( 'js/edit-form.js', Plugin_Directory\PLUGIN_FILE ), array(), 1 );
     58        }
    2659    }
    2760
    2861    /**
    2962     * Register the Admin metaboxes for the plugin management screens.
     63     *
     64     * @param string $post_type The post type of the current screen.
     65     * @return void.
    3066     */
    31     public function register_admin_metaboxes() {
     67    public function register_admin_metaboxes( $post_type ) {
     68        if ( 'plugin' != $post_type ) {
     69            return;
     70        }
     71
    3272        add_meta_box(
    3373            'plugin-committers',
    3474            __( 'Plugin Committers', 'wporg-plugins' ),
    35             array( __NAMESPACE__ . '\\Metabox\\Committers', 'display' ),
    36             'plugin'
     75            array( __NAMESPACE__ . '\Metabox\Committers', 'display' ),
     76            'plugin', 'side'
    3777        );
     78
     79        add_meta_box(
     80            'plugin-review',
     81            __( 'Plugin Review Tools', 'wporg-plugins' ),
     82            array( __NAMESPACE__ . '\Metabox\Review_Tools', 'display' ),
     83            'plugin', 'normal', 'high'
     84        );
     85
     86        add_meta_box(
     87            'plugin-fields',
     88            __( 'Plugin Meta', 'wporg-plugins' ),
     89            array( __NAMESPACE__ . '\Metabox\Custom_Fields', 'display' ),
     90            'plugin', 'normal', 'low'
     91        );
     92
     93        // Replace the publish box
     94        add_meta_box(
     95            'submitdiv',
     96            __( 'Plugin Controls', 'wporg-plugins' ),
     97            array( __NAMESPACE__ . '\Metabox\Controls', 'display' ),
     98            'plugin', 'side', 'high'
     99        );
     100
     101        // Remove the Slug metabox
     102        add_meta_box( 'slugdiv', false, false, false );
    38103    }
    39104
    40105    /**
    41      * Displays a link to the plugins zip file.
     106     * Hook into the save process for the plugin post_type to save extra metadata.
    42107     *
    43      * @param \WP_Post $post
     108     * Currently saves the tested_with value.
     109     *
     110     * @param int      $post_id The post_id being updated.
     111     * @param \WP_Post $post    The WP_Post object being updated.
    44112     */
    45     public function edit_form_after_title( $post ) {
    46         $zip_files = get_attached_media( 'application/zip', $post );
    47         $zip_file  = current( $zip_files );
    48         $zip_url   = wp_get_attachment_url( $zip_file->ID );
     113    public function save_plugin_post( $post_id, $post ) {
     114        // Save meta information
     115        if ( isset( $_POST['tested_with'] ) && isset( $_POST['hidden_tested_with'] ) && $_POST['tested_with'] != $_POST['hidden_tested_with'] ) {
     116            update_post_meta( $post_id, 'tested', wp_slash( wp_unslash( $_POST['tested_with'] ) ) );
     117        }
     118    }
    49119
    50         if ( $zip_url ) :
    51             ?>
    52 
    53             <p style="padding: 0 10px;">
    54                 <?php printf( __( '<strong>Zip file:</strong> %s' ), sprintf( '<a href="%s">%s</a>', esc_url( $zip_url ), esc_html( $zip_url ) ) ); ?>
    55             </p>
    56 
    57         <?php
    58         endif;
    59     }
    60120}
Note: See TracChangeset for help on using the changeset viewer.