Making WordPress.org


Ignore:
Timestamp:
03/01/2016 07:59:36 PM (11 years ago)
Author:
obenland
Message:

Plugin Directory: Add support for internal notes.

Needs some more permission checks.

See #1570.

File:
1 edited

Legend:

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

    r2655 r2659  
    2727
    2828                add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
     29                add_action( 'wp_ajax_save-note', array( $this, 'save_note' ) );
    2930        }
    3031
    … …  
    5556                if ( 'post.php' == $hook_suffix && 'plugin' == $post_type ) {
    5657                        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                        wp_enqueue_script( 'plugin-admin-edit-js', plugins_url( 'js/edit-form.js', Plugin_Directory\PLUGIN_FILE ), array( 'wp-util' ), 1 );
    5859                }
    5960        }
    … …  
    7576                        array( __NAMESPACE__ . '\Metabox\Committers', 'display' ),
    7677                        'plugin', 'side'
     78                );
     79
     80                add_meta_box(
     81                        'plugin-notes',
     82                        __( 'Internal Notes', 'wporg-plugins' ),
     83                        array( __NAMESPACE__ . '\Metabox\Notes', 'display' ),
     84                        'plugin', 'normal', 'high'
    7785                );
    7886
    … …  
    118126        }
    119127
     128        /**
     129         * Saves a plugin note.
     130         */
     131        public function save_note() {
     132                check_admin_referer( 'save-note', 'notce' );
     133
     134                if ( empty( $_POST['id'] ) ) {
     135                        wp_send_json_error( array( 'errorCode' => 'no_post_specified' ) );
     136                }
     137
     138                if ( ! current_user_can( 'review_plugin', absint( $_POST['id'] ) ) ) {
     139                        wp_send_json_error( array(
     140                                'error' => __( 'You do not have sufficient permissions to edit notes on this site.' ),
     141                        ) );
     142                }
     143
     144                update_post_meta( absint( $_POST['id'] ), 'note', wp_kses_post( $_POST['note'] ) );
     145
     146                wp_send_json_success( array(
     147                        'note' => wpautop( wp_kses_post( $_POST['note'] ) ),
     148                ) );
     149        }
    120150}
Note: See TracChangeset for help on using the changeset viewer.