Changeset 2655
- Timestamp:
- 03/01/2016 07:51:16 AM (9 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
- Files:
-
- 8 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php
r2639 r2655 1 1 <?php 2 2 namespace WordPressdotorg\Plugin_Directory\Admin; 3 use \WordPressdotorg\Plugin_Directory; 3 4 4 5 /** … … 10 11 11 12 /** 12 * Fetch the instance of the Plugin_Directoryclass.13 * Fetch the instance of the Admin Customizations class. 13 14 */ 14 15 public static function instance() { … … 18 19 } 19 20 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 20 31 /** 32 * Adds the plugin name into the post editing title. 21 33 * 34 * @global $title The wp-admin title variable. 35 * 36 * @param string $post_type The post type of the current page 37 * @return void. 22 38 */ 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 } 26 59 } 27 60 28 61 /** 29 62 * 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. 30 66 */ 31 public function register_admin_metaboxes() { 67 public function register_admin_metaboxes( $post_type ) { 68 if ( 'plugin' != $post_type ) { 69 return; 70 } 71 32 72 add_meta_box( 33 73 'plugin-committers', 34 74 __( 'Plugin Committers', 'wporg-plugins' ), 35 array( __NAMESPACE__ . '\ \Metabox\\Committers', 'display' ),36 'plugin' 75 array( __NAMESPACE__ . '\Metabox\Committers', 'display' ), 76 'plugin', 'side' 37 77 ); 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 ); 38 103 } 39 104 40 105 /** 41 * Displays a link to the plugins zip file.106 * Hook into the save process for the plugin post_type to save extra metadata. 42 107 * 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. 44 112 */ 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 } 49 119 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 <?php58 endif;59 }60 120 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-committers.php
r2621 r2655 1 1 <?php 2 2 namespace WordPressdotorg\Plugin_Directory\Admin\Metabox; 3 4 3 use WordPressdotorg\Plugin_Directory\Tools; 5 4 … … 10 9 */ 11 10 class Committers { 12 13 /**14 *15 */16 11 static function display() { 17 12 $plugin_slug = get_post()->post_name; -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
r2640 r2655 12 12 * Fetch the instance of the Plugin_Directory class. 13 13 */ 14 public static function instance( $plugin_file = null) {14 public static function instance() { 15 15 static $instance = null; 16 16 17 return ! is_null( $instance ) ? $instance : $instance = new Plugin_Directory( $plugin_file ); 18 } 19 20 /** 21 * @param string $plugin_file 22 */ 23 private function __construct( $plugin_file ) { 17 return ! is_null( $instance ) ? $instance : $instance = new Plugin_Directory(); 18 } 19 20 private function __construct() { 24 21 add_action( 'init', array( $this, 'init' ) ); 25 22 add_action( 'init', array( $this, 'register_shortcodes' ) ); … … 30 27 31 28 // Load all Admin-specific items. 32 add_action( 'admin_init', array( __NAMESPACE__ . '\ \Admin\\Customizations', 'instance' ) );33 34 register_activation_hook( $plugin_file, array( $this, 'activate' ) );35 register_deactivation_hook( $plugin_file, array( $this, 'deactivate' ) );29 add_action( 'admin_init', array( __NAMESPACE__ . '\Admin\Customizations', 'instance' ) ); 30 31 register_activation_hook( PLUGIN_FILE, array( $this, 'activate' ) ); 32 register_deactivation_hook( PLUGIN_FILE, array( $this, 'deactivate' ) ); 36 33 } 37 34 … … 43 40 44 41 register_post_type( 'plugin', array( 45 'labels' => array(46 'name' => __( 'Plugins', 'wporg-plugins' ),47 'singular_name' => __( 'Plugin', 'wporg-plugins' ),48 'menu_name' => __( 'My Plugins', 'wporg-plugins' ),49 'add_new' => __( 'Add New', 'wporg-plugins' ),50 'add_new_item' => __( 'Add New Plugin', 'wporg-plugins' ),51 'edit_item' => __( 'Edit Plugin','wporg-plugins' ),52 'new_item' => __( 'New Plugin', 'wporg-plugins' ),53 'view_item' => __( 'View Plugin', 'wporg-plugins' ),54 'search_items' => __( 'Search Plugins', 'wporg-plugins' ),55 'not_found' => __( 'No plugins found', 'wporg-plugins' ),42 'labels' => array( 43 'name' => __( 'Plugins', 'wporg-plugins' ), 44 'singular_name' => __( 'Plugin', 'wporg-plugins' ), 45 'menu_name' => __( 'My Plugins', 'wporg-plugins' ), 46 'add_new' => __( 'Add New', 'wporg-plugins' ), 47 'add_new_item' => __( 'Add New Plugin', 'wporg-plugins' ), 48 'edit_item' => __( 'Editing Plugin: %s', 'wporg-plugins' ), 49 'new_item' => __( 'New Plugin', 'wporg-plugins' ), 50 'view_item' => __( 'View Plugin', 'wporg-plugins' ), 51 'search_items' => __( 'Search Plugins', 'wporg-plugins' ), 52 'not_found' => __( 'No plugins found', 'wporg-plugins' ), 56 53 'not_found_in_trash' => __( 'No plugins found in Trash', 'wporg-plugins' ), 57 54 ), 58 'description' => __( 'A Repo Plugin', 'wporg-plugins' ), 59 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields' ), 60 'taxonomies' => array( 'post_tag', 'category' ), 61 'public' => true, 62 'show_ui' => true, 63 'has_archive' => true, 64 'rewrite' => false, 65 'menu_icon' => 'dashicons-admin-plugins', 55 'description' => __( 'A Repo Plugin', 'wporg-plugins' ), 56 'supports' => false, 57 'public' => true, 58 'show_ui' => true, 59 'has_archive' => true, 60 'rewrite' => false, 61 'menu_icon' => 'dashicons-admin-plugins', 62 'capability_type' => array( 'post', 'posts' ), // TODO roles & capabilities 63 'map_meta_cap' => true, 64 'capabilities' => array( 65 'create_posts' => 'do_not_allow' 66 ) 67 ) ); 68 69 register_taxonomy( 'plugin_category', 'plugin', array( 70 'hierarchical' => true, 71 'query_var' => 'plugin_category', 72 'rewrite' => false, 73 'public' => true, 74 'show_ui' => true, 75 'show_admin_column' => true, 76 'meta_box_cb' => 'post_categories_meta_box', 77 'capabilities' => array( 78 'assign_terms' => 'manage_categories', 79 ) 80 ) ); 81 82 register_taxonomy( 'plugin_tag', 'plugin', array( 83 'hierarchical' => true, /* for tax_input[] handling on post saves. */ 84 'query_var' => 'plugin_tag', 85 'rewrite' => array( 86 'hierarchical' => false, 87 'slug' => 'tags', 88 'with_front' => false, 89 'ep_mask' => EP_TAGS, 90 ), 91 'labels' => array( 92 'name' => __( 'Plugin Tags', 'wporg-plugins' ), 93 'singular_name' => __( 'Plugin Tag', 'wporg-plugins' ), 94 'edit_item' => __( 'Edit Tag', 'wporg-plugins' ), 95 'update_item' => __( 'Update Tag', 'wporg-plugins' ), 96 'add_new_item' => __( 'Add New Tag', 'wporg-plugins' ), 97 'new_item_name' => __( 'New Tag Name', 'wporg-plugins' ), 98 'search_items' => __( 'Search Tags', 'wporg-plugins' ), 99 ), 100 'public' => true, 101 'show_ui' => true, 102 'show_admin_column' => true, 103 'meta_box_cb' => array( __NAMESPACE__ . '\Admin\Metabox\Plugin_Tags', 'display' ), 104 'capabilities' => array() 66 105 ) ); 67 106 … … 83 122 'show_in_admin_status_list' => true, 84 123 'label_count' => _n_noop( 'Closed <span class="count">(%s)</span>', 'Closed <span class="count">(%s)</span>', 'wporg-plugins' ), 124 ) ); 125 register_post_status( 'rejected', array( 126 'label' => _x( 'Rejected', 'plugin status', 'wporg-plugins' ), 127 'public' => false, 128 'show_in_admin_status_list' => true, 129 'label_count' => _n_noop( 'Rejected <span class="count">(%s)</span>', 'Rejected <span class="count">(%s)</span>', 'wporg-plugins' ), 85 130 ) ); 86 131 … … 108 153 */ 109 154 public function register_shortcodes() { 110 add_shortcode( 'wporg-plugin-upload', array( __NAMESPACE__ . '\\Shortcodes\\Upload', 'display' ) ); 111 add_shortcode( 'wporg-plugins-screenshots', array( __NAMESPACE__ . '\\Shortcodes\\Screenshots', 'display' ) ); 112 // add_shortcode( 'wporg-plugins-stats', array( __NAMESPACE__ . '\\Shortcodes\\Stats', 'display' ) ); 113 // add_shortcode( 'wporg-plugins-developer', array( __NAMESPACE__ . '\\Shortcodes\\Developer', 'display' ) ); 114 } 115 116 /** 155 add_shortcode( 'wporg-plugin-upload', array( __NAMESPACE__ . '\Shortcodes\Upload', 'display' ) ); 156 add_shortcode( 'wporg-plugins-screenshots', array( __NAMESPACE__ . '\Shortcodes\Screenshots', 'display' ) ); 157 // add_shortcode( 'wporg-plugins-stats', array( __NAMESPACE__ . '\Shortcodes\Stats', 'display' ) ); 158 // add_shortcode( 'wporg-plugins-developer', array( __NAMESPACE__ . '\Shortcodes\Developer', 'display' ) ); 159 } 160 161 /** 162 * Upon plugin activation, set up the current site for acting 163 * as the plugin directory. 164 * 165 * Setting up the site requires setting up the theme and proper 166 * rewrite permastructs. 167 * 117 168 * @global \WP_Rewrite $wp_rewrite WordPress rewrite component. 118 169 */ … … 148 199 149 200 /** 150 * 201 * Clean up options & rewrite rules after plugin deactivation. 151 202 */ 152 203 public function deactivate() { … … 241 292 switch ( get_query_var( 'browse' ) ) { 242 293 case 'beta': 243 $wp_query->query_vars[' category_name'] = 'beta';294 $wp_query->query_vars['plugin_category'] = 'beta'; 244 295 break; 245 296 246 297 case 'featured': 247 $wp_query->query_vars[' category_name'] = 'featured';298 $wp_query->query_vars['plugin_category'] = 'featured'; 248 299 break; 249 300 … … 326 377 * 327 378 * @param $plugin_slug string|\WP_Post The slug of the plugin to retrieve. 328 * @return \WP_Post| \WP_Error379 * @return \WP_Post|bool 329 380 */ 330 381 static public function get_plugin_post( $plugin_slug ) { 382 global $post; 331 383 if ( $plugin_slug instanceof \WP_Post ) { 332 384 return $plugin_slug; 385 } 386 // Use the global $post object when it matches to avoid hitting the database. 387 if ( !empty( $post ) && 'plugin' == $post->post_type && $plugin_slug == $post->post_name ) { 388 return $post; 333 389 } 334 390 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php
r2649 r2655 3 3 use WordPressdotorg\Plugin_Directory\Plugin_Directory; 4 4 use WordPressdotorg\Plugin_Directory\Readme_Parser; 5 use WordPressdotorg\Plugin_Directory\Template; 5 6 use WordPressdotorg\Plugin_Directory\Tools; 6 7 use WordPressdotorg\Plugin_Directory\Tools\Filesystem; … … 88 89 89 90 foreach ( $this->readme_fields as $readme_field ) { 90 update_post_meta( $plugin->ID, $readme_field, $readme->$readme_field ); 91 // Don't change the tested version if a newer version was specified through wp-admin 92 if ( 'tested' == $readme_field && version_compare( get_post_meta( $plugin->ID, 'tested', true ), $readme->$readme_field, '>' ) ) { 93 continue; 94 } 95 update_post_meta( $plugin->ID, $readme_field, wp_slash( $readme->$readme_field ) ); 91 96 } 92 97 foreach ( $this->plugin_headers as $plugin_header => $meta_field ) { 93 update_post_meta( $plugin->ID, $meta_field, $headers->$plugin_header);98 update_post_meta( $plugin->ID, $meta_field, wp_slash( $headers->$plugin_header ) ); 94 99 } 95 100 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/plugin-directory.php
r2621 r2655 16 16 namespace WordPressdotorg\Plugin_Directory; 17 17 18 /** 19 * Store the root plugin file for usage with functions which use the plugin basename. 20 */ 21 define( __NAMESPACE__ . '\PLUGIN_FILE', __FILE__ ); 22 18 23 // Register an Autoloader for all files 19 24 include __DIR__ . '/class-autoloader.php'; 20 25 Autoloader\register_class_path( __NAMESPACE__, __DIR__ ); 21 26 22 // Create the instance of the plugin, passing __FILE__ for actions that need it.27 // Instantiate the Plugin Directory 23 28 include __DIR__ . '/class-plugin-directory.php'; 24 Plugin_Directory::instance( __FILE__);29 Plugin_Directory::instance();
Note: See TracChangeset
for help on using the changeset viewer.