+/**
+ * Add a meta box to an edit form.
+ *
+ * @since 2.5.0
+ *
+ * @param string $id String for use in the 'id' attribute of tags.
+ * @param string $title Title of the meta box.
+ * @param string $callback Function that fills the box with the desired content. The function should echo its output.
+ * @param string $page The type of edit page on which to show the box (post, page, link).
+ * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
+ * @param string $priority The priority within the context where the boxes should show ('high', 'low').
+ */
+function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args=null) {
+ global $wp_meta_boxes;
+
+ if ( !isset($wp_meta_boxes) )
+ $wp_meta_boxes = array();
+ if ( !isset($wp_meta_boxes[$page]) )
+ $wp_meta_boxes[$page] = array();
+ if ( !isset($wp_meta_boxes[$page][$context]) )
+ $wp_meta_boxes[$page][$context] = array();
+
+ foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
+ foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
+ if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
+ continue;
+
+ // If a core box was previously added or removed by a plugin, don't add.
+ if ( 'core' == $priority ) {
+ // If core box previously deleted, don't add
+ if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
+ return;
+ // If box was added with default priority, give it core priority to maintain sort order
+ if ( 'default' == $a_priority ) {
+ $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
+ unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
+ }
+ return;
+ }
+ // If no priority given and id already present, use existing priority
+ if ( empty($priority) ) {
+ $priority = $a_priority;
+ // else if we're adding to the sorted priortiy, we don't know the title or callback. Glab them from the previously added context/priority.
+ } elseif ( 'sorted' == $priority ) {
+ $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
+ $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
+ $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
+ }
+ // An id can be in only one priority and one context
+ if ( $priority != $a_priority || $context != $a_context )
+ unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
+ }
+ }
+
+ if ( empty($priority) )
+ $priority = 'low';
+
+ if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
+ $wp_meta_boxes[$page][$context][$priority] = array();
+
+ $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
+}
+
+/**
+ * {@internal Missing Short Description}}
+ *
+ * @since unknown
+ *
+ * @param unknown_type $page
+ * @param unknown_type $context
+ * @param unknown_type $object
+ * @return int number of meta_boxes
+ */
+function do_meta_boxes($page, $context, $object) {
+ global $wp_meta_boxes;
+ static $already_sorted = false;
+
+ //do_action('do_meta_boxes', $page, $context, $object);
+
+ $hidden = get_hidden_meta_boxes($page);
+
+ echo "<div id='$context-sortables' class='meta-box-sortables'>\n";
+
+ $i = 0;
+ do {
+ // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
+ if ( !$already_sorted && $sorted = get_user_option( "meta-box-order_$page", 0, false ) ) {
+ foreach ( $sorted as $box_context => $ids )
+ foreach ( explode(',', $ids) as $id )
+ if ( $id )
+ add_meta_box( $id, null, null, $page, $box_context, 'sorted' );
+ }
+ $already_sorted = true;
+
+ if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
+ break;
+
+ foreach ( array('high', 'sorted', 'core', 'default', 'low') as $priority ) {
+ if ( isset($wp_meta_boxes[$page][$context][$priority]) ) {
+ foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
+ if ( false == $box || ! $box['title'] )
+ continue;
+ $i++;
+ $style = '';
+ if ( in_array($box['id'], $hidden) )
+ $style = 'style="display:none;"';
+ echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . '" ' . $style . '>' . "\n";
+ echo '<div class="handlediv" title="' . __('Click to toggle') . '"><br /></div>';
+ echo "<h3 class='hndle'><span>{$box['title']}</span></h3>\n";
+ echo '<div class="inside">' . "\n";
+ call_user_func($box['callback'], $object, $box);
+ echo "</div>\n";
+ echo "</div>\n";
+ }
+ }
+ }
+ } while(0);
+
+ echo "</div>";
+
+ return $i;
+
+}
+
+/**
+ * Remove a meta box from an edit form.
+ *
+ * @since 2.6.0
+ *
+ * @param string $id String for use in the 'id' attribute of tags.
+ * @param string $page The type of edit page on which to show the box (post, page, link).
+ * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
+ */
+function remove_meta_box($id, $page, $context) {
+ global $wp_meta_boxes;
+
+ if ( !isset($wp_meta_boxes) )
+ $wp_meta_boxes = array();
+ if ( !isset($wp_meta_boxes[$page]) )
+ $wp_meta_boxes[$page] = array();
+ if ( !isset($wp_meta_boxes[$page][$context]) )
+ $wp_meta_boxes[$page][$context] = array();
+
+ foreach ( array('high', 'core', 'default', 'low') as $priority )
+ $wp_meta_boxes[$page][$context][$priority][$id] = false;
+}
+
+/**
+ * {@internal Missing Short Description}}
+ *
+ * @since unknown
+ *
+ * @param unknown_type $page
+ */
+function meta_box_prefs($page) {
+ global $wp_meta_boxes;
+
+ if ( empty($wp_meta_boxes[$page]) )
+ return;
+
+ $hidden = get_hidden_meta_boxes($page);
+
+ foreach ( array_keys($wp_meta_boxes[$page]) as $context ) {
+ foreach ( array_keys($wp_meta_boxes[$page][$context]) as $priority ) {
+ foreach ( $wp_meta_boxes[$page][$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";
+ }
+ }
+ }
+}
+
+function get_hidden_meta_boxes($page) {
+ $hidden = (array) get_user_option( "meta-box-hidden_$page", 0, false );
+
+ // Hide slug boxes by default
+ if ( empty($hidden[0]) ) {
+ $hidden = array('slugdiv');
+ }
+
+ return $hidden;
+}
+
+/**
+ * Add a new section to a settings page.
+ *
+ * @since 2.7.0
+ *
+ * @param string $id String for use in the 'id' attribute of tags.
+ * @param string $title Title of the section.
+ * @param string $callback Function that fills the section with the desired content. The function should echo its output.
+ * @param string $page The type of settings page on which to show the section (general, reading, writing, ...).
+ */
+function add_settings_section($id, $title, $callback, $page) {
+ global $wp_settings_sections;
+
+ if ( !isset($wp_settings_sections) )
+ $wp_settings_sections = array();
+ if ( !isset($wp_settings_sections[$page]) )
+ $wp_settings_sections[$page] = array();
+ if ( !isset($wp_settings_sections[$page][$id]) )
+ $wp_settings_sections[$page][$id] = array();
+
+ $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
+}
+
+/**
+ * Add a new field to a settings page.
+ *
+ * @since 2.7.0
+ *
+ * @param string $id String for use in the 'id' attribute of tags.
+ * @param string $title Title of the field.
+ * @param string $callback Function that fills the field with the desired content. The function should echo its output.
+ * @param string $page The type of settings page on which to show the field (general, reading, writing, ...).
+ * @param string $section The section of the settingss page in which to show the box (default, ...).
+ * @param array $args Additional arguments
+ */
+function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
+ global $wp_settings_fields;
+
+ if ( !isset($wp_settings_fields) )
+ $wp_settings_fields = array();
+ if ( !isset($wp_settings_fields[$page]) )
+ $wp_settings_fields[$page] = array();
+ if ( !isset($wp_settings_fields[$page][$section]) )
+ $wp_settings_fields[$page][$section] = array();
+
+ $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
+}
+
+/**
+ * {@internal Missing Short Description}}
+ *
+ * @since unknown
+ *
+ * @param unknown_type $page
+ */
+function do_settings_sections($page) {
+ global $wp_settings_sections, $wp_settings_fields;
+
+ if ( !isset($wp_settings_sections) || !isset($wp_settings_sections[$page]) )
+ return;
+
+ foreach ( (array) $wp_settings_sections[$page] as $section ) {
+ echo "<h3>{$section['title']}</h3>\n";
+ call_user_func($section['callback'], $section);
+ if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section['id']]) )
+ continue;
+ echo '<table class="form-table">';
+ do_settings_fields($page, $section['id']);
+ echo '</table>';
+ }
+}
+
+/**
+ * {@internal Missing Short Description}}
+ *
+ * @since unknown
+ *
+ * @param unknown_type $page
+ * @param unknown_type $section
+ */
+function do_settings_fields($page, $section) {
+ global $wp_settings_fields;
+
+ if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section]) )
+ return;
+
+ foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
+ echo '<tr valign="top">';
+ if ( !empty($field['args']['label_for']) )
+ echo '<th scope="row"><label for="' . $field['args']['label_for'] . '">' . $field['title'] . '</label></th>';
+ else
+ echo '<th scope="row">' . $field['title'] . '</th>';
+ echo '<td>';
+ call_user_func($field['callback'], $field['args']);
+ echo '</td>';
+ echo '</tr>';
+ }
+}
+
+/**
+ * {@internal Missing Short Description}}
+ *
+ * @since unknown
+ *
+ * @param unknown_type $page
+ */
+function manage_columns_prefs($page) {
+ $columns = get_column_headers($page);
+
+ $hidden = get_hidden_columns($page);
+
+ foreach ( $columns as $column => $title ) {
+ // Can't hide these
+ if ( 'cb' == $column || 'title' == $column || 'name' == $column || 'username' == $column || 'media' == $column || 'comment' == $column )
+ continue;
+ if ( empty($title) )
+ continue;
+
+ if ( 'comments' == $column )
+ $title = __('Comments');
+ $id = "$column-hide";
+ echo '<label for="' . $id . '">';
+ echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . (! in_array($column, $hidden) ? ' checked="checked"' : '') . ' />';
+ echo "$title</label>\n";
+ }
+}
+
+/**
+ * {@internal Missing Short Description}}
+ *
+ * @since unknown
+ *
+ * @param unknown_type $found_action
+ */
+function find_posts_div($found_action = '') {
+?>
+ <div id="find-posts" class="find-box" style="display:none;">
+ <div id="find-posts-head" class="find-box-head"><?php _e('Find Posts or Pages'); ?></div>
+ <div class="find-box-inside">
+ <div class="find-box-search">
+ <?php if ( $found_action ) { ?>
+ <input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" />
+ <?php } ?>
+
+ <input type="hidden" name="affected" id="affected" value="" />
+ <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
+ <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
+ <input type="text" id="find-posts-input" name="ps" value="" />
+ <input type="button" onclick="findPosts.send();" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /><br />
+
+ <input type="radio" name="find-posts-what" id="find-posts-posts" checked="checked" value="posts" />
+ <label for="find-posts-posts"><?php _e( 'Posts' ); ?></label>
+ <input type="radio" name="find-posts-what" id="find-posts-pages" value="pages" />
+ <label for="find-posts-pages"><?php _e( 'Pages' ); ?></label>
+ </div>
+ <div id="find-posts-response"></div>
+ </div>
+ <div class="find-box-buttons">
+ <input type="button" class="button alignleft" onclick="findPosts.close();" value="<?php esc_attr_e('Close'); ?>" />
+ <input id="find-posts-submit" type="submit" class="button-primary alignright" value="<?php esc_attr_e('Select'); ?>" />
+ </div>
+ </div>
+<?php
+}
+
+/**
+ * Display the post password.
+ *
+ * The password is passed through {@link esc_attr()} to ensure that it
+ * is safe for placing in an html attribute.
+ *
+ * @uses attr
+ * @since 2.7.0
+ */
+function the_post_password() {
+ global $post;
+ if ( isset( $post->post_password ) ) echo esc_attr( $post->post_password );
+}
+
+/**
+ * {@internal Missing Short Description}}
+ *
+ * @since unknown
+ */
+function favorite_actions( $screen = null ) {
+ switch ( $screen ) {
+ case 'post-new.php':
+ $default_action = array('edit.php' => array(__('Edit Posts'), 'edit_posts'));
+ break;
+ case 'edit-pages.php':
+ $default_action = array('page-new.php' => array(__('New Page'), 'edit_pages'));
+ break;
+ case 'page-new.php':
+ $default_action = array('edit-pages.php' => array(__('Edit Pages'), 'edit_pages'));
+ break;
+ case 'upload.php':
+ $default_action = array('media-new.php' => array(__('New Media'), 'upload_files'));
+ break;
+ case 'media-new.php':
+ $default_action = array('upload.php' => array(__('Edit Media'), 'upload_files'));
+ break;
+ case 'link-manager.php':
+ $default_action = array('link-add.php' => array(__('New Link'), 'manage_links'));
+ break;
+ case 'link-add.php':
+ $default_action = array('link-manager.php' => array(__('Edit Links'), 'manage_links'));
+ break;
+ case 'users.php':
+ $default_action = array('user-new.php' => array(__('New User'), 'create_users'));
+ break;
+ case 'user-new.php':
+ $default_action = array('users.php' => array(__('Edit Users'), 'edit_users'));
+ break;
+ case 'plugins.php':
+ $default_action = array('plugin-install.php' => array(__('Install Plugins'), 'install_plugins'));
+ break;
+ case 'plugin-install.php':
+ $default_action = array('plugins.php' => array(__('Manage Plugins'), 'activate_plugins'));
+ break;
+ case 'themes.php':
+ $default_action = array('theme-install.php' => array(__('Install Themes'), 'install_themes'));
+ break;
+ case 'theme-install.php':
+ $default_action = array('themes.php' => array(__('Manage Themes'), 'switch_themes'));
+ break;
+ default:
+ $default_action = array('post-new.php' => array(__('New Post'), 'edit_posts'));
+ break;
+ }
+
+ $actions = array(
+ 'post-new.php' => array(__('New Post'), 'edit_posts'),
+ 'edit.php?post_status=draft' => array(__('Drafts'), 'edit_posts'),
+ 'page-new.php' => array(__('New Page'), 'edit_pages'),
+ 'media-new.php' => array(__('Upload'), 'upload_files'),
+ 'edit-comments.php' => array(__('Comments'), 'moderate_comments')
+ );
+
+ $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);
+
+ $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";
+}
+
+/**
+ * Get the post title.
+ *
+ * The post title is fetched and if it is blank then a default string is
+ * returned.
+ *
+ * @since 2.7.0
+ * @param int $id The post id. If not supplied the global $post is used.
+ *
+ */
+function _draft_or_post_title($post_id = 0)
+{
+ $title = get_the_title($post_id);
+ if ( empty($title) )
+ $title = __('(no title)');
+ return $title;
+}
+
+/**
+ * Display the search query.
+ *
+ * A simple wrapper to display the "s" parameter in a GET URI. This function
+ * should only be used when {@link the_search_query()} cannot.
+ *
+ * @uses attr
+ * @since 2.7.0
+ *
+ */
+function _admin_search_query() {
+ echo isset($_GET['s']) ? esc_attr( stripslashes( $_GET['s'] ) ) : '';
+}
+
+/**
+ * Generic Iframe header for use with Thickbox
+ *
+ * @since 2.7.0
+ * @param string $title Title of the Iframe page.
+ * @param bool $limit_styles Limit styles to colour-related styles only (unless others are enqueued).
+ *
+ */
+function iframe_header( $title = '', $limit_styles = false ) {
+?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
+<head>
+<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
+<title><?php bloginfo('name') ?> › <?php echo $title ?> — <?php _e('WordPress'); ?></title>
+<?php
+wp_enqueue_style( 'global' );
+if ( ! $limit_styles )
+ wp_enqueue_style( 'wp-admin' );
+wp_enqueue_style( 'colors' );
+?>
+<script type="text/javascript">
+//<![CDATA[
+addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
+function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
+//]]>
+</script>
+<?php
+do_action('admin_print_styles');
+do_action('admin_print_scripts');
+do_action('admin_head');
+?>
+</head>
+<body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?>>
+<?php
+}
+
+/**
+ * Generic Iframe footer for use with Thickbox
+ *
+ * @since 2.7.0
+ *
+ */
+function iframe_footer() {
+ //We're going to hide any footer output on iframe pages, but run the hooks anyway since they output Javascript or other needed content. ?>
+ <div class="hidden">
+<?php
+ do_action('admin_footer', '');
+ do_action('admin_print_footer_scripts'); ?>
+ </div>
+<script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script>
+</body>
+</html>
+<?php
+}
+
+function _post_states($post) {
+ $post_states = array();
+ if ( isset($_GET['post_status']) )
+ $post_status = $_GET['post_status'];
+ else
+ $post_status = '';
+
+ if ( !empty($post->post_password) )
+ $post_states[] = __('Password protected');
+ if ( 'private' == $post->post_status && 'private' != $post_status )
+ $post_states[] = __('Private');
+ if ( 'draft' == $post->post_status && 'draft' != $post_status )
+ $post_states[] = __('Draft');
+ if ( 'pending' == $post->post_status && 'pending' != $post_status )
+ /* translators: post state */
+ $post_states[] = _x('Pending', 'post state');
+ if ( is_sticky($post->ID) )
+ $post_states[] = __('Sticky');
+
+ $post_states = apply_filters( 'display_post_states', $post_states );
+
+ if ( ! empty($post_states) ) {
+ $state_count = count($post_states);
+ $i = 0;
+ echo ' - ';
+ foreach ( $post_states as $state ) {
+ ++$i;
+ ( $i == $state_count ) ? $sep = '' : $sep = ', ';
+ echo "<span class='post-state'>$state$sep</span>";
+ }
+ }
+}
+
+function screen_meta($screen) {
+ global $wp_meta_boxes, $_wp_contextual_help;
+
+ $screen = str_replace('.php', '', $screen);
+ $screen = str_replace('-new', '', $screen);
+ $screen = str_replace('-add', '', $screen);
+ $screen = apply_filters('screen_meta_screen', $screen);
+
+ $column_screens = get_column_headers($screen);
+ $meta_screens = array('index' => 'dashboard');
+
+ if ( isset($meta_screens[$screen]) )
+ $screen = $meta_screens[$screen];
+ $show_screen = false;
+ $show_on_screen = false;
+ if ( !empty($wp_meta_boxes[$screen]) || !empty($column_screens) ) {
+ $show_screen = true;
+ $show_on_screen = true;
+ }
+
+ $screen_options = screen_options($screen);
+ if ( $screen_options )
+ $show_screen = true;
+
+ if ( !isset($_wp_contextual_help) )
+ $_wp_contextual_help = array();
+
+ $settings = '';
+
+ switch ( $screen ) {
+ case 'post':
+ if ( !isset($_wp_contextual_help['post']) ) {
+ $help = drag_drop_help();
+ $help .= '<p>' . __('<a href="http://codex.wordpress.org/Writing_Posts" target="_blank">Writing Posts</a>') . '</p>';
+ $_wp_contextual_help['post'] = $help;
+ }
+ break;
+ case 'page':
+ if ( !isset($_wp_contextual_help['page']) ) {
+ $help = drag_drop_help();
+ $_wp_contextual_help['page'] = $help;
+ }
+ break;
+ case 'dashboard':
+ if ( !isset($_wp_contextual_help['dashboard']) ) {
+ $help = '<p>' . __('The modules on this screen can be arranged in several columns. You can select the number of columns from the Screen Options tab.') . "</p>\n";
+ $help .= drag_drop_help();
+ $_wp_contextual_help['dashboard'] = $help;
+ }
+ break;
+ case 'link':
+ if ( !isset($_wp_contextual_help['link']) ) {
+ $help = drag_drop_help();
+ $_wp_contextual_help['link'] = $help;
+ }
+ break;
+ case 'options-general':
+ if ( !isset($_wp_contextual_help['options-general']) )
+ $_wp_contextual_help['options-general'] = __('<a href="http://codex.wordpress.org/Settings_General_SubPanel" target="_blank">General Settings</a>');
+ break;
+ case 'theme-install':
+ case 'plugin-install':
+ if ( ( !isset($_GET['tab']) || 'dashboard' == $_GET['tab'] ) && !isset($_wp_contextual_help[$screen]) ) {
+ $help = plugins_search_help();
+ $_wp_contextual_help[$screen] = $help;
+ }
+ break;
+ case 'widgets':
+ if ( !isset($_wp_contextual_help['widgets']) ) {
+ $help = widgets_help();
+ $_wp_contextual_help['widgets'] = $help;
+ }
+ $settings = '<p><a id="access-on" href="widgets.php?widgets-access=on">' . __('Enable accessibility mode') . '</a><a id="access-off" href="widgets.php?widgets-access=off">' . __('Disable accessibility mode') . "</a></p>\n";
+ $show_screen = true;
+ break;
+ }
+?>
+<div id="screen-meta">
+<?php
+ if ( $show_screen ) :
+?>
+<div id="screen-options-wrap" class="hidden">
+ <form id="adv-settings" action="" method="post">
+<?php if ( $show_on_screen ) : ?>
+ <h5><?php _e('Show on screen') ?></h5>
+ <div class="metabox-prefs">
+<?php
+ if ( !meta_box_prefs($screen) && isset($column_screens) ) {
+ manage_columns_prefs($screen);
+ }
+?>
+ <br class="clear" />
+ </div>
+<?php endif; ?>
+<?php echo screen_layout($screen); ?>
+<?php echo $screen_options; ?>
+<?php echo $settings; ?>
+<div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>
+</form>
+</div>
+
+<?php
+ endif;
+
+ global $title;
+
+ $_wp_contextual_help = apply_filters('contextual_help_list', $_wp_contextual_help, $screen);
+ ?>
+ <div id="contextual-help-wrap" class="hidden">
+ <?php
+ $contextual_help = '';
+ if ( isset($_wp_contextual_help[$screen]) ) {
+ if ( !empty($title) )
+ $contextual_help .= '<h5>' . sprintf(__('Get help with “%s”'), $title) . '</h5>';
+ else
+ $contextual_help .= '<h5>' . __('Get help with this page') . '</h5>';
+ $contextual_help .= '<div class="metabox-prefs">' . $_wp_contextual_help[$screen] . "</div>\n";
+
+ $contextual_help .= '<h5>' . __('Other Help') . '</h5>';
+ } else {
+ $contextual_help .= '<h5>' . __('Help') . '</h5>';
+ }
+
+ $contextual_help .= '<div class="metabox-prefs">';
+ $default_help = __('<a href="http://codex.wordpress.org/" target="_blank">Documentation</a>');
+ $default_help .= '<br />';
+ $default_help .= __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>');
+ $contextual_help .= apply_filters('default_contextual_help', $default_help);
+ $contextual_help .= "</div>\n";
+ echo apply_filters('contextual_help', $contextual_help, $screen);
+ ?>
+ </div>
+
+<div id="screen-meta-links">
+<div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
+<a href="#contextual-help" id="contextual-help-link" class="show-settings"><?php _e('Help') ?></a>
+</div>
+<?php if ( $show_screen ) { ?>
+<div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
+<a href="#screen-options" id="show-settings-link" class="show-settings"><?php _e('Screen Options') ?></a>
+</div>
+<?php } ?>
+</div>
+</div>
+<?php
+}
+
+/**
+ * Add contextual help text for a page
+ *
+ * @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 Arbitrary help text
+ */
+function add_contextual_help($screen, $help) {
+ global $_wp_contextual_help;
+
+ if ( !isset($_wp_contextual_help) )
+ $_wp_contextual_help = array();
+
+ $_wp_contextual_help[$screen] = $help;
+}
+
+function drag_drop_help() {
+ return '
+ <p>' . __('Most of the modules on this screen can be moved. If you hover your mouse over the title bar of a module you’ll notice the 4 arrow cursor appears to let you know it is movable. Click on it, hold down the mouse button and start dragging the module to a new location. As you drag the module, notice the dotted gray box that also moves. This box indicates where the module will be placed when you release the mouse button.') . '</p>
+ <p>' . __('The same modules can be expanded and collapsed by clicking once on their title bar and also completely hidden from the Screen Options tab.') . '</p>
+';
+}
+
+function plugins_search_help() {
+ return '
+ <p><strong>' . __('Search help') . '</strong></p>' .
+ '<p>' . __('You may search based on 3 criteria:') . '<br />' .
+ __('<strong>Term:</strong> Searches theme names and descriptions for the specified term.') . '<br />' .
+ __('<strong>Tag:</strong> Searches for themes tagged as such.') . '<br />' .
+ __('<strong>Author:</strong> Searches for themes created by the Author, or which the Author contributed to.') . '</p>
+';
+}
+
+function widgets_help() {
+ return '
+ <p>' . __('Widgets are added and arranged by simple drag ’n’ drop. If you hover your mouse over the titlebar of a widget, you’ll see a 4-arrow cursor which indicates that the widget is movable. Click on the titlebar, hold down the mouse button and drag the widget to a sidebar. As you drag, you’ll see a dotted box that also moves. This box shows where the widget will go once you drop it.') . '</p>
+ <p>' . __('To remove a widget from a sidebar, drag it back to Available Widgets or click on the arrow on its titlebar to reveal its settings, and then click Remove.') . '</p>
+ <p>' . __('To remove a widget from a sidebar <em>and keep its configuration</em>, drag it to Inactive Widgets.') . '</p>
+ <p>' . __('The Inactive Widgets area stores widgets that are configured but not curently used. If you change themes and the new theme has fewer sidebars than the old, all extra widgets will be stored to Inactive Widgets automatically.') . '</p>
+';
+}
+
+function screen_layout($screen) {
+ global $screen_layout_columns;
+
+ $columns = array('dashboard' => 4, 'post' => 2, 'page' => 2, 'link' => 2);
+ $columns = apply_filters('screen_layout_columns', $columns, $screen);
+
+ if ( !isset($columns[$screen]) ) {
+ $screen_layout_columns = 0;
+ return '';
+ }
+
+ $screen_layout_columns = get_user_option("screen_layout_$screen");
+ $num = $columns[$screen];
+
+ if ( ! $screen_layout_columns )
+ $screen_layout_columns = 2;
+
+ $i = 1;
+ $return = '<h5>' . __('Screen Layout') . "</h5>\n<div class='columns-prefs'>" . __('Number of Columns:') . "\n";
+ while ( $i <= $num ) {
+ $return .= "<label><input type='radio' name='screen_columns' value='$i'" . ( ($screen_layout_columns == $i) ? " checked='checked'" : "" ) . " /> $i</label>\n";
+ ++$i;
+ }
+ $return .= "</div>\n";
+ return $return;
+}
+
+function screen_options($screen) {
+ switch ( $screen ) {
+ case 'edit':
+ $per_page_label = __('Posts per page:');
+ break;
+ case 'edit-pages':
+ $per_page_label = __('Pages per page:');
+ break;
+ case 'edit-comments':
+ $per_page_label = __('Comments per page:');
+ break;
+ case 'upload':
+ $per_page_label = __('Media items per page:');
+ break;
+ case 'categories':
+ $per_page_label = __('Categories per page:');
+ break;
+ case 'edit-tags':
+ $per_page_label = __('Tags per page:');
+ break;
+ case 'plugins':
+ $per_page_label = __('Plugins per page:');
+ break;
+ default:
+ return '';
+ }
+
+ $option = str_replace( '-', '_', "${screen}_per_page" );
+ $per_page = (int) get_user_option( $option, 0, false );
+ if ( empty( $per_page ) || $per_page < 1 ) {
+ if ( 'plugins' == $screen )
+ $per_page = 999;
+ else
+ $per_page = 20;
+ }
+ if ( 'edit_comments_per_page' == $option )
+ $per_page = apply_filters( 'comments_per_page', $per_page, isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all' );
+ elseif ( 'categories' == $option )
+ $per_page = apply_filters( 'edit_categories_per_page', $per_page );
+ else
+ $per_page = apply_filters( $option, $per_page );
+
+ $return = '<h5>' . __('Options') . "</h5>\n";
+ $return .= "<div class='screen-options'>\n";
+ if ( !empty($per_page_label) )
+ $return .= "<label for='$option'>$per_page_label</label> <input type='text' class='screen-per-page' name='wp_screen_options[value]' id='$option' maxlength='3' value='$per_page' />\n";
+ $return .= "<input type='submit' class='button' value='" . esc_attr__('Apply') . "' />";
+ $return .= "<input type='hidden' name='wp_screen_options[option]' value='" . esc_attr($option) . "' />";
+ $return .= "</div>\n";
+ return $return;
+}
+
+function screen_icon($name = '') {
+ global $parent_file, $hook_suffix;
+
+ if ( empty($name) ) {
+ if ( isset($parent_file) && !empty($parent_file) )
+ $name = substr($parent_file, 0, -4);
+ else
+ $name = str_replace(array('.php', '-new', '-add'), '', $hook_suffix);
+ }
+?>
+ <div id="icon-<?php echo $name; ?>" class="icon32"><br /></div>
+<?php
+}
+
+/**
+ * Test support for compressing JavaScript from PHP
+ *
+ * Outputs JavaScript that tests if compression from PHP works as expected
+ * and sets an option with the result. Has no effect when the current user
+ * is not an administrator. To run the test again the option 'can_compress_scripts'
+ * has to be deleted.
+ *
+ * @since 2.8.0
+ */
+function compression_test() {
+?>
+ <script type="text/javascript">
+ /* <![CDATA[ */
+ var testCompression = {
+ get : function(test) {
+ var x;
+ if ( window.XMLHttpRequest ) {
+ x = new XMLHttpRequest();
+ } else {
+ try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
+ }
+
+ if (x) {
+ x.onreadystatechange = function() {
+ var r, h;
+ if ( x.readyState == 4 ) {
+ r = x.responseText.substr(0, 18);
+ h = x.getResponseHeader('Content-Encoding');
+ testCompression.check(r, h, test);
+ }
+ }
+
+ x.open('GET', 'admin-ajax.php?action=wp-compression-test&test='+test+'&'+(new Date()).getTime(), true);
+ x.send('');
+ }
+ },
+
+ check : function(r, h, test) {
+ if ( ! r && ! test )
+ this.get(1);
+
+ if ( 1 == test ) {
+ if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) )
+ this.get('no');
+ else
+ this.get(2);
+
+ return;
+ }
+
+ if ( 2 == test ) {
+ if ( '"wpCompressionTest' == r )
+ this.get('yes');
+ else
+ this.get('no');
+ }
+ }
+ };
+ testCompression.check();
+ /* ]]> */
+ </script>
+<?php
+}
+