* @return void */ public function __construct() { // Clean up a bit the top of the admin pages when notices exist add_action( 'admin_enqueue_scripts', array( $this, 'clean_administration_notices_classic' ) ); add_action( 'enqueue_block_assets', array( $this, 'clean_administration_notices_gutenberg' ) ); // Deal with the missing media states notices add_action( 'all_admin_notices', array( $this, 'display_missing_channel_notice' ) ); add_action( 'all_admin_notices', array( $this, 'display_missing_media_notice' ) ); } /** * Cleans up the administration notices by adding custom CSS to the page. * @author Affilizz * @since 1.14.0 * @return void */ public function clean_administration_notices_classic() { if ( ! function_exists( 'get_current_screen' ) ) { return; } if ( ! empty( get_current_screen() ) && get_current_screen()->is_block_editor() ) { return; } wp_add_inline_style( 'affilizz-admin', ':not(.notice) + .notice { margin-top: 20px; }' ); } public function clean_administration_notices_gutenberg() { if ( ! is_admin() ) { return; } if ( ! function_exists( 'get_current_screen' ) ) { return; } if ( empty( get_current_screen() ) || ! get_current_screen()->is_block_editor() ) { return; } wp_add_inline_style( 'affilizz-admin', ':not(.notice) + .notice { margin-top: 20px; }' ); } /** * Wraps the given content in a notice container. * @author Romain Carlier * @since 1.14.0 * @param string $content The content to wrap. * @return string The wrapped content. */ public function wrap_single_line_notice( $notice_class = '', $content = '' ) { return wp_kses( '

' . $content . '

' . PHP_EOL, \Affilizz\Core::get_extended_allowed_tags() ); } /** * Displays an error if there is a missing information. * @author Affilizz * @return void */ public function display_missing_channel_notice() { $missing_channel = get_transient( 'affilizz_missing_channel' ); if ( false !== $missing_channel ) { echo wp_kses( $this->wrap_single_line_notice( 'warning', wp_sprintf( /* translators: 1 and 2: strong tags, 3 and 4: wizard link tags. */ __( '%1$sWarning%2$s : Your Affilizz %1$schannel%2$s seems to be inexistant or wrongly defined. Please %3$sre-execute our wizard%4$s to redefine these values.', 'affilizz' ), '', '', '', '' ) ), \Affilizz\Core::get_extended_allowed_tags() ); } } /** * Displays an error if there is a missing information. * @author Affilizz * @return void */ public function display_missing_media_notice() { $missing_media = get_transient( 'affilizz_missing_media' ); if ( false !== $missing_media ) { echo wp_kses( $this->wrap_single_line_notice( 'warning', wp_sprintf( /* translators: 1 and 2: strong tags, 3 and 4: wizard link tags. */ __( '%1$sWarning%2$s : Your Affilizz %1$smedia%2$s seems to be inexistant or wrongly defined. Please %3$sre-execute our wizard%4$s to redefine these values.', 'affilizz' ), '', '', '', '' ) ), \Affilizz\Core::get_extended_allowed_tags() ); } } }