[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/includes/ -> screen.php (source)

   1  <?php
   2  /**
   3   * WordPress Administration Screen API.
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /**
  10   * Get the column headers for a screen
  11   *
  12   * @since 2.7.0
  13   *
  14   * @staticvar array $column_headers
  15   *
  16   * @param string|WP_Screen $screen The screen you want the headers for
  17   * @return array Containing the headers in the format id => UI String
  18   */
  19  function get_column_headers( $screen ) {
  20      if ( is_string( $screen ) ) {
  21          $screen = convert_to_screen( $screen );
  22      }
  23  
  24      static $column_headers = array();
  25  
  26      if ( ! isset( $column_headers[ $screen->id ] ) ) {
  27  
  28          /**
  29           * Filters the column headers for a list table on a specific screen.
  30           *
  31           * The dynamic portion of the hook name, `$screen->id`, refers to the
  32           * ID of a specific screen. For example, the screen ID for the Posts
  33           * list table is edit-post, so the filter for that screen would be
  34           * manage_edit-post_columns.
  35           *
  36           * @since 3.0.0
  37           *
  38           * @param array $columns An array of column headers. Default empty.
  39           */
  40          $column_headers[ $screen->id ] = apply_filters( "manage_{$screen->id}_columns", array() );
  41      }
  42  
  43      return $column_headers[ $screen->id ];
  44  }
  45  
  46  /**
  47   * Get a list of hidden columns.
  48   *
  49   * @since 2.7.0
  50   *
  51   * @param string|WP_Screen $screen The screen you want the hidden columns for
  52   * @return array
  53   */
  54  function get_hidden_columns( $screen ) {
  55      if ( is_string( $screen ) ) {
  56          $screen = convert_to_screen( $screen );
  57      }
  58  
  59      $hidden = get_user_option( 'manage' . $screen->id . 'columnshidden' );
  60  
  61      $use_defaults = ! is_array( $hidden );
  62  
  63      if ( $use_defaults ) {
  64          $hidden = array();
  65  
  66          /**
  67           * Filters the default list of hidden columns.
  68           *
  69           * @since 4.4.0
  70           *
  71           * @param array     $hidden An array of columns hidden by default.
  72           * @param WP_Screen $screen WP_Screen object of the current screen.
  73           */
  74          $hidden = apply_filters( 'default_hidden_columns', $hidden, $screen );
  75      }
  76  
  77      /**
  78       * Filters the list of hidden columns.
  79       *
  80       * @since 4.4.0
  81       * @since 4.4.1 Added the `use_defaults` parameter.
  82       *
  83       * @param array     $hidden An array of hidden columns.
  84       * @param WP_Screen $screen WP_Screen object of the current screen.
  85       * @param bool      $use_defaults Whether to show the default columns.
  86       */
  87      return apply_filters( 'hidden_columns', $hidden, $screen, $use_defaults );
  88  }
  89  
  90  /**
  91   * Prints the meta box preferences for screen meta.
  92   *
  93   * @since 2.7.0
  94   *
  95   * @global array $wp_meta_boxes
  96   *
  97   * @param WP_Screen $screen
  98   */
  99  function meta_box_prefs( $screen ) {
 100      global $wp_meta_boxes;
 101  
 102      if ( is_string( $screen ) ) {
 103          $screen = convert_to_screen( $screen );
 104      }
 105  
 106      if ( empty( $wp_meta_boxes[ $screen->id ] ) ) {
 107          return;
 108      }
 109  
 110      $hidden = get_hidden_meta_boxes( $screen );
 111  
 112      foreach ( array_keys( $wp_meta_boxes[ $screen->id ] ) as $context ) {
 113          foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
 114              if ( ! isset( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] ) ) {
 115                  continue;
 116              }
 117              foreach ( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] as $box ) {
 118                  if ( false == $box || ! $box['title'] ) {
 119                      continue;
 120                  }
 121                  // Submit box cannot be hidden
 122                  if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] ) {
 123                      continue;
 124                  }
 125  
 126                  $widget_title = $box['title'];
 127  
 128                  if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) {
 129                      $widget_title = $box['args']['__widget_basename'];
 130                  }
 131  
 132                  printf(
 133                      '<label for="%1$s-hide"><input class="hide-postbox-tog" name="%1$s-hide" type="checkbox" id="%1$s-hide" value="%1$s" %2$s />%3$s</label>',
 134                      esc_attr( $box['id'] ),
 135                      checked( in_array( $box['id'], $hidden ), false, false ),
 136                      $widget_title
 137                  );
 138              }
 139          }
 140      }
 141  }
 142  
 143  /**
 144   * Get Hidden Meta Boxes
 145   *
 146   * @since 2.7.0
 147   *
 148   * @param string|WP_Screen $screen Screen identifier
 149   * @return array Hidden Meta Boxes
 150   */
 151  function get_hidden_meta_boxes( $screen ) {
 152      if ( is_string( $screen ) ) {
 153          $screen = convert_to_screen( $screen );
 154      }
 155  
 156      $hidden = get_user_option( "metaboxhidden_{$screen->id}" );
 157  
 158      $use_defaults = ! is_array( $hidden );
 159  
 160      // Hide slug boxes by default
 161      if ( $use_defaults ) {
 162          $hidden = array();
 163          if ( 'post' == $screen->base ) {
 164              if ( 'post' == $screen->post_type || 'page' == $screen->post_type || 'attachment' == $screen->post_type ) {
 165                  $hidden = array( 'slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv' );
 166              } else {
 167                  $hidden = array( 'slugdiv' );
 168              }
 169          }
 170  
 171          /**
 172           * Filters the default list of hidden meta boxes.
 173           *
 174           * @since 3.1.0
 175           *
 176           * @param array     $hidden An array of meta boxes hidden by default.
 177           * @param WP_Screen $screen WP_Screen object of the current screen.
 178           */
 179          $hidden = apply_filters( 'default_hidden_meta_boxes', $hidden, $screen );
 180      }
 181  
 182      /**
 183       * Filters the list of hidden meta boxes.
 184       *
 185       * @since 3.3.0
 186       *
 187       * @param array     $hidden       An array of hidden meta boxes.
 188       * @param WP_Screen $screen       WP_Screen object of the current screen.
 189       * @param bool      $use_defaults Whether to show the default meta boxes.
 190       *                                Default true.
 191       */
 192      return apply_filters( 'hidden_meta_boxes', $hidden, $screen, $use_defaults );
 193  }
 194  
 195  /**
 196   * Register and configure an admin screen option
 197   *
 198   * @since 3.1.0
 199   *
 200   * @param string $option An option name.
 201   * @param mixed $args Option-dependent arguments.
 202   */
 203  function add_screen_option( $option, $args = array() ) {
 204      $current_screen = get_current_screen();
 205  
 206      if ( ! $current_screen ) {
 207          return;
 208      }
 209  
 210      $current_screen->add_option( $option, $args );
 211  }
 212  
 213  /**
 214   * Get the current screen object
 215   *
 216   * @since 3.1.0
 217   *
 218   * @global WP_Screen $current_screen WordPress current screen object.
 219   *
 220   * @return WP_Screen|null Current screen object or null when screen not defined.
 221   */
 222  function get_current_screen() {
 223      global $current_screen;
 224  
 225      if ( ! isset( $current_screen ) ) {
 226          return null;
 227      }
 228  
 229      return $current_screen;
 230  }
 231  
 232  /**
 233   * Set the current screen object
 234   *
 235   * @since 3.0.0
 236   *
 237   * @param mixed $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen,
 238   *                         or an existing screen object.
 239   */
 240  function set_current_screen( $hook_name = '' ) {
 241      WP_Screen::get( $hook_name )->set_current_screen();
 242  }


Generated: Wed Sep 18 01:00:03 2019 Cross-referenced by PHPXref 0.7.1