),
array( '#413256', '#523f6d', '#a3b745', '#d46f15' ),
array(
'base' => '#ece6f6',
'focus' => '#fff',
'current' => '#fff',
)
);
wp_admin_css_color(
'ocean',
_x( 'Ocean', 'admin color scheme' ),
admin_url( "css/colors/ocean/colors$suffix.css" ),
array( '#627c83', '#738e96', '#9ebaa0', '#aa9d88' ),
array(
'base' => '#f2fcff',
'focus' => '#fff',
'current' => '#fff',
)
);
wp_admin_css_color(
'coffee',
_x( 'Coffee', 'admin color scheme' ),
admin_url( "css/colors/coffee/colors$suffix.css" ),
array( '#46403c', '#59524c', '#c7a589', '#9ea476' ),
array(
'base' => '#f3f2f1',
'focus' => '#fff',
'current' => '#fff',
)
);
}
/**
* Displays the URL of a WordPress admin CSS file.
*
* @see WP_Styles::_css_href() and its {@see 'style_loader_src'} filter.
*
* @since 2.3.0
*
* @param string $file file relative to wp-admin/ without its ".css" extension.
* @return string
*/
function wp_admin_css_uri( $file = 'wp-admin' ) {
if ( defined( 'WP_INSTALLING' ) ) {
$_file = "./$file.css";
} else {
$_file = admin_url( "$file.css" );
}
$_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file );
/**
* Filters the URI of a WordPress admin CSS file.
*
* @since 2.3.0
*
* @param string $_file Relative path to the file with query arguments attached.
* @param string $file Relative path to the file, minus its ".css" extension.
*/
return apply_filters( 'wp_admin_css_uri', $_file, $file );
}
/**
* Enqueues or directly prints a stylesheet link to the specified CSS file.
*
* "Intelligently" decides to enqueue or to print the CSS file. If the
* {@see 'wp_print_styles'} action has *not* yet been called, the CSS file will be
* enqueued. If the {@see 'wp_print_styles'} action has been called, the CSS link will
* be printed. Printing may be forced by passing true as the $force_echo
* (second) parameter.
*
* For backward compatibility with WordPress 2.3 calling method: If the $file
* (first) parameter does not correspond to a registered CSS file, we assume
* $file is a file relative to wp-admin/ without its ".css" extension. A
* stylesheet link to that generated URL is printed.
*
* @since 2.3.0
*
* @param string $file Optional. Style handle name or file name (without ".css" extension) relative
* to wp-admin/. Defaults to 'wp-admin'.
* @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
*/
function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
// For backward compatibility.
$handle = str_starts_with( $file, 'css/' ) ? substr( $file, 4 ) : $file;
if ( wp_styles()->query( $handle ) ) {
if ( $force_echo || did_action( 'wp_print_styles' ) ) {
// We already printed the style queue. Print this one immediately.
wp_print_styles( $handle );
} else {
// Add to style queue.
wp_enqueue_style( $handle );
}
return;
}
$stylesheet_link = sprintf(
"\n",
esc_url( wp_admin_css_uri( $file ) )
);
/**
* Filters the stylesheet link to the specified CSS file.
*
* If the site is set to display right-to-left, the RTL stylesheet link
* will be used instead.
*
* @since 2.3.0
* @param string $stylesheet_link HTML link element for the stylesheet.
* @param string $file Style handle name or filename (without ".css" extension)
* relative to wp-admin/. Defaults to 'wp-admin'.
*/
echo apply_filters( 'wp_admin_css', $stylesheet_link, $file );
if ( function_exists( 'is_rtl' ) && is_rtl() ) {
$rtl_stylesheet_link = sprintf(
"\n",
esc_url( wp_admin_css_uri( "$file-rtl" ) )
);
/** This filter is documented in wp-includes/general-template.php */
echo apply_filters( 'wp_admin_css', $rtl_stylesheet_link, "$file-rtl" );
}
}
/**
* Enqueues the default ThickBox js and css.
*
* If any of the settings need to be changed, this can be done with another js
* file similar to media-upload.js. That file should
* require array('thickbox') to ensure it is loaded after.
*
* @since 2.5.0
*/
function add_thickbox() {
wp_enqueue_script( 'thickbox' );
wp_enqueue_style( 'thickbox' );
if ( is_network_admin() ) {
add_action( 'admin_head', '_thickbox_path_admin_subfolder' );
}
}
/**
* Displays the XHTML generator that is generated on the wp_head hook.
*
* See {@see 'wp_head'}.
*
* @since 2.5.0
*/
function wp_generator() {
/**
* Filters the output of the XHTML generator tag.
*
* @since 2.5.0
*
* @param string $generator_type The XHTML generator.
*/
the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
}
/**
* Displays the generator XML or Comment for RSS, ATOM, etc.
*
* Returns the correct generator type for the requested output format. Allows
* for a plugin to filter generators overall the {@see 'the_generator'} filter.
*
* @since 2.5.0
*
* @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
*/
function the_generator( $type ) {
/**
* Filters the output of the XHTML generator tag for display.
*
* @since 2.5.0
*
* @param string $generator_type The generator output.
* @param string $type The type of generator to output. Accepts 'html',
* 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export'.
*/
echo apply_filters( 'the_generator', get_the_generator( $type ), $type ) . "\n";
}
/**
* Creates the generator XML or Comment for RSS, ATOM, etc.
*
* Returns the correct generator type for the requested output format. Allows
* for a plugin to filter generators on an individual basis using the
* {@see 'get_the_generator_$type'} filter.
*
* @since 2.5.0
*
* @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
* @return string|void The HTML content for the generator.
*/
function get_the_generator( $type = '' ) {
if ( empty( $type ) ) {
$current_filter = current_filter();
if ( empty( $current_filter ) ) {
return;
}
switch ( $current_filter ) {
case 'rss2_head':
case 'commentsrss2_head':
$type = 'rss2';
break;
case 'rss_head':
case 'opml_head':
$type = 'comment';
break;
case 'rdf_header':
$type = 'rdf';
break;
case 'atom_head':
case 'comments_atom_head':
case 'app_head':
$type = 'atom';
break;
}
}
switch ( $type ) {
case 'html':
$gen = '';
break;
case 'xhtml':
$gen = '';
break;
case 'atom':
$gen = 'WordPress';
break;
case 'rss2':
$gen = '' . sanitize_url( 'https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) ) . '';
break;
case 'rdf':
$gen = '';
break;
case 'comment':
$gen = '';
break;
case 'export':
$gen = '';
break;
}
/**
* Filters the HTML for the retrieved generator type.
*
* The dynamic portion of the hook name, `$type`, refers to the generator type.
*
* Possible hook names include:
*
* - `get_the_generator_atom`
* - `get_the_generator_comment`
* - `get_the_generator_export`
* - `get_the_generator_html`
* - `get_the_generator_rdf`
* - `get_the_generator_rss2`
* - `get_the_generator_xhtml`
*
* @since 2.5.0
*
* @param string $gen The HTML markup output to wp_head().
* @param string $type The type of generator. Accepts 'html', 'xhtml', 'atom',
* 'rss2', 'rdf', 'comment', 'export'.
*/
return apply_filters( "get_the_generator_{$type}", $gen, $type );
}
/**
* Outputs the HTML checked attribute.
*
* Compares the first two arguments and if identical marks as checked.
*
* @since 1.0.0
*
* @param mixed $checked One of the values to compare.
* @param mixed $current Optional. The other value to compare if not just true.
* Default true.
* @param bool $display Optional. Whether to echo or just return the string.
* Default true.
* @return string HTML attribute or empty string.
*/
function checked( $checked, $current = true, $display = true ) {
return __checked_selected_helper( $checked, $current, $display, 'checked' );
}
/**
* Outputs the HTML selected attribute.
*
* Compares the first two arguments and if identical marks as selected.
*
* @since 1.0.0
*
* @param mixed $selected One of the values to compare.
* @param mixed $current Optional. The other value to compare if not just true.
* Default true.
* @param bool $display Optional. Whether to echo or just return the string.
* Default true.
* @return string HTML attribute or empty string.
*/
function selected( $selected, $current = true, $display = true ) {
return __checked_selected_helper( $selected, $current, $display, 'selected' );
}
/**
* Outputs the HTML disabled attribute.
*
* Compares the first two arguments and if identical marks as disabled.
*
* @since 3.0.0
*
* @param mixed $disabled One of the values to compare.
* @param mixed $current Optional. The other value to compare if not just true.
* Default true.
* @param bool $display Optional. Whether to echo or just return the string.
* Default true.
* @return string HTML attribute or empty string.
*/
function disabled( $disabled, $current = true, $display = true ) {
return __checked_selected_helper( $disabled, $current, $display, 'disabled' );
}
/**
* Outputs the HTML readonly attribute.
*
* Compares the first two arguments and if identical marks as readonly.
*
* @since 5.9.0
*
* @param mixed $readonly_value One of the values to compare.
* @param mixed $current Optional. The other value to compare if not just true.
* Default true.
* @param bool $display Optional. Whether to echo or just return the string.
* Default true.
* @return string HTML attribute or empty string.
*/
function wp_readonly( $readonly_value, $current = true, $display = true ) {
return __checked_selected_helper( $readonly_value, $current, $display, 'readonly' );
}
/*
* Include a compat `readonly()` function on PHP < 8.1. Since PHP 8.1,
* `readonly` is a reserved keyword and cannot be used as a function name.
* In order to avoid PHP parser errors, this function was extracted
* to a separate file and is only included conditionally on PHP < 8.1.
*/
if ( PHP_VERSION_ID < 80100 ) {
require_once __DIR__ . '/php-compat/readonly.php';
}
/**
* Private helper function for checked, selected, disabled and readonly.
*
* Compares the first two arguments and if identical marks as `$type`.
*
* @since 2.8.0
* @access private
*
* @param mixed $helper One of the values to compare.
* @param mixed $current The other value to compare if not just true.
* @param bool $display Whether to echo or just return the string.
* @param string $type The type of checked|selected|disabled|readonly we are doing.
* @return string HTML attribute or empty string.
*/
function __checked_selected_helper( $helper, $current, $display, $type ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
if ( (string) $helper === (string) $current ) {
$result = " $type='$type'";
} else {
$result = '';
}
if ( $display ) {
echo $result;
}
return $result;
}
/**
* Assigns a visual indicator for required form fields.
*
* @since 6.1.0
*
* @return string Indicator glyph wrapped in a `span` tag.
*/
function wp_required_field_indicator() {
/* translators: Character to identify required form fields. */
$glyph = __( '*' );
$indicator = '' . esc_html( $glyph ) . '';
/**
* Filters the markup for a visual indicator of required form fields.
*
* @since 6.1.0
*
* @param string $indicator Markup for the indicator element.
*/
return apply_filters( 'wp_required_field_indicator', $indicator );
}
/**
* Creates a message to explain required form fields.
*
* @since 6.1.0
*
* @return string Message text and glyph wrapped in a `span` tag.
*/
function wp_required_field_message() {
$message = sprintf(
'%s',
/* translators: %s: Asterisk symbol (*). */
sprintf( __( 'Required fields are marked %s' ), wp_required_field_indicator() )
);
/**
* Filters the message to explain required form fields.
*
* @since 6.1.0
*
* @param string $message Message text and glyph wrapped in a `span` tag.
*/
return apply_filters( 'wp_required_field_message', $message );
}
/**
* Default settings for heartbeat.
*
* Outputs the nonce used in the heartbeat XHR.
*
* @since 3.6.0
*
* @param array $settings
* @return array Heartbeat settings.
*/
function wp_heartbeat_settings( $settings ) {
if ( ! is_admin() ) {
$settings['ajaxurl'] = admin_url( 'admin-ajax.php', 'relative' );
}
if ( is_user_logged_in() ) {
$settings['nonce'] = wp_create_nonce( 'heartbeat-nonce' );
}
return $settings;
}