. */ /** * @package AllAccessible * @version 1.3.7 * @since 1.0 * @author AllAccessible Team * @copyright Copyright (c) 2024 AllAccessible * @link https://www.allaccessible.org/ * @license http://www.gnu.org/licenses/gpl.html */ if(!defined('ABSPATH')) { die('You are not allowed to call this page directly.'); } // Load Constants require_once plugin_dir_path(__FILE__) . 'inc/constants.php'; // Load Version Manager require_once plugin_dir_path(__FILE__) . 'inc/VersionManager.php'; function aacb_load_textdomain() { load_plugin_textdomain( 'allaccessible', false, basename( dirname( __FILE__ ) ) . '/languages/' ); } // Load text domain for translations add_action( 'init', 'aacb_load_textdomain' ); /** * Load AllAccessible options */ function AllAccessible_getSiteOptions() { $apiUrl ='https://app.allaccessible.org/api/get-site-options/'; $apiResponse = wp_remote_post( $apiUrl, [ 'method' =>'POST', 'sslverify'=> false, 'headers' => [ 'content-type'=>'application/json', ], 'body' => json_encode(array('siteId'=> get_option('aacb_siteID'))) ] ); return json_decode( wp_remote_retrieve_body( $apiResponse ) ); } /** * Load AllAccessible Settings Page */ function AllAccessible_settings() { // Removes all admin notices for this page remove_all_actions( 'admin_notices' ); //TODO - improve $GLOBALS['aacb_accountID'] = get_option('aacb_accountID'); if(!get_option('aacb_siteID') && get_option('aacb_accountID')){ $apiUrl ='https://app.allaccessible.org/api/get-site-id/'; $apiResponse = wp_remote_post( $apiUrl, [ 'method' =>'POST', 'sslverify'=> false, 'headers' => [ 'content-type'=>'application/json', ], 'body' => json_encode(array('pageUrl'=> get_bloginfo('wpurl'),'accountID'=> get_option('aacb_accountID'))) ] ); $apiBody = json_decode( wp_remote_retrieve_body( $apiResponse ) ); update_option('aacb_siteID', $apiBody ); } $GLOBALS['aacb_accountID'] = get_option('aacb_siteID'); if(get_option('aacb_siteID')){ $GLOBALS['aacb_siteOptions'] = AllAccessible_getSiteOptions(); } include AACB_INC .'AllAccessibleSettings.php'; } //========================= // Add Script to Header //========================= function AllAccessible_loadWidget() { if (!is_admin() && empty($_GET['et_fb'])) { $account_id = get_option('aacb_accountID') ? esc_attr(get_option('aacb_accountID')) : 'wp_vFtGhKjLm'; // Load local file for default account ID, remote file otherwise $script_src = ($account_id === 'wp_vFtGhKjLm') ? AACB_JS . 'widget.js' : "https://app.allaccessible.org/api/{$account_id}.js"; $aacbPreview = false; if(isset($_GET['aacb_preview']) && $_GET['aacb_preview']){ $aacbPreview = true; } ?> admin_url('admin-ajax.php'), 'nonce' => $nonce ); wp_localize_script('allaccessible-custom', 'ajax_object', $ajax_data); wp_enqueue_script('allaccessible-custom'); } add_action('admin_enqueue_scripts','AllAccessible_LoadScript'); function aacb_dismiss_notice() { update_option('aacb_hide_premium_notice', true); echo 'success'; wp_die(); } add_action('wp_ajax_aacb_dismiss_notice', 'aacb_dismiss_notice'); /** * AllAccessible Setting Saver * Securely saves plugin settings with proper authorization and validation * * @since 1.3.5 */ function AllAccessible_save_settings() { // Verify user has admin capabilities if (!current_user_can('install_plugins')) { wp_send_json_error('Unauthorized access'); return; } // Verify nonce $nonce = isset($_POST['nonce']) ? sanitize_text_field($_POST['nonce']) : ''; if (empty($nonce) || !wp_verify_nonce($nonce, 'allaccessible_save_settings')) { wp_send_json_error('Invalid security token'); return; } // Get and sanitize input $opt_name = isset($_POST['opt_name']) ? sanitize_text_field($_POST['opt_name']) : ''; $opt_value = isset($_POST['opt_value']) ? sanitize_text_field($_POST['opt_value']) : ''; // List of allowed options $allowed_options = array( 'aacb_accountID', 'aacb_siteID', 'aacb_options', 'aacb_installed' ); // Validate option name if (!in_array($opt_name, $allowed_options)) { wp_send_json_error('Invalid option name'); return; } // Update option $result = update_option($opt_name, $opt_value); if ($result) { wp_send_json_success(array( 'message' => 'Option updated successfully', 'option' => $opt_name )); } else { wp_send_json_error(array( 'message' => 'Failed to update option', 'option' => $opt_name )); } } add_action('wp_ajax_AllAccessible_save_settings', 'AllAccessible_save_settings'); // =================================================== // Setup Core AllAccessible Admin Options and Settings // =================================================== /** * Admin dashboard menu bar */ add_action('admin_menu','AllAccessible_integration'); function AllAccessible_integration() { add_men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LjY3LDY3LjA2LDI3NC41NSw0MCwyNTYuNjIsNTcuODhaIiBzdHlsZT0iZmlsbC1ydWxlOmV2ZW5vZGQ7ZmlsbDp1cmwoI2xpbmVhci1ncmFkaWVudCkiLz48cGF0aCBkPSJNMTU5LDYwLjMxYTI3Ljg2LDI3Ljg2LDAsMSwxLTI3Ljg2LDI3Ljg1QTI3Ljg1LDI3Ljg1LDAsMCwxLDE1OSw2MC4zMVpNMTU5LDBhMTU4Ljg4LDE1OC44OCwwLDEsMCwxMzguOSw4MS42MiwzMC40OCwzMC40OCwwLDAsMS03LDEwLjU0TDI3OC4yNiwxMDQuOGExMzEuMTEsMTMxLjExLDAsMCwxLTI1Ljc1LDE0NS44MmwtNDcuMzUtNDcuMzVjLTE3LjkzLTE3LjkzLTQ1LDkuMTgtMjcuMTEsMjcuMTFMMjIxLjY2LDI3NEExMzEuMjEsMTMxLjIxLDAsMCwxLDk2LDI3My44M2w0My42LTQzLjZjMTcuOTQtMTcuOTQtOS4xOS00NS0yNy4xMS0yNy4xMUw2NS4xNiwyNTAuNEExMzEsMTMxLDAsMCwxLDI0Mi4yOSw1Ny44OGw3LjE3LTcuMTZhMjkuMzMsMjkuMzMsMCwwLDEsMTcuMTktOC42N0ExNTguNDEsMTU4LjQxLDAsMCwwLDE1OSwwWiIgc3R5bGU9ImZpbGwtcnVsZTpldmVub2RkO2ZpbGw6dXJsKCNsaW5lYXItZ3JhZGllbnQtMikiLz48L3N2Zz4=', 25 ); } /** * AllAccessible Initial Activation */ function AllAccessible_activation() { global $wpdb; $options = get_option('aacb_options'); if ( ( $options['aacb_installed'] != 1 ) || ( ! is_array( $options ) ) ) { $opt = array( 'aacb_installed' => 1, ); update_option('aacb_options', $opt ); } } /** * AllAccessible Admin Notices */ function aacb_activated_notice() { $options = get_option('aacb_options'); $hide_notice = get_option('aacb_hide_premium_notice'); if ($options['aacb_installed'] && !get_option('aacb_accountID') && !$hide_notice) { $settings_url = admin_url('options-general.php?page=allaccessible'); ?>
AACB_TEXT, 'version' => AACB_VERSION, 'url' => get_bloginfo('wpurl') ); return $plugins; }); /** * Logs a debug statement to /wp-content/debug.log * * @param string */ function AllAccessible_log_debug( $message ) { if ( WP_DEBUG === true ) { if ( is_array( $message ) || is_object( $message ) ) { error_log( print_r( $message, true ) ); } else { error_log( esc_attr($message) ); } } } /** * Hide all the unrelated notices from plugin page. * * @since 1.3 * @return void */ function hide_admin_notices() { // Bail if we're not on a AllAccessible screen. if ( empty( $_REQUEST['page'] ) || ! preg_match( '/allaccessible/', esc_html( wp_unslash( $_REQUEST['page'] ) ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized return; } global $wp_filter; $notices_type = array( 'user_admin_notices', 'admin_notices', 'all_admin_notices', ); foreach ( $notices_type as $type ) { if ( empty( $wp_filter[ $type ]->callbacks ) || ! is_array( $wp_filter[ $type ]->callbacks ) ) { continue; } foreach ( $wp_filter[ $type ]->callbacks as $priority => $hooks ) { foreach ( $hooks as $name => $arr ) { if ( is_object( $arr['function'] ) && $arr['function'] instanceof \Closure ) { unset( $wp_filter[ $type ]->callbacks[ $priority ][ $name ] ); continue; } $class = ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) ? strtolower( get_class( $arr['function'][0] ) ) : ''; if ( ! empty( $class ) && preg_match( '/^(?:aacb)/', $class ) ) { continue; } if ( ! empty( $name ) && ! preg_match( '/^(?:aacb)/', $name ) ) { unset( $wp_filter[ $type ]->callbacks[ $priority ][ $name ] ); } } } } } // Hide the unrelated admin notices. add_action( 'admin_print_scripts', 'hide_admin_notices');