*/ class Accessibility_Onetap_Admin { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * The option group name used for registering accessibility status settings. * * @since 1.0.0 * @access protected * @var string $accessibility_status_option_group Option group ID for accessibility status settings. */ protected $accessibility_status_option_group = 'options_group_onetap_accessibility_status'; /** * The list of allowed languages for accessibility status settings. * * @since 1.0.0 * @access public * @const array ALLOWED_LANGUAGES Array of allowed language codes. */ const ALLOWED_LANGUAGES = array( 'en', 'de', 'es', 'fr', 'it', 'pl', 'se', 'fi', 'pt', 'ro', 'si', 'sk', 'nl', 'dk', 'gr', 'cz', 'hu', 'lt', 'lv', 'ee', 'hr', 'ie', 'bg', 'no', 'tr', 'id', 'pt-br', 'ja', 'ko', 'zh', 'ar', 'ru', 'hi', 'uk', 'sr', ); /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; $this->version = $version; } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles() { wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/accessibility-onetap-admin.css', array(), $this->version, 'all' ); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 * * @param string $hook The current admin page hook suffix passed by WordPress. */ public function enqueue_scripts( $hook ) { if ( 'toplevel_page_accessibility-onetap-settings' === $hook || 'onetap_page_accessibility-onetap-modules' === $hook || 'admin_page_onetap-module-labels' === $hook || 'onetap_page_accessibility-onetap-accessibility-status' === $hook ) { wp_enqueue_script( $this->plugin_name, ACCESSIBILITY_ONETAP_PLUGINS_URL . 'assets/js/admin-menu.min.js', array( 'jquery' ), $this->version, true ); wp_enqueue_script( $this->plugin_name . '-sweetalert', ACCESSIBILITY_ONETAP_PLUGINS_URL . 'assets/js/sweetalert.min.js', array(), $this->version, true ); // Localize admin. wp_localize_script( $this->plugin_name, 'adminLocalize', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'ajaxNonce' => wp_create_nonce( 'onetap-ajax-verification' ), 'adminUrl' => esc_url( admin_url() ), ) ); } wp_enqueue_script( $this->plugin_name . '-admin-global', ACCESSIBILITY_ONETAP_PLUGINS_URL . 'assets/js/admin-global.min.js', array( 'jquery' ), $this->version, true ); } /** * Display admin notice. */ public function display_admin_notice() { $get_cookie_disable_admin_notices = isset( $_COOKIE['onetap_disable_admin_notices'] ) ? sanitize_key( $_COOKIE['onetap_disable_admin_notices'] ) : ''; if ( 'disable' === $get_cookie_disable_admin_notices ) { return; } ?>
true ) ); wp_die(); } /** * Allow external domain for safe redirect. * * @param string[] $hosts Array of allowed hosts. * @return string[] Modified array with external host. */ public function onetap_allow_external_redirect_host( $hosts ) { $hosts[] = 'wponetap.com'; return $hosts; } /** * Redirect users accessing a specific admin page to an external pricing URL. * * This function runs on 'admin_init' and checks whether the current admin page * matches a specific plugin slug. * * @return void */ public function onetap_redirect_admin_page_to_pricing() { global $plugin_page, $pagenow; // Check if we are in the admin and on admin.php. if ( is_admin() && 'admin.php' === $pagenow && 'accessibility-onetap-pro' === $plugin_page ) { // Redirect. wp_safe_redirect( 'https://wponetap.com/pricing/', 301 ); exit; } } /** * Add a custom "Settings" link below the plugin description metadata * (next to "Version | By | View details") in the Plugins admin screen. * * This function hooks into 'plugin_row_meta' and adds a link to the plugin's settings page * only for this specific plugin file. * * @param array $links Array of existing plugin row meta links. * @param string $file The plugin file path (relative to the plugins directory). * * @return array Modified array of plugin row meta links. */ public function add_row_meta( $links, $file ) { // Only add the settings link for this specific plugin. if ( 'accessibility-onetap/accessibility-onetap.php' === $file ) { $settings_url = admin_url( 'admin.php?page=accessibility-onetap-settings' ); $settings_link = '' . esc_html__( 'Settings', 'accessibility-onetap' ) . ''; // Append the custom settings link to the plugin meta row. $links[] = $settings_link; } return $links; } /** * Register settings related to the accessibility status section. * * This method registers multiple options using the WordPress Settings API, * including checkboxes, text inputs, select dropdowns, and rich text fields. * * @since 1.0.0 * @access public * @return void */ public function register_settings_for_accessibility_status() { // Register a boolean setting for showing the accessibility status toggle. register_setting( $this->accessibility_status_option_group, 'onetap_show_accessibility', array( 'type' => 'boolean', 'sanitize_callback' => array( $this, 'sanitize_checkbox_input' ), ) ); // Register a string setting for language selection. register_setting( $this->accessibility_status_option_group, 'onetap_select_language', array( 'type' => 'string', 'sanitize_callback' => array( $this, 'sanitize_select_language' ), ) ); // Register a string setting for the company name input. register_setting( $this->accessibility_status_option_group, 'onetap_company_name', array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', ) ); // Register a string setting for the company website URL. register_setting( $this->accessibility_status_option_group, 'onetap_company_website', array( 'type' => 'string', 'sanitize_callback' => 'esc_url_raw', ) ); // Register a string setting for the business email address. register_setting( $this->accessibility_status_option_group, 'onetap_business_email', array( 'type' => 'string', 'sanitize_callback' => 'sanitize_email', ) ); // Register a boolean setting for the confirmation checkbox. register_setting( $this->accessibility_status_option_group, 'onetap_confirmation_checkbox', array( 'type' => 'boolean', 'sanitize_callback' => array( $this, 'sanitize_checkbox_input' ), ) ); // Register a string setting for a WYSIWYG or rich text editor. register_setting( $this->accessibility_status_option_group, 'onetap_editor_generator', array( 'type' => 'string', 'sanitize_callback' => 'wp_kses_post', ) ); } /** * Sanitize checkbox input value. * * Converts any truthy value to integer 1, otherwise returns 0. * * @since 1.0.0 * @access public * * @param mixed $value The input value to sanitize. * @return int Sanitized checkbox value (1 or 0). */ public function sanitize_checkbox_input( $value ) { return ( isset( $value ) && (bool) $value ) ? 1 : 0; } /** * Sanitize the selected language input. * * Ensures the selected language is in the list of allowed values. * Defaults to 'en' if the input is not valid. * * @since 1.0.0 * @access public * * @param string $value The selected language value. * @return string Sanitized language code. */ public function sanitize_select_language( $value ) { return in_array( $value, self::ALLOWED_LANGUAGES, true ) ? $value : 'en'; } }