wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
wp_get_admin_notice › WordPress Function
Seit6.4.0
Veraltetn/v
› wp_get_admin_notice ( $message, $args = array() )
| Parameter: (2) |
|
| Gibt zurück: |
|
| Definiert in: |
|
| Codex: |
Creates and returns the markup for an admin notice.
Ähnliche Funktionen: wp_admin_notice, site_admin_notice, wp_explain_nonce, wp_get_abilities, wp_print_admin_notice_templates
Quellcode
function wp_get_admin_notice( $message, $args = array() ) {
$defaults = array(
'type' => '',
'dismissible' => false,
'id' => '',
'additional_classes' => array(),
'attributes' => array(),
'paragraph_wrap' => true,
);
$args = wp_parse_args( $args, $defaults );
/**
* Filters the arguments for an admin notice.
*
* @since 6.4.0
*
* @param array $args The arguments for the admin notice.
* @param string $message The message for the admin notice.
*/
$args = apply_filters( 'wp_admin_notice_args', $args, $message );
$wrap_with_p = false !== $args['paragraph_wrap'];
$wrap_opener = $wrap_with_p ? '<p>' : '';
$wrap_closer = $wrap_with_p ? '</p>' : '';
$html_builder = new WP_HTML_Tag_Processor( "<div class=\"notice\">{$wrap_opener}" );
$html_builder->next_token();
if ( is_string( $args['id'] ) ) {
$trimmed_id = trim( $args['id'] );
if ( '' !== $trimmed_id ) {
$html_builder->set_attribute( 'id', $trimmed_id );
}
}
if ( is_string( $args['type'] ) ) {
$type = trim( $args['type'] );
if ( strlen( $type ) !== strcspn( $type, " \f\t\r\n" ) ) {
_doing_it_wrong(
__FUNCTION__,
sprintf(
/* translators: %s: The "type" key. */
__( 'The %s key must be a string without spaces.' ),
'<code>type</code>'
),
'6.4.0'
);
}
if ( '' !== $type ) {
$html_builder->add_class( "notice-{$type}" );
}
}
if ( true === $args['dismissible'] ) {
$html_builder->add_class( 'is-dismissible' );
}
if ( is_array( $args['additional_classes'] ) && ! empty( $args['additional_classes'] ) ) {
foreach ( $args['additional_classes'] as $class_name ) {
$html_builder->add_class( $class_name );
}
}
if ( is_array( $args['attributes'] ) && ! empty( $args['attributes'] ) ) {
foreach ( $args['attributes'] as $name => $value ) {
if ( is_int( $name ) ) {
/*
* Boolean attributes may have been appended as numeric list items,
* for example, with `$args['attributes'][] = 'disabled'`. They should
* be recorded with the value serving as their name.
*/
$html_builder->set_attribute( $value, true );
} elseif ( true === $value ) {
$html_builder->set_attribute( $name, true );
} elseif ( false !== $value ) {
$html_builder->set_attribute( $name, trim( (string) $value ) );
}
}
}
$markup = $html_builder->get_updated_html();
$markup .= $message;
$markup .= "{$wrap_closer}</div>";
/**
* Filters the markup for an admin notice.
*
* @since 6.4.0
*
* @param string $markup The HTML markup for the admin notice.
* @param string $message The message for the admin notice.
* @param array $args The arguments for the admin notice.
*/
return apply_filters( 'wp_admin_notice_markup', $markup, $message, $args );
}