Changeset 2655 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php
- Timestamp:
- 03/01/2016 07:51:16 AM (9 years ago)
- File:
-
- 1 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 }
Note: See TracChangeset
for help on using the changeset viewer.