Changeset 56654 for trunk/src/wp-includes/functions.php
- Timestamp:
- 09/21/2023 06:22:10 PM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r56570 r56654 8763 8763 return abs( (float) $expected - (float) $actual ) <= $precision; 8764 8764 } 8765 8766 /** 8767 * Creates and returns the markup for an admin notice. 8768 * 8769 * @since 6.4.0 8770 * 8771 * @param string $message The message. 8772 * @param array $args { 8773 * Optional. An array of arguments for the admin notice. Default empty array. 8774 * 8775 * @type string $type Optional. The type of admin notice. 8776 * For example, 'error', 'success', 'warning', 'info'. 8777 * Default empty string. 8778 * @type bool $dismissible Optional. Whether the admin notice is dismissible. Default false. 8779 * @type string $id Optional. The value of the admin notice's ID attribute. Default empty string. 8780 * @type string[] $additional_classes Optional. A string array of class names. Default empty array. 8781 * @type string[] $attributes Optional. Additional attributes for the notice div. Default empty array. 8782 * @type bool $paragraph_wrap Optional. Whether to wrap the message in paragraph tags. Default true. 8783 * } 8784 * @return string The markup for an admin notice. 8785 */ 8786 function wp_get_admin_notice( $message, $args = array() ) { 8787 $defaults = array( 8788 'type' => '', 8789 'dismissible' => false, 8790 'id' => '', 8791 'additional_classes' => array(), 8792 'attributes' => array(), 8793 'paragraph_wrap' => true, 8794 ); 8795 8796 $args = wp_parse_args( $args, $defaults ); 8797 8798 /** 8799 * Filters the arguments for an admin notice. 8800 * 8801 * @since 6.4.0 8802 * 8803 * @param array $args The arguments for the admin notice. 8804 * @param string $message The message for the admin notice. 8805 */ 8806 $args = apply_filters( 'wp_admin_notice_args', $args, $message ); 8807 $id = ''; 8808 $classes = 'notice'; 8809 $attributes = ''; 8810 8811 if ( is_string( $args['id'] ) ) { 8812 $trimmed_id = trim( $args['id'] ); 8813 8814 if ( '' !== $trimmed_id ) { 8815 $id = 'id="' . $trimmed_id . '" '; 8816 } 8817 } 8818 8819 if ( is_string( $args['type'] ) ) { 8820 $type = trim( $args['type'] ); 8821 8822 if ( str_contains( $type, ' ' ) ) { 8823 _doing_it_wrong( 8824 __FUNCTION__, 8825 sprintf( 8826 /* translators: %s: The "type" key. */ 8827 __( 'The %s key must be a string without spaces.' ), 8828 '<code>type</code>' 8829 ), 8830 '6.4.0' 8831 ); 8832 } 8833 8834 if ( '' !== $type ) { 8835 $classes .= ' notice-' . $type; 8836 } 8837 } 8838 8839 if ( true === $args['dismissible'] ) { 8840 $classes .= ' is-dismissible'; 8841 } 8842 8843 if ( is_array( $args['additional_classes'] ) && ! empty( $args['additional_classes'] ) ) { 8844 $classes .= ' ' . implode( ' ', $args['additional_classes'] ); 8845 } 8846 8847 if ( is_array( $args['attributes'] ) && ! empty( $args['attributes'] ) ) { 8848 $attributes = ''; 8849 foreach ( $args['attributes'] as $attr => $val ) { 8850 if ( is_bool( $val ) ) { 8851 $attributes .= $val ? ' ' . $attr : ''; 8852 } elseif ( is_int( $attr ) ) { 8853 $attributes .= ' ' . esc_attr( trim( $val ) ); 8854 } elseif ( $val ) { 8855 $attributes .= ' ' . $attr . '="' . esc_attr( trim( $val ) ) . '"'; 8856 } 8857 } 8858 } 8859 8860 if ( false !== $args['paragraph_wrap'] ) { 8861 $message = "<p>$message</p>"; 8862 } 8863 8864 $markup = sprintf( '<div %1$sclass="%2$s"%3$s>%4$s</div>', $id, $classes, $attributes, $message ); 8865 8866 /** 8867 * Filters the markup for an admin notice. 8868 * 8869 * @since 6.4.0 8870 * 8871 * @param string $markup The HTML markup for the admin notice. 8872 * @param string $message The message for the admin notice. 8873 * @param array $args The arguments for the admin notice. 8874 */ 8875 return apply_filters( 'wp_admin_notice_markup', $markup, $message, $args ); 8876 } 8877 8878 /** 8879 * Outputs an admin notice. 8880 * 8881 * @since 6.4.0 8882 * 8883 * @param string $message The message to output. 8884 * @param array $args { 8885 * Optional. An array of arguments for the admin notice. Default empty array. 8886 * 8887 * @type string $type Optional. The type of admin notice. 8888 * For example, 'error', 'success', 'warning', 'info'. 8889 * Default empty string. 8890 * @type bool $dismissible Optional. Whether the admin notice is dismissible. Default false. 8891 * @type string $id Optional. The value of the admin notice's ID attribute. Default empty string. 8892 * @type string[] $additional_classes Optional. A string array of class names. Default empty array. 8893 * @type bool $paragraph_wrap Optional. Whether to wrap the message in paragraph tags. Default true. 8894 * } 8895 */ 8896 function wp_admin_notice( $message, $args = array() ) { 8897 /** 8898 * Fires before an admin notice is output. 8899 * 8900 * @since 6.4.0 8901 * 8902 * @param string $message The message for the admin notice. 8903 * @param array $args The arguments for the admin notice. 8904 */ 8905 do_action( 'wp_admin_notice', $message, $args ); 8906 8907 echo wp_kses_post( wp_get_admin_notice( $message, $args ) ); 8908 }
Note: See TracChangeset
for help on using the changeset viewer.