mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 17:48:01 +01:00
Deprecate favorite_actions(), add_contextual_help(), add_screen_option(), move meta_box_prefs() and get_screen_icon() in WP_Screen, see #18690
git-svn-id: http://svn.automattic.com/wordpress/trunk@18874 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e0a7825baa
commit
bc6411bb52
File diff suppressed because one or more lines are too long
@ -254,7 +254,7 @@ textarea {
|
||||
|
||||
input[type="checkbox"],
|
||||
input[type="radio"] {
|
||||
vertical-align: middle;
|
||||
vertical-align: text-top;
|
||||
}
|
||||
|
||||
/* general */
|
||||
@ -1549,6 +1549,10 @@ form.upgrade .hint {
|
||||
margin: 0 5px 0 2px;
|
||||
}
|
||||
|
||||
.metabox-prefs label input[type="radio"] {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.metabox-prefs label a {
|
||||
display: none;
|
||||
}
|
||||
@ -4723,7 +4727,7 @@ p.pagenav {
|
||||
|
||||
.row-actions {
|
||||
visibility: hidden;
|
||||
padding: 2px 0 0;
|
||||
padding: 0 0 2px;
|
||||
}
|
||||
|
||||
tr:hover .row-actions,
|
||||
|
@ -801,6 +801,103 @@ function screen_options( $screen ) {
|
||||
* @see WP_Screen::render_screen_meta()
|
||||
*/
|
||||
function screen_meta( $screen ) {
|
||||
_deprecated_function( __FUNCTION__, '3.3', '$current_screen->render_screen_meta()' );
|
||||
|
||||
$current_screen = get_current_screen();
|
||||
$current_screen->render_screen_meta();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@internal Missing Short Description}}
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @deprecated 3.3.0
|
||||
*/
|
||||
function favorite_actions() {
|
||||
_deprecated_function( __FUNCTION__, '3.3' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Old way of adding contextual help text for a page. Use:
|
||||
* $current_screen->add_help_tab( array(
|
||||
* 'id' => 'my-id', // required
|
||||
* 'title' => __('My Tab'), // required
|
||||
* 'content' => 'help html'
|
||||
* ));
|
||||
*
|
||||
* Creates a 'Screen Info' help tab.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @deprecated 3.3.0
|
||||
*
|
||||
* @param string $screen The handle for the screen to add help to. This is usually the hook name returned by the add_*_page() functions.
|
||||
* @param string $help The content of a 'Screen Info' help tab.
|
||||
*/
|
||||
function add_contextual_help($screen, $help) {
|
||||
_deprecated_function( __FUNCTION__, '3.3', '$current_screen->add_help_tab()' );
|
||||
|
||||
global $_wp_contextual_help;
|
||||
|
||||
if ( is_string($screen) )
|
||||
$screen = convert_to_screen($screen);
|
||||
|
||||
if ( !isset($_wp_contextual_help) )
|
||||
$_wp_contextual_help = array();
|
||||
|
||||
$_wp_contextual_help[$screen->id] = $help;
|
||||
}
|
||||
|
||||
/**
|
||||
* Old way of registering and configuring an admin screen option. Use $current_screen->add_option().
|
||||
*
|
||||
* @since 3.1.0
|
||||
* @deprecated 3.3.0
|
||||
*
|
||||
* @param string $option An option name.
|
||||
* @param mixed $args Option dependent arguments
|
||||
* @return void
|
||||
*/
|
||||
function add_screen_option( $option, $args = array() ) {
|
||||
_deprecated_function( __FUNCTION__, '3.3', '$current_screen->add_option()' );
|
||||
|
||||
$current_screen = get_current_screen();
|
||||
|
||||
if ( ! $current_screen )
|
||||
return;
|
||||
|
||||
return $current_screen->add_option( $option, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the HTML for hiding metaboxes on the page, use $current_screen->render_metabox_prefs().
|
||||
*
|
||||
* Note that the outputted HTML contains the H5 heading and the DIV class="metabox-prefs".
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @deprecated 3.3.0
|
||||
*
|
||||
* @param mixed $screen
|
||||
*/
|
||||
function meta_box_prefs($screen) {
|
||||
_deprecated_function( __FUNCTION__, '3.3', '$current_screen->render_metabox_prefs()' );
|
||||
|
||||
$current_screen = get_current_screen();
|
||||
|
||||
if ( ! $current_screen )
|
||||
return;
|
||||
|
||||
return $current_screen->render_metabox_prefs();
|
||||
}
|
||||
|
||||
function get_screen_icon( $screen = '' ) {
|
||||
_deprecated_function( __FUNCTION__, '3.3', '$current_screen->get_screen_icon()' );
|
||||
|
||||
$current_screen = get_current_screen();
|
||||
|
||||
if ( ! $current_screen )
|
||||
return;
|
||||
|
||||
return $current_screen->get_screen_icon($screen);
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
* @param string|object $screen The screen you want the headers for
|
||||
* @return array Containing the headers in the format id => UI String
|
||||
*/
|
||||
function get_column_headers( $screen ) { // TODO: fold into WP_Screen
|
||||
function get_column_headers( $screen ) { // TODO: fold into WP_Screen?
|
||||
if ( is_string( $screen ) )
|
||||
$screen = convert_to_screen( $screen );
|
||||
|
||||
@ -42,41 +42,6 @@ function get_hidden_columns( $screen ) { // TODO: fold into WP_Screen
|
||||
return (array) get_user_option( 'manage' . $screen->id . 'columnshidden' );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@internal Missing Short Description}}
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @param unknown_type $screen
|
||||
*/
|
||||
function meta_box_prefs($screen) { // TODO: fold into WP_Screen
|
||||
global $wp_meta_boxes;
|
||||
|
||||
if ( is_string($screen) )
|
||||
$screen = convert_to_screen($screen);
|
||||
|
||||
if ( empty($wp_meta_boxes[$screen->id]) )
|
||||
return;
|
||||
|
||||
$hidden = get_hidden_meta_boxes($screen);
|
||||
|
||||
foreach ( array_keys($wp_meta_boxes[$screen->id]) as $context ) {
|
||||
foreach ( array_keys($wp_meta_boxes[$screen->id][$context]) as $priority ) {
|
||||
foreach ( $wp_meta_boxes[$screen->id][$context][$priority] as $box ) {
|
||||
if ( false == $box || ! $box['title'] )
|
||||
continue;
|
||||
// Submit box cannot be hidden
|
||||
if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] )
|
||||
continue;
|
||||
$box_id = $box['id'];
|
||||
echo '<label for="' . $box_id . '-hide">';
|
||||
echo '<input class="hide-postbox-tog" name="' . $box_id . '-hide" type="checkbox" id="' . $box_id . '-hide" value="' . $box_id . '"' . (! in_array($box_id, $hidden) ? ' checked="checked"' : '') . ' />';
|
||||
echo "{$box['title']}</label>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Hidden Meta Boxes
|
||||
*
|
||||
@ -97,124 +62,13 @@ function get_hidden_meta_boxes( $screen ) { // TODO: fold into WP_Screen
|
||||
$hidden = array('slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv');
|
||||
else
|
||||
$hidden = array( 'slugdiv' );
|
||||
|
||||
$hidden = apply_filters('default_hidden_meta_boxes', $hidden, $screen);
|
||||
}
|
||||
|
||||
return $hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@internal Missing Short Description}}
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
function favorite_actions( $screen = null ) { // TODO: deprecate and remove?
|
||||
$default_action = false;
|
||||
|
||||
if ( is_string($screen) )
|
||||
$screen = convert_to_screen($screen);
|
||||
|
||||
if ( $screen->is_user )
|
||||
return;
|
||||
|
||||
if ( isset($screen->post_type) ) {
|
||||
$post_type_object = get_post_type_object($screen->post_type);
|
||||
if ( 'add' != $screen->action )
|
||||
$default_action = array('post-new.php?post_type=' . $post_type_object->name => array($post_type_object->labels->new_item, $post_type_object->cap->edit_posts));
|
||||
else
|
||||
$default_action = array('edit.php?post_type=' . $post_type_object->name => array($post_type_object->labels->name, $post_type_object->cap->edit_posts));
|
||||
}
|
||||
|
||||
if ( !$default_action ) {
|
||||
if ( $screen->is_network ) {
|
||||
$default_action = array('sites.php' => array( __('Sites'), 'manage_sites'));
|
||||
} else {
|
||||
switch ( $screen->id ) {
|
||||
case 'upload':
|
||||
$default_action = array('media-new.php' => array(__('New Media'), 'upload_files'));
|
||||
break;
|
||||
case 'media':
|
||||
$default_action = array('upload.php' => array(__('Edit Media'), 'upload_files'));
|
||||
break;
|
||||
case 'link-manager':
|
||||
case 'link':
|
||||
if ( 'add' != $screen->action )
|
||||
$default_action = array('link-add.php' => array(__('New Link'), 'manage_links'));
|
||||
else
|
||||
$default_action = array('link-manager.php' => array(__('Edit Links'), 'manage_links'));
|
||||
break;
|
||||
case 'users':
|
||||
$default_action = array('user-new.php' => array(__('New User'), 'create_users'));
|
||||
break;
|
||||
case 'user':
|
||||
$default_action = array('users.php' => array(__('Edit Users'), 'edit_users'));
|
||||
break;
|
||||
case 'plugins':
|
||||
$default_action = array('plugin-install.php' => array(__('Install Plugins'), 'install_plugins'));
|
||||
break;
|
||||
case 'plugin-install':
|
||||
$default_action = array('plugins.php' => array(__('Manage Plugins'), 'activate_plugins'));
|
||||
break;
|
||||
case 'themes':
|
||||
$default_action = array('theme-install.php' => array(__('Install Themes'), 'install_themes'));
|
||||
break;
|
||||
case 'theme-install':
|
||||
$default_action = array('themes.php' => array(__('Manage Themes'), 'switch_themes'));
|
||||
break;
|
||||
default:
|
||||
$default_action = array('post-new.php' => array(__('New Post'), 'edit_posts'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$screen->is_network ) {
|
||||
$actions = array(
|
||||
'post-new.php' => array(__('New Post'), 'edit_posts'),
|
||||
'edit.php?post_status=draft' => array(__('Drafts'), 'edit_posts'),
|
||||
'post-new.php?post_type=page' => array(__('New Page'), 'edit_pages'),
|
||||
'media-new.php' => array(__('Upload'), 'upload_files'),
|
||||
'edit-comments.php' => array(__('Comments'), 'moderate_comments')
|
||||
);
|
||||
} else {
|
||||
$actions = array(
|
||||
'sites.php' => array( __('Sites'), 'manage_sites'),
|
||||
'users.php' => array( __('Users'), 'manage_network_users')
|
||||
);
|
||||
}
|
||||
|
||||
$default_key = array_keys($default_action);
|
||||
$default_key = $default_key[0];
|
||||
if ( isset($actions[$default_key]) )
|
||||
unset($actions[$default_key]);
|
||||
$actions = array_merge($default_action, $actions);
|
||||
$actions = apply_filters( 'favorite_actions', $actions, $screen );
|
||||
|
||||
$allowed_actions = array();
|
||||
foreach ( $actions as $action => $data ) {
|
||||
if ( current_user_can($data[1]) )
|
||||
$allowed_actions[$action] = $data[0];
|
||||
}
|
||||
|
||||
if ( empty($allowed_actions) )
|
||||
return;
|
||||
|
||||
$first = array_keys($allowed_actions);
|
||||
$first = $first[0];
|
||||
echo '<div id="favorite-actions">';
|
||||
echo '<div id="favorite-first"><a href="' . $first . '">' . $allowed_actions[$first] . '</a></div><div id="favorite-toggle"><br /></div>';
|
||||
echo '<div id="favorite-inside">';
|
||||
|
||||
array_shift($allowed_actions);
|
||||
|
||||
foreach ( $allowed_actions as $action => $label) {
|
||||
echo "<div class='favorite-action'><a href='$action'>";
|
||||
echo $label;
|
||||
echo "</a></div>\n";
|
||||
}
|
||||
echo "</div></div>\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a screen string to a screen object
|
||||
*
|
||||
@ -223,7 +77,7 @@ function favorite_actions( $screen = null ) { // TODO: deprecate and remove?
|
||||
* @param string $screen The name of the screen
|
||||
* @return object An object containing the safe screen name and id
|
||||
*/
|
||||
function convert_to_screen( $screen ) { // TODO: fold into WP_Screen
|
||||
function convert_to_screen( $screen ) { // TODO: fold into WP_Screen?
|
||||
$screen = str_replace( array('.php', '-new', '-add', '-network', '-user' ), '', $screen);
|
||||
|
||||
if ( is_network_admin() )
|
||||
@ -236,79 +90,13 @@ function convert_to_screen( $screen ) { // TODO: fold into WP_Screen
|
||||
return $screen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add contextual help text for a page.
|
||||
*
|
||||
* Creates a 'Screen Info' help tab.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @param string $screen The handle for the screen to add help to. This is usually the hook name returned by the add_*_page() functions.
|
||||
* @param string $help The content of a 'Screen Info' help tab.
|
||||
*/
|
||||
function add_contextual_help($screen, $help) { // TODO: deprecate
|
||||
global $_wp_contextual_help;
|
||||
function screen_icon( $for = '' ) { // TODO: fold into WP_Screen?
|
||||
global $current_screen;
|
||||
|
||||
if ( is_string($screen) )
|
||||
$screen = convert_to_screen($screen);
|
||||
|
||||
if ( !isset($_wp_contextual_help) )
|
||||
$_wp_contextual_help = array();
|
||||
|
||||
$_wp_contextual_help[$screen->id] = $help;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register and configure an admin screen option
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param string $option An option name.
|
||||
* @param mixed $args Option dependent arguments
|
||||
* @return void
|
||||
*/
|
||||
function add_screen_option( $option, $args = array() ) { // TODO: set deprecated
|
||||
$current_screen = get_current_screen();
|
||||
|
||||
if ( ! $current_screen )
|
||||
if ( !isset($current_screen) )
|
||||
return;
|
||||
|
||||
return $current_screen->add_option( $option, $args );
|
||||
}
|
||||
|
||||
function screen_icon( $screen = '' ) { // TODO: fold into WP_Screen
|
||||
echo get_screen_icon( $screen );
|
||||
}
|
||||
|
||||
function get_screen_icon( $screen = '' ) { // TODO: fold into WP_Screen
|
||||
global $current_screen, $typenow;
|
||||
|
||||
if ( empty($screen) )
|
||||
$screen = $current_screen;
|
||||
elseif ( is_string($screen) )
|
||||
$name = $screen;
|
||||
|
||||
$class = 'icon32';
|
||||
|
||||
if ( empty($name) ) {
|
||||
if ( !empty($screen->parent_base) )
|
||||
$name = $screen->parent_base;
|
||||
else
|
||||
$name = $screen->base;
|
||||
|
||||
if ( 'edit' == $name && isset($screen->post_type) && 'page' == $screen->post_type )
|
||||
$name = 'edit-pages';
|
||||
|
||||
$post_type = '';
|
||||
if ( isset( $screen->post_type ) )
|
||||
$post_type = $screen->post_type;
|
||||
elseif ( $current_screen == $screen )
|
||||
$post_type = $typenow;
|
||||
if ( $post_type )
|
||||
$class .= ' ' . sanitize_html_class( 'icon32-posts-' . $post_type );
|
||||
}
|
||||
|
||||
return '<div id="icon-' . esc_attr( $name ) . '" class="' . $class . '"><br /></div>';
|
||||
echo $current_screen->get_screen_icon( $for );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -339,10 +127,8 @@ function get_current_screen() {
|
||||
function set_current_screen( $id = '' ) {
|
||||
global $current_screen;
|
||||
|
||||
if ( is_a( $current_screen, 'WP_Screen' ) )
|
||||
return;
|
||||
|
||||
$current_screen = new WP_Screen( $id );
|
||||
if ( !is_a( $current_screen, 'WP_Screen' ) )
|
||||
$current_screen = new WP_Screen( $id );
|
||||
|
||||
// why do we need this? $current_screen = apply_filters('current_screen', $current_screen);
|
||||
}
|
||||
@ -479,15 +265,6 @@ final class WP_Screen {
|
||||
*/
|
||||
private $_show_options = false;
|
||||
|
||||
/**
|
||||
* Stores the 'screen_settings' section of screen options.
|
||||
*
|
||||
* @since 3.3.0
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
private $_screen_settings = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@ -664,6 +441,7 @@ final class WP_Screen {
|
||||
public function render_screen_meta() {
|
||||
global $_wp_contextual_help;
|
||||
|
||||
// Intended for adding Help and Screen Options.
|
||||
do_action('add_screen_help_and_options');
|
||||
|
||||
// Call old contextual_help_list filter.
|
||||
@ -779,9 +557,7 @@ final class WP_Screen {
|
||||
// TODO: deprecate
|
||||
$screen_settings = apply_filters( 'screen_settings', $screen_settings, $this );
|
||||
|
||||
?>
|
||||
<form id="adv-settings" action="" method="post">
|
||||
<?php
|
||||
echo '<form id="adv-settings" action="" method="post">';
|
||||
|
||||
$this->render_table_columns_prefs();
|
||||
$this->render_metabox_prefs();
|
||||
@ -789,9 +565,9 @@ final class WP_Screen {
|
||||
$this->render_per_page_options();
|
||||
echo $screen_settings;
|
||||
|
||||
wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?>
|
||||
</form>
|
||||
<?php
|
||||
wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false );
|
||||
echo '</form>';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -839,11 +615,30 @@ final class WP_Screen {
|
||||
function render_metabox_prefs() {
|
||||
global $wp_meta_boxes;
|
||||
|
||||
if ( isset( $wp_meta_boxes[ $this->id ] ) ) {
|
||||
if ( !empty( $wp_meta_boxes[ $this->id ] ) ) {
|
||||
$hidden = get_hidden_meta_boxes($this);
|
||||
?>
|
||||
<h5><?php _ex('Show on screen', 'Metaboxes') ?></h5>
|
||||
<div class="metabox-prefs">
|
||||
<?php meta_box_prefs( $this ); ?>
|
||||
<?php
|
||||
|
||||
foreach ( array_keys($wp_meta_boxes[$this->id]) as $context ) {
|
||||
foreach ( array_keys($wp_meta_boxes[$this->id][$context]) as $priority ) {
|
||||
foreach ( $wp_meta_boxes[$this->id][$context][$priority] as $box ) {
|
||||
if ( false == $box || ! $box['title'] )
|
||||
continue;
|
||||
// Submit box cannot be hidden
|
||||
if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] )
|
||||
continue;
|
||||
$box_id = $box['id'];
|
||||
echo '<label for="' . $box_id . '-hide">';
|
||||
echo '<input class="hide-postbox-tog" name="' . $box_id . '-hide" type="checkbox" id="' . $box_id . '-hide" value="' . $box_id . '"' . (! in_array($box_id, $hidden) ? ' checked="checked"' : '') . ' />';
|
||||
echo "{$box['title']}</label>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<br class="clear" />
|
||||
</div>
|
||||
<?php
|
||||
@ -957,5 +752,26 @@ final class WP_Screen {
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
function get_screen_icon( $for = '' ) {
|
||||
|
||||
if ( !empty($for) && is_string($for) ) {
|
||||
$name = $for;
|
||||
} else {
|
||||
if ( !empty($this->parent_base) )
|
||||
$name = $this->parent_base;
|
||||
else
|
||||
$name = $this->base;
|
||||
}
|
||||
|
||||
if ( 'edit' == $name && isset($this->post_type) && 'page' == $this->post_type )
|
||||
$name = 'edit-pages';
|
||||
|
||||
$class = '';
|
||||
if ( !empty( $this->post_type ) )
|
||||
$class = ' ' . sanitize_html_class( 'icon32-posts-' . $this->post_type );
|
||||
|
||||
return '<div id="icon-' . esc_attr( $name ) . '" class="icon32' . $class . '"><br /></div>';
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user