[ 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   * @param string|WP_Screen $screen The screen you want the headers for
  15   * @return string[] The column header labels keyed by column ID.
  16   */
  17  function get_column_headers( $screen ) {
  18      if ( is_string( $screen ) ) {
  19          $screen = convert_to_screen( $screen );
  20      }
  21  
  22      static $column_headers = array();
  23  
  24      if ( ! isset( $column_headers[ $screen->id ] ) ) {
  25          /**
  26           * Filters the column headers for a list table on a specific screen.
  27           *
  28           * The dynamic portion of the hook name, `$screen->id`, refers to the
  29           * ID of a specific screen. For example, the screen ID for the Posts
  30           * list table is edit-post, so the filter for that screen would be
  31           * manage_edit-post_columns.
  32           *
  33           * @since 3.0.0
  34           *
  35           * @param string[] $columns The column header labels keyed by column ID.
  36           */
  37          $column_headers[ $screen->id ] = apply_filters( "manage_{$screen->id}_columns", array() );
  38      }
  39  
  40      return $column_headers[ $screen->id ];
  41  }
  42  
  43  /**
  44   * Get a list of hidden columns.
  45   *
  46   * @since 2.7.0
  47   *
  48   * @param string|WP_Screen $screen The screen you want the hidden columns for
  49   * @return string[] Array of IDs of hidden columns.
  50   */
  51  function get_hidden_columns( $screen ) {
  52      if ( is_string( $screen ) ) {
  53          $screen = convert_to_screen( $screen );
  54      }
  55  
  56      $hidden = get_user_option( 'manage' . $screen->id . 'columnshidden' );
  57  
  58      $use_defaults = ! is_array( $hidden );
  59  
  60      if ( $use_defaults ) {
  61          $hidden = array();
  62  
  63          /**
  64           * Filters the default list of hidden columns.
  65           *
  66           * @since 4.4.0
  67           *
  68           * @param string[]  $hidden Array of IDs of columns hidden by default.
  69           * @param WP_Screen $screen WP_Screen object of the current screen.
  70           */
  71          $hidden = apply_filters( 'default_hidden_columns', $hidden, $screen );
  72      }
  73  
  74      /**
  75       * Filters the list of hidden columns.
  76       *
  77       * @since 4.4.0
  78       * @since 4.4.1 Added the `use_defaults` parameter.
  79       *
  80       * @param string[]  $hidden       Array of IDs of hidden columns.
  81       * @param WP_Screen $screen       WP_Screen object of the current screen.
  82       * @param bool      $use_defaults Whether to show the default columns.
  83       */
  84      return apply_filters( 'hidden_columns', $hidden, $screen, $use_defaults );
  85  }
  86  
  87  /**
  88   * Prints the meta box preferences for screen meta.
  89   *
  90   * @since 2.7.0
  91   *
  92   * @global array $wp_meta_boxes
  93   *
  94   * @param WP_Screen $screen
  95   */
  96  function meta_box_prefs( $screen ) {
  97      global $wp_meta_boxes;
  98  
  99      if ( is_string( $screen ) ) {
 100          $screen = convert_to_screen( $screen );
 101      }
 102  
 103      if ( empty( $wp_meta_boxes[ $screen->id ] ) ) {
 104          return;
 105      }
 106  
 107      $hidden = get_hidden_meta_boxes( $screen );
 108  
 109      foreach ( array_keys( $wp_meta_boxes[ $screen->id ] ) as $context ) {
 110          foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
 111              if ( ! isset( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] ) ) {
 112                  continue;
 113              }
 114              foreach ( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] as $box ) {
 115                  if ( false == $box || ! $box['title'] ) {
 116                      continue;
 117                  }
 118                  // Submit box cannot be hidden.
 119                  if ( 'submitdiv' === $box['id'] || 'linksubmitdiv' === $box['id'] ) {
 120                      continue;
 121                  }
 122  
 123                  $widget_title = $box['title'];
 124  
 125                  if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) {
 126                      $widget_title = $box['args']['__widget_basename'];
 127                  }
 128  
 129                  $is_hidden = in_array( $box['id'], $hidden, true );
 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( $is_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 ( in_array( $screen->post_type, array( 'post', 'page', 'attachment' ), true ) ) {
 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: Thu Jul 2 01:00:04 2020 Cross-referenced by PHPXref 0.7.1