'', 'dismissible' => false, 'id' => '', 'additional_classes' => array(), 'attributes' => array(), 'paragraph_wrap' => true, ); $args = wp_parse_args( $args, $defaults ); $args = apply_filters( 'wp_admin_notice_args', $args, $message ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- replicates WordPress core's own wp_admin_notice_args filter for compatibility with code hooking the real core filter. $id = ''; $classes = 'notice'; $attributes = ''; if ( is_string( $args['id'] ) ) { $trimmed_id = trim( $args['id'] ); if ( '' !== $trimmed_id ) { $id = 'id="' . $trimmed_id . '" '; } } if ( is_string( $args['type'] ) ) { $type = trim( $args['type'] ); if ( '' !== $type ) { $classes .= ' notice-' . $type; } } if ( true === $args['dismissible'] ) { $classes .= ' is-dismissible'; } if ( is_array( $args['additional_classes'] ) && ! empty( $args['additional_classes'] ) ) { $classes .= ' ' . implode( ' ', $args['additional_classes'] ); } if ( is_array( $args['attributes'] ) && ! empty( $args['attributes'] ) ) { foreach ( $args['attributes'] as $attr => $val ) { if ( is_bool( $val ) ) { $attributes .= $val ? ' ' . $attr : ''; } elseif ( is_int( $attr ) ) { $attributes .= ' ' . esc_attr( trim( $val ) ); } elseif ( $val ) { $attributes .= ' ' . $attr . '="' . esc_attr( trim( $val ) ) . '"'; } } } if ( false !== $args['paragraph_wrap'] ) { $message = "

$message

"; } $markup = sprintf( '
%4$s
', $id, $classes, $attributes, $message ); return apply_filters( 'wp_admin_notice_markup', $markup, $message, $args ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- replicates WordPress core's own wp_admin_notice_markup filter for compatibility with code hooking the real core filter. } } if ( ! function_exists( 'ao_admin_notice' ) ) { /** * Outputs an admin notice. Uses WP 6.4's wp_admin_notice() if available, * otherwise falls back to a backport of it. * * @param string $message The notice message (HTML allowed). * @param array $args Optional arguments: type, dismissible, id, additional_classes, attributes, paragraph_wrap. * @return void */ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- ao_ is this plugin's established short-form prefix. function ao_admin_notice( $message, $args = array() ) { if ( function_exists( 'wp_admin_notice' ) ) { // phpcs:ignore PluginCheck.CodeAnalysis.Compatibility.wp_function_not_compatible_with_requires_wp -- guarded by function_exists(); only reached on WP 6.4+ where this function exists. wp_admin_notice( $message, $args ); return; } do_action( 'wp_admin_notice', $message, $args ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- replicates WordPress core's own wp_admin_notice action for compatibility with code hooking the real core action. echo wp_kses_post( ao_get_admin_notice( $message, $args ) ); } }