Settings', ]; return array_merge($custom_link, $links); } /** * Adds plugin settings page. * * @since 1.1 * @access public * @return void */ public function add_settings_page() { add_submenu_page( 'options-general.php', 'Admin Notice', 'Admin Notice', 'manage_options', 'admin_notice', [$this, 'render_settings_page'] ); } /** * Registers settings, sections, and fields. * * @since 1.1 * @access public * @return void */ public function settings_init() { register_setting( 'agw_admin_notice_settings_group', 'agw_admin_notice_msg', [$this, 'sanitize_wysiwyg'] ); register_setting( 'agw_admin_notice_settings_group', 'agw_admin_notice_style', [$this, 'sanitize_option'] ); register_setting( 'agw_admin_notice_settings_group', 'agw_admin_notice_enable', [$this, 'sanitize_option'] ); add_settings_section( 'agw_admin_notice_settings', 'Settings', [$this, 'settings_info'], 'admin_notice' ); add_settings_field( 'agw_admin_notice_enable', 'Enable Notice', [$this, 'enable_field'], 'admin_notice', 'agw_admin_notice_settings' ); add_settings_field( 'agw_admin_notice_msg', 'Message', [$this, 'message_field'], 'admin_notice', 'agw_admin_notice_settings' ); add_settings_field( 'agw_admin_notice_style', 'Style', [$this, 'style_field'], 'admin_notice', 'agw_admin_notice_settings' ); } /** * Prints the settings page. * * @since 1.1 * @access public * @return void */ public function render_settings_page() { $this->message = get_option('agw_admin_notice_msg'); $this->style = get_option('agw_admin_notice_style'); $this->enable = get_option('agw_admin_notice_enable'); ?>

Admin Notice

enable)) { $enable = esc_attr($this->enable); } else { $enable = ''; } $checked = ($enable === '1') ? 'checked="checked"' : ''; printf( '
', $checked, __('Enable', 'admin-notice') ); } /** * Prints the Message setting field. * * @since 1.1 * @access public * @return void */ public function message_field() { if (isset($this->message)) { $msg = wp_kses_post($this->message); } else { $msg = ''; } wp_editor($msg, 'agw_admin_notice_msg', [ 'textarea_name' => 'agw_admin_notice_msg', 'media_buttons' => false, 'textarea_rows' => 6, 'quicktags' => true, 'teeny' => true, ]); } /** * Prints the Style setting field. * * @since 1.1 * @access public * @return void */ public function style_field() { if (isset($this->style)) { $style = esc_attr($this->style); } else { $style = ''; } $values = ['error', 'info', 'success', 'warning']; $options = ''; foreach ($values as $value) { $selected = ($value === $style) ? 'selected="selected"' : ''; $options .= sprintf( '', esc_attr($value), $selected, esc_html(ucfirst($value)) ); } printf( '', $options ); } /** * Sanitizes radio and select fields. * * @since 1.1 * @access public * @param string $input The value to sanitize. * @return string The sanitized value. */ public function sanitize_option($input) { $new_input = ''; if ($input !== null) { $new_input = sanitize_text_field($input); } return $new_input; } /** * Sanitizes WYSIWYG fields. * * @since 1.1 * @access public * @param string $input The value to sanitize. * @return string The sanitized value. */ public function sanitize_wysiwyg($input = null) { $new_input = ''; if ($input !== null) { $new_input = wp_kses_post($input); } return $new_input; } /** * Prints the admin notice. * * @since 1.1 * @access public * @return void */ function add_admin_notice() { $msg = get_option('agw_admin_notice_msg'); $enabled = get_option('agw_admin_notice_enable'); $style = get_option('agw_admin_notice_style'); $class = "agw-admin-notice notice notice-{$style}"; $enabled = apply_filters('admin_notice_enable', $enabled); if ($msg !== '' && boolval($enabled) === true) { printf( '

%s

', esc_attr($class), wp_kses_post(wpautop($msg)) ); } } /** * Prints required CSS. * * @since 1.1 * @access public * @return void */ function print_css() { echo "\n"; } } new AGW_Admin_Notice();