PluginProbe
Accessibility by AllAccessible / 1.2
Accessibility by AllAccessible v1.2
2.1.6 2.1.5 2.1.4 2.1.3 2.1.2 2.1.1 2.1.0 2.0.6 trunk 1.0 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 All 43 releases
allaccessible / allaccessible.php

allaccessible.php in Accessibility by AllAccessible 1.2, at allaccessible.php

268 lines 9.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 Plugin Name: AllAccessible
4 Plugin URI: https://www.allaccessible.org/platform/wordpress/
5 Description: AllAccessible Accessibility Plugin
6 Version: 1.2
7 Author: AllAccessible Team
8 Author URI: https://www.allaccessible.org/
9 Text Domain: allaccessible
10 */
11
12 /**
13 * Copyright (C) 2022 AllAccessible.
14 *
15 * This program is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 */
28
29 /**
30 * @package AllAccessible
31 * @version 1.2
32 * @since 1.0
33 * @author AllAccessible Team
34 * @copyright Copyright (c) 2022 AllAccessible
35 * @link https://www.allaccessible.org/
36 * @license http://www.gnu.org/licenses/gpl.html
37 */
38
39 if(!defined('ABSPATH')) {
40 die('You are not allowed to call this page directly.');
41 }
42
43 // =============================================
44 // Define Global Constants
45 // =============================================
46 if ( !defined('AACB_NAME') ) {
47 define('AACB_NAME','AllAccessible');
48 }
49 //Set Current Plugin Version
50 if ( !defined('AACB_VERSION') ) {
51 define('AACB_VERSION','1.2');
52 }
53 //Set Minimum WordPress version for compatibility
54 if( !defined('AACB_WP_MIN_VERSION') ){
55 define('AACB_WP_MIN_VERSION','5.0');
56 }
57
58 if ( !defined('AACB_TEXT') ) {
59 define('AACB_TEXT','allaccessible');
60 }
61
62 if ( !defined('AACB_DIR') ) {
63 define('AACB_DIR', dirname( plugin_basename( __FILE__ ) ) );
64 }
65
66 // Set constant URI to the plugin URL.
67 if ( !defined('AACB_URL') ) {
68 define('AACB_URL', plugin_dir_url( __FILE__ ) );
69 }
70
71 // Set constant path to the plugin directory.
72 if ( !defined('AACB_PATH') ) {
73 define('AACB_PATH', plugin_dir_path( __FILE__ ) );
74 }
75
76 // Set the constant path to the plugin's javascript directory.
77 if( !defined('AACB_JS') ) {
78 define('AACB_JS', AACB_URL . trailingslashit('assets') );
79 }
80
81 // Set the constant path to the plugin's CSS directory.
82 if( !defined('AACB_CSS') ) {
83 define('AACB_CSS', AACB_URL . trailingslashit('assets') );
84 }
85
86 // Set the constant path to the plugin's images directory.
87 if( !defined('AACB_IMG') ) {
88 define('AACB_IMG', AACB_URL . trailingslashit('assets') );
89 }
90
91 // Set the constant path to the plugin's includes directory.
92 if( !defined('AACB_INC') ) {
93 define('AACB_INC', AACB_PATH . trailingslashit('inc') );
94 }
95
96 // Set the constant path to the plugin's includes directory.
97 if( !defined('AACB_SUPPORT') ) {
98 define('AACB_SUPPORT','https://support.allaccessible.org/');
99 }
100
101 /**
102 * Load AllAccessible options
103 */
104 function AllAccessible_getSiteOptions() {
105 $apiUrl ='https://app.allaccessible.org/api/get-site-options/';
106 $apiResponse = wp_remote_post( $apiUrl,
107 [
108 'method' =>'POST',
109 'sslverify'=> false,
110 'headers' => [
111 'content-type'=>'application/json',
112 ],
113 'body' => json_encode(array('siteId'=> get_option('aacb_siteID')))
114 ]
115 );
116
117 return json_decode( wp_remote_retrieve_body( $apiResponse ) );
118
119 }
120
121 /**
122 * Load AllAccessible Settings Page
123 */
124 function AllAccessible_settings() {
125
126 //TODO - improve
127 $GLOBALS['aacb_accountID'] = get_option('aacb_accountID');
128
129 if(!get_option('aacb_siteID') && get_option('aacb_accountID')){
130 $apiUrl ='https://app.allaccessible.org/api/get-site-id/';
131 $apiResponse = wp_remote_post( $apiUrl,
132 [
133 'method' =>'POST',
134 'sslverify'=> false,
135 'headers' => [
136 'content-type'=>'application/json',
137 ],
138 'body' => json_encode(array('pageUrl'=> get_bloginfo('wpurl'),'accountID'=> get_option('aacb_accountID')))
139 ]
140 );
141 $apiBody = json_decode( wp_remote_retrieve_body( $apiResponse ) );
142
143 update_option('aacb_siteID', $apiBody );
144 }
145
146 $GLOBALS['aacb_accountID'] = get_option('aacb_siteID');
147
148 if(get_option('aacb_siteID')){
149 $GLOBALS['aacb_siteOptions'] = AllAccessible_getSiteOptions();
150 }
151
152 include AACB_INC .'AllAccessibleSettings.php';
153 }
154
155 //=========================
156 // Add Script to Header
157 //=========================
158
159 if(get_option('aacb_accountID')){
160 function AllAccessible_loadWidget() { ?>
161 <script data-accessible-account-id="<?php echo esc_attr(get_option('aacb_accountID')); ?>" id="allAccessibleWidget" src="https://app.allaccessible.org/api/<?php echo esc_attr(get_option('aacb_accountID')); ?>.js" defer></script>
162 <?php }
163 add_action('wp_head','AllAccessible_loadWidget');
164 }
165
166
167 register_activation_hook( __FILE__ ,'AllAccessible_Activation');
168 register_deactivation_hook( __FILE__ ,'AllAccessible_Deactivation');
169
170
171 // =============================================
172 // Load JS and CSS
173 // =============================================
174
175 /**
176 * Add admin scripts
177 */
178 function AllAccessible_LoadScript($hook){
179
180 if ('toplevel_page_allaccessible'!= $hook ) {
181 wp_enqueue_style('allaccessible-style', AACB_CSS .'allaccessible-style.css',array(),AACB_VERSION);
182 return;
183 } else {
184 wp_enqueue_style('allaccessible-spectrum-style', 'https://app.allaccessible.org/assets/plugins/custom/spectrum-2.0.8/dist/spectrum.min.css',array(),AACB_VERSION);
185 wp_enqueue_script('allaccessible-spectrum', 'https://app.allaccessible.org/assets/plugins/custom/spectrum-2.0.8/dist/spectrum.js',array(),AACB_VERSION);
186 wp_enqueue_style('allaccessible-select2', 'https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css',array(),AACB_VERSION);
187 wp_enqueue_script('allaccessible-select2-script', 'https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js',array(),AACB_VERSION);
188 wp_enqueue_style('allaccessible-admin-style', AACB_CSS .'allaccessible-style.css',array(),AACB_VERSION);
189 wp_enqueue_script('allaccessible-custom', AACB_JS .'allaccessible-custom.js',array(),AACB_VERSION);
190
191 }
192 }
193 add_action('admin_enqueue_scripts','AllAccessible_LoadScript');
194
195
196 // ===================================================
197 // Setup Core AllAccessible Admin Options and Settings
198 // ===================================================
199
200 /**
201 * Admin dashboard menu bar
202 */
203 add_action('admin_menu','AllAccessible_integration');
204
205 function AllAccessible_integration() {
206 add_menu_page(
207 'AllAccessible',
208 'AllAccessible',
209 'manage_options',
210 'allaccessible',
211 'allaccessible_settings',
212 'data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgMzE3LjkgMzE3Ljg5Ij48ZGVmcz48bGluZWFyR3JhZGllbnQgaWQ9ImxpbmVhci1ncmFkaWVudCIgeDE9IjE4My4yOSIgeTE9IjIxOC4yMiIgeDI9IjE4My4yOSIgeTI9IjQxLjI0IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+PHN0b3Agb2Zmc2V0PSIwIiBzdG9wLWNvbG9yPSIjMGY4Y2ZhIi8+PHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjNTRiOGZmIi8+PC9saW5lYXJHcmFkaWVudD48bGluZWFyR3JhZGllbnQgaWQ9ImxpbmVhci1ncmFkaWVudC0yIiB4M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1Ny44OGw3LjE3LTcuMTZhMjkuMzMsMjkuMzMsMCwwLDEsMTcuMTktOC42N0ExNTguNDEsMTU4LjQxLDAsMCwwLDE1OSwwWiIgc3R5bGU9ImZpbGwtcnVsZTpldmVub2RkO2ZpbGw6dXJsKCNsaW5lYXItZ3JhZGllbnQtMikiLz48L3N2Zz4=',
213 25
214 );
215 }
216
217 /**
218 * AllAccessible Initial Activation
219 */
220 function AllAccessible_activation() {
221 global $wpdb;
222 $options = get_option('aacb_options');
223
224 if ( ( $options['aacb_installed'] != 1 ) || ( ! is_array( $options ) ) ) {
225 $opt = array(
226 'aacb_installed' => 1,
227 );
228 update_option('aacb_options', $opt );
229 }
230
231 }
232
233 /**
234 * AllAccessible Setting Saver
235 */
236 function AllAccessible_save_settings() {
237
238 $opt_name = isset($_POST['opt_name']) ? sanitize_text_field($_POST['opt_name']) : null;
239 $opt_value = isset($_POST['opt_value']) ? sanitize_text_field($_POST['opt_value']) : null;
240 $update = update_option($opt_name, $opt_value);
241
242 }
243 add_action('wp_ajax_AllAccessible_save_settings','AllAccessible_save_settings');
244
245 /**
246 * AllAccessible Deactivation
247 */
248 function AllAccessible_deactivation() {
249
250 //Nothing Yet
251
252 }
253
254 /**
255 * Logs a debug statement to /wp-content/debug.log
256 *
257 * @param string
258 */
259 function AllAccessible_log_debug( $message ) {
260 if ( WP_DEBUG === true ) {
261 if ( is_array( $message ) || is_object( $message ) ) {
262 error_log( print_r( $message, true ) );
263 } else {
264 error_log( esc_attr($message) );
265 }
266 }
267 }
268