Make WordPress Core


Ignore:
Timestamp:
10/04/2011 03:32:12 AM (15 years ago)
Author:
azaozz
Message:

Deprecate favorite_actions(), add_contextual_help(), add_screen_option(), move meta_box_prefs() and get_screen_icon() in WP_Screen, see #18690

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/screen.php

    r18867 r18874  
    1515 * @return array Containing the headers in the format id => UI String
    1616 */
    17 function get_column_headers( $screen ) { // TODO: fold into WP_Screen
     17function get_column_headers( $screen ) { // TODO: fold into WP_Screen?
    1818        if ( is_string( $screen ) )
    1919                $screen = convert_to_screen( $screen );
     
    4444
    4545/**
    46  * {@internal Missing Short Description}}
    47  *
    48  * @since 2.7.0
    49  *
    50  * @param unknown_type $screen
    51  */
    52 function meta_box_prefs($screen) { // TODO: fold into WP_Screen
    53         global $wp_meta_boxes;
    54 
    55         if ( is_string($screen) )
    56                 $screen = convert_to_screen($screen);
    57 
    58         if ( empty($wp_meta_boxes[$screen->id]) )
    59                 return;
    60 
    61         $hidden = get_hidden_meta_boxes($screen);
    62 
    63         foreach ( array_keys($wp_meta_boxes[$screen->id]) as $context ) {
    64                 foreach ( array_keys($wp_meta_boxes[$screen->id][$context]) as $priority ) {
    65                         foreach ( $wp_meta_boxes[$screen->id][$context][$priority] as $box ) {
    66                                 if ( false == $box || ! $box['title'] )
    67                                         continue;
    68                                 // Submit box cannot be hidden
    69                                 if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] )
    70                                         continue;
    71                                 $box_id = $box['id'];
    72                                 echo '<label for="' . $box_id . '-hide">';
    73                                 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"' : '') . ' />';
    74                                 echo "{$box['title']}</label>\n";
    75                         }
    76                 }
    77         }
    78 }
    79 
    80 /**
    8146 * Get Hidden Meta Boxes
    8247 *
     
    9863                else
    9964                        $hidden = array( 'slugdiv' );
     65
    10066                $hidden = apply_filters('default_hidden_meta_boxes', $hidden, $screen);
    10167        }
    10268
    10369        return $hidden;
    104 }
    105 
    106 /**
    107  * {@internal Missing Short Description}}
    108  *
    109  * @since 2.7.0
    110  */
    111 function favorite_actions( $screen = null ) { // TODO: deprecate and remove?
    112         $default_action = false;
    113 
    114         if ( is_string($screen) )
    115                 $screen = convert_to_screen($screen);
    116 
    117         if ( $screen->is_user )
    118                 return;
    119 
    120         if ( isset($screen->post_type) ) {
    121                 $post_type_object = get_post_type_object($screen->post_type);
    122                 if ( 'add' != $screen->action )
    123                         $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));
    124                 else
    125                         $default_action = array('edit.php?post_type=' . $post_type_object->name => array($post_type_object->labels->name, $post_type_object->cap->edit_posts));
    126         }
    127 
    128         if ( !$default_action ) {
    129                 if ( $screen->is_network ) {
    130                         $default_action = array('sites.php' => array( __('Sites'), 'manage_sites'));
    131                 } else {
    132                         switch ( $screen->id ) {
    133                                 case 'upload':
    134                                         $default_action = array('media-new.php' => array(__('New Media'), 'upload_files'));
    135                                         break;
    136                                 case 'media':
    137                                         $default_action = array('upload.php' => array(__('Edit Media'), 'upload_files'));
    138                                         break;
    139                                 case 'link-manager':
    140                                 case 'link':
    141                                         if ( 'add' != $screen->action )
    142                                                 $default_action = array('link-add.php' => array(__('New Link'), 'manage_links'));
    143                                         else
    144                                                 $default_action = array('link-manager.php' => array(__('Edit Links'), 'manage_links'));
    145                                         break;
    146                                 case 'users':
    147                                         $default_action = array('user-new.php' => array(__('New User'), 'create_users'));
    148                                         break;
    149                                 case 'user':
    150                                         $default_action = array('users.php' => array(__('Edit Users'), 'edit_users'));
    151                                         break;
    152                                 case 'plugins':
    153                                         $default_action = array('plugin-install.php' => array(__('Install Plugins'), 'install_plugins'));
    154                                         break;
    155                                 case 'plugin-install':
    156                                         $default_action = array('plugins.php' => array(__('Manage Plugins'), 'activate_plugins'));
    157                                         break;
    158                                 case 'themes':
    159                                         $default_action = array('theme-install.php' => array(__('Install Themes'), 'install_themes'));
    160                                         break;
    161                                 case 'theme-install':
    162                                         $default_action = array('themes.php' => array(__('Manage Themes'), 'switch_themes'));
    163                                         break;
    164                                 default:
    165                                         $default_action = array('post-new.php' => array(__('New Post'), 'edit_posts'));
    166                                         break;
    167                         }
    168                 }
    169         }
    170 
    171         if ( !$screen->is_network ) {
    172                 $actions = array(
    173                         'post-new.php' => array(__('New Post'), 'edit_posts'),
    174                         'edit.php?post_status=draft' => array(__('Drafts'), 'edit_posts'),
    175                         'post-new.php?post_type=page' => array(__('New Page'), 'edit_pages'),
    176                         'media-new.php' => array(__('Upload'), 'upload_files'),
    177                         'edit-comments.php' => array(__('Comments'), 'moderate_comments')
    178                         );
    179         } else {
    180                 $actions = array(
    181                         'sites.php' => array( __('Sites'), 'manage_sites'),
    182                         'users.php' => array( __('Users'), 'manage_network_users')
    183                 );
    184         }
    185 
    186         $default_key = array_keys($default_action);
    187         $default_key = $default_key[0];
    188         if ( isset($actions[$default_key]) )
    189                 unset($actions[$default_key]);
    190         $actions = array_merge($default_action, $actions);
    191         $actions = apply_filters( 'favorite_actions', $actions, $screen );
    192 
    193         $allowed_actions = array();
    194         foreach ( $actions as $action => $data ) {
    195                 if ( current_user_can($data[1]) )
    196                         $allowed_actions[$action] = $data[0];
    197         }
    198 
    199         if ( empty($allowed_actions) )
    200                 return;
    201 
    202         $first = array_keys($allowed_actions);
    203         $first = $first[0];
    204         echo '<div id="favorite-actions">';
    205         echo '<div id="favorite-first"><a href="' . $first . '">' . $allowed_actions[$first] . '</a></div><div id="favorite-toggle"><br /></div>';
    206         echo '<div id="favorite-inside">';
    207 
    208         array_shift($allowed_actions);
    209 
    210         foreach ( $allowed_actions as $action => $label) {
    211                 echo "<div class='favorite-action'><a href='$action'>";
    212                 echo $label;
    213                 echo "</a></div>\n";
    214         }
    215         echo "</div></div>\n";
    21670}
    21771
     
    22478 * @return object An object containing the safe screen name and id
    22579 */
    226 function convert_to_screen( $screen ) { // TODO: fold into WP_Screen
     80function convert_to_screen( $screen ) { // TODO: fold into WP_Screen?
    22781        $screen = str_replace( array('.php', '-new', '-add', '-network', '-user' ), '', $screen);
    22882
     
    23791}
    23892
    239 /**
    240  * Add contextual help text for a page.
    241  *
    242  * Creates a 'Screen Info' help tab.
    243  *
    244  * @since 2.7.0
    245  *
    246  * @param string    $screen The handle for the screen to add help to.  This is usually the hook name returned by the add_*_page() functions.
    247  * @param string    $help   The content of a 'Screen Info' help tab.
    248  */
    249 function add_contextual_help($screen, $help) { // TODO: deprecate
    250         global $_wp_contextual_help;
    251 
    252         if ( is_string($screen) )
    253                 $screen = convert_to_screen($screen);
    254 
    255         if ( !isset($_wp_contextual_help) )
    256                 $_wp_contextual_help = array();
    257 
    258         $_wp_contextual_help[$screen->id] = $help;
    259 }
    260 
    261 /**
    262  * Register and configure an admin screen option
    263  *
    264  * @since 3.1.0
    265  *
    266  * @param string $option An option name.
    267  * @param mixed $args Option dependent arguments
    268  * @return void
    269  */
    270 function add_screen_option( $option, $args = array() ) { // TODO: set deprecated
    271         $current_screen = get_current_screen();
    272 
    273         if ( ! $current_screen )
     93function screen_icon( $for = '' ) { // TODO: fold into WP_Screen?
     94        global $current_screen;
     95
     96        if ( !isset($current_screen) )
    27497                return;
    27598
    276         return $current_screen->add_option( $option, $args );
    277 }
    278 
    279 function screen_icon( $screen = '' ) { // TODO: fold into WP_Screen
    280         echo get_screen_icon( $screen );
    281 }
    282 
    283 function get_screen_icon( $screen = '' ) { // TODO: fold into WP_Screen
    284         global $current_screen, $typenow;
    285 
    286         if ( empty($screen) )
    287                 $screen = $current_screen;
    288         elseif ( is_string($screen) )
    289                 $name = $screen;
    290 
    291         $class = 'icon32';
    292 
    293         if ( empty($name) ) {
    294                 if ( !empty($screen->parent_base) )
    295                         $name = $screen->parent_base;
    296                 else
    297                         $name = $screen->base;
    298 
    299                 if ( 'edit' == $name && isset($screen->post_type) && 'page' == $screen->post_type )
    300                         $name = 'edit-pages';
    301 
    302                 $post_type = '';
    303                 if ( isset( $screen->post_type ) )
    304                         $post_type = $screen->post_type;
    305                 elseif ( $current_screen == $screen )
    306                         $post_type = $typenow;
    307                 if ( $post_type )
    308                         $class .= ' ' . sanitize_html_class( 'icon32-posts-' . $post_type );
    309         }
    310 
    311         return '<div id="icon-' . esc_attr( $name ) . '" class="' . $class . '"><br /></div>';
     99        echo $current_screen->get_screen_icon( $for );
    312100}
    313101
     
    340128        global $current_screen;
    341129
    342         if ( is_a( $current_screen, 'WP_Screen' ) )
    343                 return;
    344 
    345         $current_screen = new WP_Screen( $id );
     130        if ( !is_a( $current_screen, 'WP_Screen' ) )
     131                $current_screen = new WP_Screen( $id );
    346132
    347133        // why do we need this? $current_screen = apply_filters('current_screen', $current_screen);
     
    479265         */
    480266        private $_show_options = false;
    481 
    482         /**
    483          * Stores the 'screen_settings' section of screen options.
    484          *
    485          * @since 3.3.0
    486          * @var string
    487          * @access private
    488          */
    489         private $_screen_settings = '';
    490267
    491268        /**
     
    665442                global $_wp_contextual_help;
    666443
     444                // Intended for adding Help and Screen Options.
    667445                do_action('add_screen_help_and_options');
    668446
     
    780558                $screen_settings = apply_filters( 'screen_settings', $screen_settings, $this );
    781559
    782                 ?>
    783                 <form id="adv-settings" action="" method="post">
    784                 <?php
     560                echo '<form id="adv-settings" action="" method="post">';
    785561
    786562                $this->render_table_columns_prefs();
     
    790566                echo $screen_settings;
    791567
    792                 wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?>
    793                 </form>
    794                 <?php
     568                wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false );
     569                echo '</form>';
     570
    795571        }
    796572
     
    840616                global $wp_meta_boxes;
    841617
    842                 if ( isset( $wp_meta_boxes[ $this->id ] ) ) {
     618                if ( !empty( $wp_meta_boxes[ $this->id ] ) ) {
     619                        $hidden = get_hidden_meta_boxes($this);
    843620                        ?>
    844621                        <h5><?php _ex('Show on screen', 'Metaboxes') ?></h5>
    845622                        <div class="metabox-prefs">
    846                                 <?php meta_box_prefs( $this ); ?>
     623                                <?php
     624
     625                                foreach ( array_keys($wp_meta_boxes[$this->id]) as $context ) {
     626                                        foreach ( array_keys($wp_meta_boxes[$this->id][$context]) as $priority ) {
     627                                                foreach ( $wp_meta_boxes[$this->id][$context][$priority] as $box ) {
     628                                                        if ( false == $box || ! $box['title'] )
     629                                                                continue;
     630                                                        // Submit box cannot be hidden
     631                                                        if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] )
     632                                                                continue;
     633                                                        $box_id = $box['id'];
     634                                                        echo '<label for="' . $box_id . '-hide">';
     635                                                        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"' : '') . ' />';
     636                                                        echo "{$box['title']}</label>\n";
     637                                                }
     638                                        }
     639                                }
     640
     641                                ?>
    847642                                <br class="clear" />
    848643                        </div>
     
    958753                <?php
    959754        }
     755       
     756        function get_screen_icon( $for = '' ) {
     757
     758                if ( !empty($for) && is_string($for) ) {
     759                        $name = $for;
     760                } else {
     761                        if ( !empty($this->parent_base) )
     762                                $name = $this->parent_base;
     763                        else
     764                                $name = $this->base;
     765                }
     766
     767                if ( 'edit' == $name && isset($this->post_type) && 'page' == $this->post_type )
     768                        $name = 'edit-pages';
     769
     770                $class = '';
     771                if ( !empty( $this->post_type ) )
     772                        $class = ' ' . sanitize_html_class( 'icon32-posts-' . $this->post_type );
     773
     774                return '<div id="icon-' . esc_attr( $name ) . '" class="icon32' . $class . '"><br /></div>';
     775        }
    960776}
    961777
Note: See TracChangeset for help on using the changeset viewer.