";
return $r;
}
/**
* {@internal Missing Short Description}}
*
* @since 1.2.0
*/
function meta_form() {
global $wpdb;
$limit = (int) apply_filters( 'postmeta_form_limit', 30 );
$keys = $wpdb->get_col( "
SELECT meta_key
FROM $wpdb->postmeta
GROUP BY meta_key
HAVING meta_key NOT LIKE '\_%'
ORDER BY meta_key
LIMIT $limit" );
if ( $keys )
natcasesort($keys);
?>
";
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 2.7.0
*
* @param unknown_type $screen
*/
function meta_box_prefs($screen) {
global $wp_meta_boxes;
if ( is_string($screen) )
$screen = convert_to_screen($screen);
if ( empty($wp_meta_boxes[$screen->id]) )
return;
$hidden = get_hidden_meta_boxes($screen);
foreach ( array_keys($wp_meta_boxes[$screen->id]) as $context ) {
foreach ( array_keys($wp_meta_boxes[$screen->id][$context]) as $priority ) {
foreach ( $wp_meta_boxes[$screen->id][$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 '\n";
}
}
}
}
/**
* Get Hidden Meta Boxes
*
* @since 2.7.0
*
* @param string|object $screen Screen identifier
* @return array Hidden Meta Boxes
*/
function get_hidden_meta_boxes( $screen ) {
if ( is_string( $screen ) )
$screen = convert_to_screen( $screen );
$hidden = get_user_option( "metaboxhidden_{$screen->id}" );
// Hide slug boxes by default
if ( !is_array( $hidden ) ) {
if ( 'post' == $screen->base || 'page' == $screen->base )
$hidden = array('slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv');
else
$hidden = array( 'slugdiv' );
$hidden = apply_filters('default_hidden_meta_boxes', $hidden, $screen);
}
return $hidden;
}
/**
* Add a new section to a settings page.
*
* Part of the Settings API. Use this to define new settings sections for an admin page.
* Show settings sections in your admin page callback function with do_settings_sections().
* Add settings fields to your section with add_settings_field()
*
* The $callback argument should be the name of a function that echoes out any
* content you want to show at the top of the settings section before the actual
* fields. It can output nothing if you want.
*
* @since 2.7.0
*
* @global $wp_settings_sections Storage array of all settings sections added to admin pages
*
* @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags.
* @param string $title Formatted title of the section. Shown as the heading for the section.
* @param string $callback Function that echos out any content at the top of the section (between heading and fields).
* @param string $page The slug-name of the settings page on which to show the section. Built-in pages include 'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using add_options_page();
*/
function add_settings_section($id, $title, $callback, $page) {
global $wp_settings_sections;
if ( 'misc' == $page ) {
_deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
$page = 'general';
}
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 section of a settings page
*
* Part of the Settings API. Use this to define a settings field that will show
* as part of a settings section inside a settings page. The fields are shown using
* do_settings_fields() in do_settings-sections()
*
* The $callback argument should be the name of a function that echoes out the
* html input tags for this setting field. Use get_option() to retrieve existing
* values to show.
*
* @since 2.7.0
*
* @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
*
* @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags.
* @param string $title Formatted title of the field. Shown as the label for the field during output.
* @param string $callback Function that fills the field with the desired form inputs. The function should echo its output.
* @param string $page The slug-name of the settings page on which to show the section (general, reading, writing, ...).
* @param string $section The slug-name of the section of the settings 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 ( 'misc' == $page ) {
_deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
$page = 'general';
}
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);
}
/**
* Prints out all settings sections added to a particular settings page
*
* Part of the Settings API. Use this in a settings page callback function
* to output all the sections and fields that were added to that $page with
* add_settings_section() and add_settings_field()
*
* @global $wp_settings_sections Storage array of all settings sections added to admin pages
* @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
* @since 2.7.0
*
* @param string $page The slug name of the page whos settings sections you want to output
*/
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 ) {
if ( $section['title'] )
echo "
';
}
}
/**
* Print out the settings fields for a particular settings section
*
* Part of the Settings API. Use this in a settings page to output
* a specific section. Should normally be called by do_settings_sections()
* rather than directly.
*
* @global $wp_settings_fields Storage array of settings fields and their pages/sections
*
* @since 2.7.0
*
* @param string $page Slug title of the admin page who's settings fields you want to show.
* @param section $section Slug title of the settings section who's fields you want to show.
*/
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 '
';
if ( !empty($field['args']['label_for']) )
echo '
';
}
}
/**
* Register a settings error to be displayed to the user
*
* Part of the Settings API. Use this to show messages to users about settings validation
* problems, missing settings or anything else.
*
* Settings errors should be added inside the $sanitize_callback function defined in
* register_setting() for a given setting to give feedback about the submission.
*
* By default messages will show immediately after the submission that generated the error.
* Additional calls to settings_errors() can be used to show errors even when the settings
* page is first accessed.
*
* @since 3.0.0
*
* @global array $wp_settings_errors Storage array of errors registered during this pageload
*
* @param string $setting Slug title of the setting to which this error applies
* @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
* @param string $message The formatted message text to display to the user (will be shown inside styled
and
)
* @param string $type The type of message it is, controls HTML class. Use 'error' or 'updated'.
*/
function add_settings_error( $setting, $code, $message, $type = 'error' ) {
global $wp_settings_errors;
if ( !isset($wp_settings_errors) )
$wp_settings_errors = array();
$new_error = array(
'setting' => $setting,
'code' => $code,
'message' => $message,
'type' => $type
);
$wp_settings_errors[] = $new_error;
}
/**
* Fetch settings errors registered by add_settings_error()
*
* Checks the $wp_settings_errors array for any errors declared during the current
* pageload and returns them.
*
* If changes were just submitted ($_GET['settings-updated']) and settings errors were saved
* to the 'settings_errors' transient then those errors will be returned instead. This
* is used to pass errors back across pageloads.
*
* Use the $sanitize argument to manually re-sanitize the option before returning errors.
* This is useful if you have errors or notices you want to show even when the user
* hasn't submitted data (i.e. when they first load an options page, or in admin_notices action hook)
*
* @since 3.0.0
*
* @global array $wp_settings_errors Storage array of errors registered during this pageload
*
* @param string $setting Optional slug title of a specific setting who's errors you want.
* @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
* @return array Array of settings errors
*/
function get_settings_errors( $setting = '', $sanitize = FALSE ) {
global $wp_settings_errors;
// If $sanitize is true, manually re-run the sanitizisation for this option
// This allows the $sanitize_callback from register_setting() to run, adding
// any settings errors you want to show by default.
if ( $sanitize )
sanitize_option( $setting, get_option($setting));
// If settings were passed back from options.php then use them
// Ignore transients if $sanitize is true, we don't want the old values anyway
if ( isset($_GET['settings-updated']) && $_GET['settings-updated'] && get_transient('settings_errors') ) {
$settings_errors = get_transient('settings_errors');
delete_transient('settings_errors');
// Otherwise check global in case validation has been run on this pageload
} elseif ( count( $wp_settings_errors ) ) {
$settings_errors = $wp_settings_errors;
} else {
return;
}
// Filter the results to those of a specific setting if one was set
if ( $setting ) {
foreach ( (array) $settings_errors as $key => $details )
if ( $setting != $details['setting'] )
unset( $settings_errors[$key] );
}
return $settings_errors;
}
/**
* Display settings errors registered by add_settings_error()
*
* Part of the Settings API. Outputs a
for each error retrieved by get_settings_errors().
*
* This is called automatically after a settings page based on the Settings API is submitted.
* Errors should be added during the validation callback function for a setting defined in register_setting()
*
* The $sanitize option is passed into get_settings_errors() and will re-run the setting sanitization
* on its current value.
*
* The $hide_on_update option will cause errors to only show when the settings page is first loaded.
* if the user has already saved new values it will be hidden to avoid repeating messages already
* shown in the default error reporting after submission. This is useful to show general errors like missing
* settings when the user arrives at the settings page.
*
* @since 3.0.0
*
* @param string $setting Optional slug title of a specific setting who's errors you want.
* @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
* @param boolean $hide_on_update If set to true errors will not be shown if the settings page has already been submitted.
*/
function settings_errors( $setting = '', $sanitize = FALSE, $hide_on_update = FALSE ) {
if ($hide_on_update AND $_GET['settings-updated']) return;
$settings_errors = get_settings_errors( $setting, $sanitize );
if ( !is_array($settings_errors) ) return;
$output = '';
foreach ( $settings_errors as $key => $details ) {
$css_id = 'setting-error-' . $details['code'];
$css_class = $details['type'] . ' settings-error';
$output .= "
\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 $post_id The post id. If not supplied the global $post is used.
* @return string The post title if set
*/
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($_REQUEST['s']) ? esc_attr( stripslashes( $_REQUEST['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 ) {
show_admin_bar( false );
global $hook_suffix, $current_screen, $current_user, $admin_body_class, $wp_locale;
$admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
$admin_body_class .= ' iframe';
?>
>
› —
class="no-js ">
\n";
$show_screen = true;
break;
}
if ( ! empty( $settings ) )
$show_screen = true;
if ( !empty($wp_current_screen_options) )
$show_screen = true;
$show_screen = apply_filters('screen_options_show_screen', $show_screen, $screen);
// If we have screen options, add the menu to the admin bar.
if ( $show_screen )
add_action( 'admin_bar_menu', 'wp_admin_bar_screen_options_menu', 80 );
?>
' . "\n";
/*
* Loop through ['contextual-help-tabs']
* - It's a nested array where $key=>$value >> $title=>$content
* Has no output so can only loop the array once
*/
$contextual_help_tabs = ''; // store looped content for later
$contextual_help_panels = ''; // store looped content for later
$tab_active = true;
foreach ( $_wp_contextual_help[$screen->id]['tabs'] as $tab ) {
$tab_slug = sanitize_html_class( $tab[ 0 ] );
$contextual_help_tabs .= '
array( $tab1_title => $tab1_value [, $tab2_title => $tab2_value, ...] ),
* 'contextual-help-links' => $help_links_as_string )
*
* For backwards compatability, a string is also accepted.
*
* @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 array|string $help Creates tabs & links columns within help text in array.
*
*/
function add_contextual_help($screen, $help) {
global $_wp_contextual_help;
if ( is_string($screen) )
$screen = convert_to_screen($screen);
if ( !isset($_wp_contextual_help) )
$_wp_contextual_help = array();
$_wp_contextual_help[$screen->id] = $help;
}
function screen_layout($screen) {
global $screen_layout_columns, $wp_current_screen_options;
if ( is_string($screen) )
$screen = convert_to_screen($screen);
// Back compat for plugins using the filter instead of add_screen_option()
$columns = apply_filters('screen_layout_columns', array(), $screen->id, $screen);
if ( !empty($columns) && isset($columns[$screen->id]) )
add_screen_option('layout_columns', array('max' => $columns[$screen->id]) );
if ( !isset($wp_current_screen_options['layout_columns']) ) {
$screen_layout_columns = 0;
return '';
}
$screen_layout_columns = get_user_option("screen_layout_$screen->id");
$num = $wp_current_screen_options['layout_columns']['max'];
if ( ! $screen_layout_columns ) {
if ( isset($wp_current_screen_options['layout_columns']['default']) )
$screen_layout_columns = $wp_current_screen_options['layout_columns']['default'];
else
$screen_layout_columns = 'auto';
}
$i = 1;
$return = '
';
}
/**
* 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() {
?>
'1' ).
* These attributes will be output as attribute="value", such as tabindex="1".
* Defaults to no other attributes. Other attributes can also be provided as a
* string such as 'tabindex="1"', though the array format is typically cleaner.
*/
function submit_button( $text = NULL, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = NULL ) {
echo get_submit_button( $text, $type, $name, $wrap, $other_attributes );
}
/**
* Returns a submit button, with provided text and appropriate class
*
* @since 3.1.0
*
* @param string $text The text of the button (defaults to 'Save Changes')
* @param string $type The type of button. One of: primary, secondary, delete
* @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute
* is given in $other_attributes below, $name will be used as the button's id.
* @param bool $wrap True if the output button should be wrapped in a paragraph tag,
* false otherwise. Defaults to true
* @param array|string $other_attributes Other attributes that should be output with the button,
* mapping attributes to their values, such as array( 'tabindex' => '1' ).
* These attributes will be output as attribute="value", such as tabindex="1".
* Defaults to no other attributes. Other attributes can also be provided as a
* string such as 'tabindex="1"', though the array format is typically cleaner.
*/
function get_submit_button( $text = NULL, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = NULL ) {
switch ( $type ) :
case 'primary' :
case 'secondary' :
$class = 'button-' . $type;
break;
case 'delete' :
$class = 'button-secondary delete';
break;
default :
$class = $type; // Custom cases can just pass in the classes they want to be used
endswitch;
$text = ( NULL == $text ) ? __( 'Save Changes' ) : $text;
// Default the id attribute to $name unless an id was specifically provided in $other_attributes
$id = $name;
if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) {
$id = $other_attributes['id'];
unset( $other_attributes['id'] );
}
$attributes = '';
if ( is_array( $other_attributes ) ) {
foreach ( $other_attributes as $attribute => $value ) {
$attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
}
} else if ( !empty( $other_attributes ) ) { // Attributes provided as a string
$attributes = $other_attributes;
}
$button = '';
if ( $wrap ) {
$button = '