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


Generated: Sat Apr 4 01:00:03 2020 Cross-referenced by PHPXref 0.7.1