@@ -1001,8 +1001,8 @@ |
||
1001 | 1001 | aui_flip_color_scheme_on_scroll(); |
1002 | 1002 | |
1003 | 1003 | <?php |
1004 | - // FSE tweaks. |
|
1005 | - if(!empty($_REQUEST['postType'])){ ?> |
|
1004 | + // FSE tweaks. |
|
1005 | + if(!empty($_REQUEST['postType'])){ ?> |
|
1006 | 1006 | function aui_fse_set_data_scroll() { |
1007 | 1007 | console.log('init scroll'); |
1008 | 1008 | let Iframe = document.getElementsByClassName("edit-site-visual-editor__editor-canvas"); |
@@ -1,264 +1,264 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | if ( ! class_exists( "AyeCode_Connect_Helper" ) ) { |
7 | - /** |
|
8 | - * Allow the quick setup and connection of our AyeCode Connect plugin. |
|
9 | - * |
|
10 | - * Class AyeCode_Connect_Helper |
|
11 | - */ |
|
12 | - class AyeCode_Connect_Helper { |
|
13 | - |
|
14 | - // Hold the version number |
|
15 | - var $version = "1.0.4"; |
|
16 | - |
|
17 | - // Hold the default strings. |
|
18 | - var $strings = array(); |
|
19 | - |
|
20 | - // Hold the default pages. |
|
21 | - var $pages = array(); |
|
22 | - |
|
23 | - /** |
|
24 | - * The constructor. |
|
25 | - * |
|
26 | - * AyeCode_Connect_Helper constructor. |
|
27 | - * |
|
28 | - * @param array $strings |
|
29 | - * @param array $pages |
|
30 | - */ |
|
31 | - public function __construct( $strings = array(), $pages = array() ) { |
|
32 | - // Only fire if not localhost and the current user has the right permissions. |
|
33 | - if ( ! $this->is_localhost() && current_user_can( 'manage_options' ) ) { |
|
34 | - // set default strings |
|
35 | - $default_strings = array( |
|
36 | - 'connect_title' => __( "Thanks for choosing an AyeCode Product!", 'ayecode-connect' ), |
|
37 | - 'connect_external' => __( "Please confirm you wish to connect your site?", 'ayecode-connect' ), |
|
38 | - 'connect' => wp_sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", 'ayecode-connect' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>" ), |
|
39 | - 'connect_button' => __( "Connect Site", 'ayecode-connect' ), |
|
40 | - 'connecting_button' => __( "Connecting...", 'ayecode-connect' ), |
|
41 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.", 'ayecode-connect' ), |
|
42 | - 'error' => __( "Something went wrong, please refresh and try again.", 'ayecode-connect' ), |
|
43 | - ); |
|
44 | - $this->strings = array_merge( $default_strings, $strings ); |
|
45 | - |
|
46 | - // set default pages |
|
47 | - $default_pages = array(); |
|
48 | - $this->pages = array_merge( $default_pages, $pages ); |
|
49 | - |
|
50 | - // maybe show connect site notice |
|
51 | - add_action( 'admin_notices', array( $this, 'ayecode_connect_install_notice' ) ); |
|
52 | - |
|
53 | - // add ajax action if not already added |
|
54 | - if ( ! has_action( 'wp_ajax_ayecode_connect_helper' ) ) { |
|
55 | - add_action( 'wp_ajax_ayecode_connect_helper', array( $this, 'ayecode_connect_install' ) ); |
|
56 | - } |
|
57 | - } |
|
58 | - |
|
59 | - // add ajax action if not already added |
|
60 | - if ( ! has_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed' ) ) { |
|
61 | - add_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed', array( $this, 'ayecode_connect_helper_installed' ) ); |
|
62 | - } |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Give a way to check we can connect via a external redirect. |
|
67 | - */ |
|
68 | - public function ayecode_connect_helper_installed(){ |
|
69 | - $active = array( |
|
70 | - 'gd' => defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION,'2.0.0.79','>') ? 1 : 0, |
|
71 | - 'uwp' => defined('USERSWP_VERSION') && version_compare(USERSWP_VERSION,'1.2.1.5','>') ? 1 : 0, |
|
72 | - 'wpi' => defined('WPINV_VERSION') && version_compare(WPINV_VERSION,'1.0.14','>') ? 1 : 0, |
|
73 | - ); |
|
74 | - wp_send_json_success( $active ); |
|
75 | - wp_die(); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Get slug from path |
|
80 | - * |
|
81 | - * @param string $key |
|
82 | - * |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - private function format_plugin_slug( $key ) { |
|
86 | - $slug = explode( '/', $key ); |
|
87 | - $slug = explode( '.', end( $slug ) ); |
|
88 | - |
|
89 | - return $slug[0]; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Install and activate the AyeCode Connect Plugin |
|
94 | - */ |
|
95 | - public function ayecode_connect_install() { |
|
96 | - // bail if localhost |
|
97 | - if ( $this->is_localhost() ) { |
|
98 | - wp_send_json_error( $this->strings['error_localhost'] ); |
|
99 | - } |
|
100 | - |
|
101 | - // Explicitly clear the event. |
|
102 | - wp_clear_scheduled_hook( 'geodir_plugin_background_installer', func_get_args() ); |
|
103 | - |
|
104 | - $success = true; |
|
105 | - $plugin_slug = "ayecode-connect"; |
|
106 | - if ( ! empty( $plugin_slug ) ) { |
|
107 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
108 | - require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); |
|
109 | - require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); |
|
110 | - require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
111 | - |
|
112 | - WP_Filesystem(); |
|
113 | - |
|
114 | - $skin = new Automatic_Upgrader_Skin; |
|
115 | - $upgrader = new WP_Upgrader( $skin ); |
|
116 | - $installed_plugins = array_map( array( $this, 'format_plugin_slug' ), array_keys( get_plugins() ) ); |
|
117 | - $plugin_slug = $plugin_slug; |
|
118 | - $plugin = $plugin_slug . '/' . $plugin_slug . '.php'; |
|
119 | - $installed = false; |
|
120 | - $activate = false; |
|
121 | - |
|
122 | - // See if the plugin is installed already |
|
123 | - if ( in_array( $plugin_slug, $installed_plugins ) ) { |
|
124 | - $installed = true; |
|
125 | - $activate = ! is_plugin_active( $plugin ); |
|
126 | - } |
|
127 | - |
|
128 | - // Install this thing! |
|
129 | - if ( ! $installed ) { |
|
130 | - |
|
131 | - // Suppress feedback |
|
132 | - ob_start(); |
|
133 | - |
|
134 | - try { |
|
135 | - $plugin_information = plugins_api( 'plugin_information', array( |
|
136 | - 'slug' => $plugin_slug, |
|
137 | - 'fields' => array( |
|
138 | - 'short_description' => false, |
|
139 | - 'sections' => false, |
|
140 | - 'requires' => false, |
|
141 | - 'rating' => false, |
|
142 | - 'ratings' => false, |
|
143 | - 'downloaded' => false, |
|
144 | - 'last_updated' => false, |
|
145 | - 'added' => false, |
|
146 | - 'tags' => false, |
|
147 | - 'homepage' => false, |
|
148 | - 'donate_link' => false, |
|
149 | - 'author_profile' => false, |
|
150 | - 'author' => false, |
|
151 | - ), |
|
152 | - ) ); |
|
153 | - |
|
154 | - if ( is_wp_error( $plugin_information ) ) { |
|
155 | - throw new Exception( $plugin_information->get_error_message() ); |
|
156 | - } |
|
157 | - |
|
158 | - $package = $plugin_information->download_link; |
|
159 | - $download = $upgrader->download_package( $package ); |
|
160 | - |
|
161 | - if ( is_wp_error( $download ) ) { |
|
162 | - throw new Exception( $download->get_error_message() ); |
|
163 | - } |
|
164 | - |
|
165 | - $working_dir = $upgrader->unpack_package( $download, true ); |
|
166 | - |
|
167 | - if ( is_wp_error( $working_dir ) ) { |
|
168 | - throw new Exception( $working_dir->get_error_message() ); |
|
169 | - } |
|
170 | - |
|
171 | - $result = $upgrader->install_package( array( |
|
172 | - 'source' => $working_dir, |
|
173 | - 'destination' => WP_PLUGIN_DIR, |
|
174 | - 'clear_destination' => false, |
|
175 | - 'abort_if_destination_exists' => false, |
|
176 | - 'clear_working' => true, |
|
177 | - 'hook_extra' => array( |
|
178 | - 'type' => 'plugin', |
|
179 | - 'action' => 'install', |
|
180 | - ), |
|
181 | - ) ); |
|
182 | - |
|
183 | - if ( is_wp_error( $result ) ) { |
|
184 | - throw new Exception( $result->get_error_message() ); |
|
185 | - } |
|
186 | - |
|
187 | - $activate = true; |
|
188 | - |
|
189 | - } catch ( Exception $e ) { |
|
190 | - $success = false; |
|
191 | - } |
|
192 | - |
|
193 | - // Discard feedback |
|
194 | - ob_end_clean(); |
|
195 | - } |
|
196 | - |
|
197 | - wp_clean_plugins_cache(); |
|
198 | - |
|
199 | - // Activate this thing |
|
200 | - if ( $activate ) { |
|
201 | - try { |
|
202 | - $result = activate_plugin( $plugin ); |
|
203 | - |
|
204 | - if ( is_wp_error( $result ) ) { |
|
205 | - $success = false; |
|
206 | - } else { |
|
207 | - $success = true; |
|
208 | - } |
|
209 | - } catch ( Exception $e ) { |
|
210 | - $success = false; |
|
211 | - } |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - if ( $success && function_exists( 'ayecode_connect_args' ) ) { |
|
216 | - ayecode_connect();// init |
|
217 | - $args = ayecode_connect_args(); |
|
218 | - $client = new AyeCode_Connect( $args ); |
|
219 | - $redirect_to = ! empty( $_POST['redirect_to'] ) ? esc_url_raw( $_POST['redirect_to'] ) : ''; |
|
220 | - $redirect = $client->build_connect_url( $redirect_to ); |
|
221 | - wp_send_json_success( array( 'connect_url' => $redirect ) ); |
|
222 | - } else { |
|
223 | - wp_send_json_error( $this->strings['error_localhost'] ); |
|
224 | - } |
|
225 | - wp_die(); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Check if maybe localhost. |
|
230 | - * |
|
231 | - * @return bool |
|
232 | - */ |
|
233 | - public function is_localhost() { |
|
234 | - $localhost = false; |
|
235 | - |
|
236 | - $host = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : ''; |
|
237 | - $localhost_domains = array( |
|
238 | - 'localhost', |
|
239 | - 'localhost.localdomain', |
|
240 | - '127.0.0.1', |
|
241 | - '::1' |
|
242 | - ); |
|
243 | - |
|
244 | - if ( in_array( $host, $localhost_domains ) ) { |
|
245 | - $localhost = true; |
|
246 | - } |
|
247 | - |
|
248 | - return $localhost; |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Show notice to connect site. |
|
253 | - */ |
|
254 | - public function ayecode_connect_install_notice() { |
|
255 | - if ( $this->maybe_show() ) { |
|
256 | - $connect_title_string = $this->strings['connect_title']; |
|
257 | - $connect_external_string = $this->strings['connect_external']; |
|
258 | - $connect_string = $this->strings['connect']; |
|
259 | - $connect_button_string = $this->strings['connect_button']; |
|
260 | - $connecting_button_string = $this->strings['connecting_button']; |
|
261 | - ?> |
|
7 | + /** |
|
8 | + * Allow the quick setup and connection of our AyeCode Connect plugin. |
|
9 | + * |
|
10 | + * Class AyeCode_Connect_Helper |
|
11 | + */ |
|
12 | + class AyeCode_Connect_Helper { |
|
13 | + |
|
14 | + // Hold the version number |
|
15 | + var $version = "1.0.4"; |
|
16 | + |
|
17 | + // Hold the default strings. |
|
18 | + var $strings = array(); |
|
19 | + |
|
20 | + // Hold the default pages. |
|
21 | + var $pages = array(); |
|
22 | + |
|
23 | + /** |
|
24 | + * The constructor. |
|
25 | + * |
|
26 | + * AyeCode_Connect_Helper constructor. |
|
27 | + * |
|
28 | + * @param array $strings |
|
29 | + * @param array $pages |
|
30 | + */ |
|
31 | + public function __construct( $strings = array(), $pages = array() ) { |
|
32 | + // Only fire if not localhost and the current user has the right permissions. |
|
33 | + if ( ! $this->is_localhost() && current_user_can( 'manage_options' ) ) { |
|
34 | + // set default strings |
|
35 | + $default_strings = array( |
|
36 | + 'connect_title' => __( "Thanks for choosing an AyeCode Product!", 'ayecode-connect' ), |
|
37 | + 'connect_external' => __( "Please confirm you wish to connect your site?", 'ayecode-connect' ), |
|
38 | + 'connect' => wp_sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", 'ayecode-connect' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>" ), |
|
39 | + 'connect_button' => __( "Connect Site", 'ayecode-connect' ), |
|
40 | + 'connecting_button' => __( "Connecting...", 'ayecode-connect' ), |
|
41 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.", 'ayecode-connect' ), |
|
42 | + 'error' => __( "Something went wrong, please refresh and try again.", 'ayecode-connect' ), |
|
43 | + ); |
|
44 | + $this->strings = array_merge( $default_strings, $strings ); |
|
45 | + |
|
46 | + // set default pages |
|
47 | + $default_pages = array(); |
|
48 | + $this->pages = array_merge( $default_pages, $pages ); |
|
49 | + |
|
50 | + // maybe show connect site notice |
|
51 | + add_action( 'admin_notices', array( $this, 'ayecode_connect_install_notice' ) ); |
|
52 | + |
|
53 | + // add ajax action if not already added |
|
54 | + if ( ! has_action( 'wp_ajax_ayecode_connect_helper' ) ) { |
|
55 | + add_action( 'wp_ajax_ayecode_connect_helper', array( $this, 'ayecode_connect_install' ) ); |
|
56 | + } |
|
57 | + } |
|
58 | + |
|
59 | + // add ajax action if not already added |
|
60 | + if ( ! has_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed' ) ) { |
|
61 | + add_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed', array( $this, 'ayecode_connect_helper_installed' ) ); |
|
62 | + } |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Give a way to check we can connect via a external redirect. |
|
67 | + */ |
|
68 | + public function ayecode_connect_helper_installed(){ |
|
69 | + $active = array( |
|
70 | + 'gd' => defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION,'2.0.0.79','>') ? 1 : 0, |
|
71 | + 'uwp' => defined('USERSWP_VERSION') && version_compare(USERSWP_VERSION,'1.2.1.5','>') ? 1 : 0, |
|
72 | + 'wpi' => defined('WPINV_VERSION') && version_compare(WPINV_VERSION,'1.0.14','>') ? 1 : 0, |
|
73 | + ); |
|
74 | + wp_send_json_success( $active ); |
|
75 | + wp_die(); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Get slug from path |
|
80 | + * |
|
81 | + * @param string $key |
|
82 | + * |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + private function format_plugin_slug( $key ) { |
|
86 | + $slug = explode( '/', $key ); |
|
87 | + $slug = explode( '.', end( $slug ) ); |
|
88 | + |
|
89 | + return $slug[0]; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Install and activate the AyeCode Connect Plugin |
|
94 | + */ |
|
95 | + public function ayecode_connect_install() { |
|
96 | + // bail if localhost |
|
97 | + if ( $this->is_localhost() ) { |
|
98 | + wp_send_json_error( $this->strings['error_localhost'] ); |
|
99 | + } |
|
100 | + |
|
101 | + // Explicitly clear the event. |
|
102 | + wp_clear_scheduled_hook( 'geodir_plugin_background_installer', func_get_args() ); |
|
103 | + |
|
104 | + $success = true; |
|
105 | + $plugin_slug = "ayecode-connect"; |
|
106 | + if ( ! empty( $plugin_slug ) ) { |
|
107 | + require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
108 | + require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); |
|
109 | + require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); |
|
110 | + require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
111 | + |
|
112 | + WP_Filesystem(); |
|
113 | + |
|
114 | + $skin = new Automatic_Upgrader_Skin; |
|
115 | + $upgrader = new WP_Upgrader( $skin ); |
|
116 | + $installed_plugins = array_map( array( $this, 'format_plugin_slug' ), array_keys( get_plugins() ) ); |
|
117 | + $plugin_slug = $plugin_slug; |
|
118 | + $plugin = $plugin_slug . '/' . $plugin_slug . '.php'; |
|
119 | + $installed = false; |
|
120 | + $activate = false; |
|
121 | + |
|
122 | + // See if the plugin is installed already |
|
123 | + if ( in_array( $plugin_slug, $installed_plugins ) ) { |
|
124 | + $installed = true; |
|
125 | + $activate = ! is_plugin_active( $plugin ); |
|
126 | + } |
|
127 | + |
|
128 | + // Install this thing! |
|
129 | + if ( ! $installed ) { |
|
130 | + |
|
131 | + // Suppress feedback |
|
132 | + ob_start(); |
|
133 | + |
|
134 | + try { |
|
135 | + $plugin_information = plugins_api( 'plugin_information', array( |
|
136 | + 'slug' => $plugin_slug, |
|
137 | + 'fields' => array( |
|
138 | + 'short_description' => false, |
|
139 | + 'sections' => false, |
|
140 | + 'requires' => false, |
|
141 | + 'rating' => false, |
|
142 | + 'ratings' => false, |
|
143 | + 'downloaded' => false, |
|
144 | + 'last_updated' => false, |
|
145 | + 'added' => false, |
|
146 | + 'tags' => false, |
|
147 | + 'homepage' => false, |
|
148 | + 'donate_link' => false, |
|
149 | + 'author_profile' => false, |
|
150 | + 'author' => false, |
|
151 | + ), |
|
152 | + ) ); |
|
153 | + |
|
154 | + if ( is_wp_error( $plugin_information ) ) { |
|
155 | + throw new Exception( $plugin_information->get_error_message() ); |
|
156 | + } |
|
157 | + |
|
158 | + $package = $plugin_information->download_link; |
|
159 | + $download = $upgrader->download_package( $package ); |
|
160 | + |
|
161 | + if ( is_wp_error( $download ) ) { |
|
162 | + throw new Exception( $download->get_error_message() ); |
|
163 | + } |
|
164 | + |
|
165 | + $working_dir = $upgrader->unpack_package( $download, true ); |
|
166 | + |
|
167 | + if ( is_wp_error( $working_dir ) ) { |
|
168 | + throw new Exception( $working_dir->get_error_message() ); |
|
169 | + } |
|
170 | + |
|
171 | + $result = $upgrader->install_package( array( |
|
172 | + 'source' => $working_dir, |
|
173 | + 'destination' => WP_PLUGIN_DIR, |
|
174 | + 'clear_destination' => false, |
|
175 | + 'abort_if_destination_exists' => false, |
|
176 | + 'clear_working' => true, |
|
177 | + 'hook_extra' => array( |
|
178 | + 'type' => 'plugin', |
|
179 | + 'action' => 'install', |
|
180 | + ), |
|
181 | + ) ); |
|
182 | + |
|
183 | + if ( is_wp_error( $result ) ) { |
|
184 | + throw new Exception( $result->get_error_message() ); |
|
185 | + } |
|
186 | + |
|
187 | + $activate = true; |
|
188 | + |
|
189 | + } catch ( Exception $e ) { |
|
190 | + $success = false; |
|
191 | + } |
|
192 | + |
|
193 | + // Discard feedback |
|
194 | + ob_end_clean(); |
|
195 | + } |
|
196 | + |
|
197 | + wp_clean_plugins_cache(); |
|
198 | + |
|
199 | + // Activate this thing |
|
200 | + if ( $activate ) { |
|
201 | + try { |
|
202 | + $result = activate_plugin( $plugin ); |
|
203 | + |
|
204 | + if ( is_wp_error( $result ) ) { |
|
205 | + $success = false; |
|
206 | + } else { |
|
207 | + $success = true; |
|
208 | + } |
|
209 | + } catch ( Exception $e ) { |
|
210 | + $success = false; |
|
211 | + } |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + if ( $success && function_exists( 'ayecode_connect_args' ) ) { |
|
216 | + ayecode_connect();// init |
|
217 | + $args = ayecode_connect_args(); |
|
218 | + $client = new AyeCode_Connect( $args ); |
|
219 | + $redirect_to = ! empty( $_POST['redirect_to'] ) ? esc_url_raw( $_POST['redirect_to'] ) : ''; |
|
220 | + $redirect = $client->build_connect_url( $redirect_to ); |
|
221 | + wp_send_json_success( array( 'connect_url' => $redirect ) ); |
|
222 | + } else { |
|
223 | + wp_send_json_error( $this->strings['error_localhost'] ); |
|
224 | + } |
|
225 | + wp_die(); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Check if maybe localhost. |
|
230 | + * |
|
231 | + * @return bool |
|
232 | + */ |
|
233 | + public function is_localhost() { |
|
234 | + $localhost = false; |
|
235 | + |
|
236 | + $host = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : ''; |
|
237 | + $localhost_domains = array( |
|
238 | + 'localhost', |
|
239 | + 'localhost.localdomain', |
|
240 | + '127.0.0.1', |
|
241 | + '::1' |
|
242 | + ); |
|
243 | + |
|
244 | + if ( in_array( $host, $localhost_domains ) ) { |
|
245 | + $localhost = true; |
|
246 | + } |
|
247 | + |
|
248 | + return $localhost; |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Show notice to connect site. |
|
253 | + */ |
|
254 | + public function ayecode_connect_install_notice() { |
|
255 | + if ( $this->maybe_show() ) { |
|
256 | + $connect_title_string = $this->strings['connect_title']; |
|
257 | + $connect_external_string = $this->strings['connect_external']; |
|
258 | + $connect_string = $this->strings['connect']; |
|
259 | + $connect_button_string = $this->strings['connect_button']; |
|
260 | + $connecting_button_string = $this->strings['connecting_button']; |
|
261 | + ?> |
|
262 | 262 | <div class="notice notice-info acch-notice"> |
263 | 263 | <span class="acch-float-left"> |
264 | 264 | <svg width="61px" height="61px" viewBox="0 0 61 61" version="1.1" |
@@ -305,9 +305,9 @@ discard block |
||
305 | 305 | </div> |
306 | 306 | |
307 | 307 | <?php |
308 | - // only include the popup HTML if needed. |
|
309 | - if ( ! empty( $_REQUEST['external-connect-request'] ) ) { |
|
310 | - ?> |
|
308 | + // only include the popup HTML if needed. |
|
309 | + if ( ! empty( $_REQUEST['external-connect-request'] ) ) { |
|
310 | + ?> |
|
311 | 311 | <div id="ayecode-connect-helper-external-confirm" style="display:none;"> |
312 | 312 | <div class="noticex notice-info acch-notice" style="border: none;"> |
313 | 313 | <span class="acch-float-left"> |
@@ -353,23 +353,23 @@ discard block |
||
353 | 353 | </div> |
354 | 354 | </div> |
355 | 355 | <?php |
356 | - } |
|
357 | - |
|
358 | - // add required scripts |
|
359 | - $this->script(); |
|
360 | - } |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Get the JS Script. |
|
365 | - */ |
|
366 | - public function script() { |
|
367 | - |
|
368 | - // add thickbox if external request is requested |
|
369 | - if ( ! empty( $_REQUEST['external-connect-request'] ) ) { |
|
370 | - add_thickbox(); |
|
371 | - } |
|
372 | - ?> |
|
356 | + } |
|
357 | + |
|
358 | + // add required scripts |
|
359 | + $this->script(); |
|
360 | + } |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Get the JS Script. |
|
365 | + */ |
|
366 | + public function script() { |
|
367 | + |
|
368 | + // add thickbox if external request is requested |
|
369 | + if ( ! empty( $_REQUEST['external-connect-request'] ) ) { |
|
370 | + add_thickbox(); |
|
371 | + } |
|
372 | + ?> |
|
373 | 373 | <style> |
374 | 374 | .acch-title { |
375 | 375 | margin: 0; |
@@ -435,38 +435,38 @@ discard block |
||
435 | 435 | }); |
436 | 436 | } |
437 | 437 | <?php |
438 | - // add thickbox if external request is requested |
|
439 | - if(! empty( $_REQUEST['external-connect-request'] )) { |
|
440 | - ?> |
|
438 | + // add thickbox if external request is requested |
|
439 | + if(! empty( $_REQUEST['external-connect-request'] )) { |
|
440 | + ?> |
|
441 | 441 | jQuery(function () { |
442 | 442 | setTimeout(function () { |
443 | 443 | tb_show("AyeCode Connect", "?TB_inline?width=300&height=80&inlineId=ayecode-connect-helper-external-confirm"); |
444 | 444 | }, 200); |
445 | 445 | }); |
446 | 446 | <?php |
447 | - } |
|
448 | - ?> |
|
447 | + } |
|
448 | + ?> |
|
449 | 449 | </script> |
450 | 450 | <?php |
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * Decide what pages to show on. |
|
455 | - * |
|
456 | - * @return bool |
|
457 | - */ |
|
458 | - public function maybe_show() { |
|
459 | - $show = false; |
|
460 | - |
|
461 | - // check if on a page set to show |
|
462 | - if ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $this->pages ) ) { |
|
463 | - // check if not active and connected |
|
464 | - if ( ! defined( 'AYECODE_CONNECT_VERSION' ) || ! get_option( 'ayecode_connect_blog_token' ) ) { |
|
465 | - $show = true; |
|
466 | - } |
|
467 | - } |
|
468 | - |
|
469 | - return $show; |
|
470 | - } |
|
471 | - } |
|
451 | + } |
|
452 | + |
|
453 | + /** |
|
454 | + * Decide what pages to show on. |
|
455 | + * |
|
456 | + * @return bool |
|
457 | + */ |
|
458 | + public function maybe_show() { |
|
459 | + $show = false; |
|
460 | + |
|
461 | + // check if on a page set to show |
|
462 | + if ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $this->pages ) ) { |
|
463 | + // check if not active and connected |
|
464 | + if ( ! defined( 'AYECODE_CONNECT_VERSION' ) || ! get_option( 'ayecode_connect_blog_token' ) ) { |
|
465 | + $show = true; |
|
466 | + } |
|
467 | + } |
|
468 | + |
|
469 | + return $show; |
|
470 | + } |
|
471 | + } |
|
472 | 472 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -21,406 +21,406 @@ discard block |
||
21 | 21 | */ |
22 | 22 | if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
23 | 23 | |
24 | - /** |
|
25 | - * A Class to be able to change settings for Font Awesome. |
|
26 | - * |
|
27 | - * Class WP_Font_Awesome_Settings |
|
28 | - */ |
|
29 | - class WP_Font_Awesome_Settings { |
|
30 | - |
|
31 | - /** |
|
32 | - * Class version version. |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $version = '1.1.7'; |
|
37 | - |
|
38 | - /** |
|
39 | - * Class textdomain. |
|
40 | - * |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - public $textdomain = 'font-awesome-settings'; |
|
44 | - |
|
45 | - /** |
|
46 | - * Latest version of Font Awesome at time of publish published. |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - public $latest = "6.4.2"; |
|
51 | - |
|
52 | - /** |
|
53 | - * The title. |
|
54 | - * |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - public $name = 'Font Awesome'; |
|
58 | - |
|
59 | - /** |
|
60 | - * Holds the settings values. |
|
61 | - * |
|
62 | - * @var array |
|
63 | - */ |
|
64 | - private $settings; |
|
65 | - |
|
66 | - /** |
|
67 | - * WP_Font_Awesome_Settings instance. |
|
68 | - * |
|
69 | - * @access private |
|
70 | - * @since 1.0.0 |
|
71 | - * @var WP_Font_Awesome_Settings There can be only one! |
|
72 | - */ |
|
73 | - private static $instance = null; |
|
74 | - |
|
75 | - /** |
|
76 | - * Main WP_Font_Awesome_Settings Instance. |
|
77 | - * |
|
78 | - * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
79 | - * |
|
80 | - * @since 1.0.0 |
|
81 | - * @static |
|
82 | - * @return WP_Font_Awesome_Settings - Main instance. |
|
83 | - */ |
|
84 | - public static function instance() { |
|
85 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
86 | - self::$instance = new WP_Font_Awesome_Settings; |
|
87 | - |
|
88 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
89 | - |
|
90 | - if ( is_admin() ) { |
|
91 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
92 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
93 | - add_action( 'admin_init', array( self::$instance, 'constants' ) ); |
|
94 | - add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
95 | - } |
|
96 | - |
|
97 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
98 | - } |
|
99 | - |
|
100 | - return self::$instance; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
24 | + /** |
|
25 | + * A Class to be able to change settings for Font Awesome. |
|
26 | + * |
|
27 | + * Class WP_Font_Awesome_Settings |
|
28 | + */ |
|
29 | + class WP_Font_Awesome_Settings { |
|
30 | + |
|
31 | + /** |
|
32 | + * Class version version. |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $version = '1.1.7'; |
|
37 | + |
|
38 | + /** |
|
39 | + * Class textdomain. |
|
40 | + * |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + public $textdomain = 'font-awesome-settings'; |
|
44 | + |
|
45 | + /** |
|
46 | + * Latest version of Font Awesome at time of publish published. |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + public $latest = "6.4.2"; |
|
51 | + |
|
52 | + /** |
|
53 | + * The title. |
|
54 | + * |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + public $name = 'Font Awesome'; |
|
58 | + |
|
59 | + /** |
|
60 | + * Holds the settings values. |
|
61 | + * |
|
62 | + * @var array |
|
63 | + */ |
|
64 | + private $settings; |
|
65 | + |
|
66 | + /** |
|
67 | + * WP_Font_Awesome_Settings instance. |
|
68 | + * |
|
69 | + * @access private |
|
70 | + * @since 1.0.0 |
|
71 | + * @var WP_Font_Awesome_Settings There can be only one! |
|
72 | + */ |
|
73 | + private static $instance = null; |
|
74 | + |
|
75 | + /** |
|
76 | + * Main WP_Font_Awesome_Settings Instance. |
|
77 | + * |
|
78 | + * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
79 | + * |
|
80 | + * @since 1.0.0 |
|
81 | + * @static |
|
82 | + * @return WP_Font_Awesome_Settings - Main instance. |
|
83 | + */ |
|
84 | + public static function instance() { |
|
85 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
86 | + self::$instance = new WP_Font_Awesome_Settings; |
|
87 | + |
|
88 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
89 | + |
|
90 | + if ( is_admin() ) { |
|
91 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
92 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
93 | + add_action( 'admin_init', array( self::$instance, 'constants' ) ); |
|
94 | + add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
95 | + } |
|
96 | + |
|
97 | + do_action( 'wp_font_awesome_settings_loaded' ); |
|
98 | + } |
|
99 | + |
|
100 | + return self::$instance; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | 104 | * Define any constants that may be needed by other packages. |
105 | 105 | * |
106 | - * @return void |
|
107 | - */ |
|
108 | - public function constants(){ |
|
106 | + * @return void |
|
107 | + */ |
|
108 | + public function constants(){ |
|
109 | 109 | |
110 | - // register iconpicker constant |
|
111 | - if ( ! defined( 'FAS_ICONPICKER_JS_URL' ) ) { |
|
112 | - $url = $this->get_path_url(); |
|
113 | - $version = $this->settings['version']; |
|
110 | + // register iconpicker constant |
|
111 | + if ( ! defined( 'FAS_ICONPICKER_JS_URL' ) ) { |
|
112 | + $url = $this->get_path_url(); |
|
113 | + $version = $this->settings['version']; |
|
114 | 114 | |
115 | - if( !$version || version_compare($version,'5.999','>')){ |
|
116 | - $url .= 'assets/js/fa-iconpicker-v6.min.js'; |
|
117 | - }else{ |
|
118 | - $url .= 'assets/js/fa-iconpicker-v5.min.js'; |
|
119 | - } |
|
115 | + if( !$version || version_compare($version,'5.999','>')){ |
|
116 | + $url .= 'assets/js/fa-iconpicker-v6.min.js'; |
|
117 | + }else{ |
|
118 | + $url .= 'assets/js/fa-iconpicker-v5.min.js'; |
|
119 | + } |
|
120 | 120 | |
121 | - define( 'FAS_ICONPICKER_JS_URL', $url ); |
|
121 | + define( 'FAS_ICONPICKER_JS_URL', $url ); |
|
122 | 122 | |
123 | - } |
|
123 | + } |
|
124 | 124 | |
125 | 125 | // Set a constant if pro enbaled |
126 | - if ( ! defined( 'FAS_PRO' ) && $this->settings['pro'] ) { |
|
127 | - define( 'FAS_PRO', true ); |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Get the url path to the current folder. |
|
133 | - * |
|
134 | - * @return string |
|
135 | - */ |
|
136 | - public function get_path_url() { |
|
137 | - $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) ); |
|
138 | - $content_url = untrailingslashit( WP_CONTENT_URL ); |
|
139 | - |
|
140 | - // Replace http:// to https://. |
|
141 | - if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) { |
|
142 | - $content_url = str_replace( 'http://', 'https://', $content_url ); |
|
143 | - } |
|
144 | - |
|
145 | - // Check if we are inside a plugin |
|
146 | - $file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
147 | - $url = str_replace( $content_dir, $content_url, $file_dir ); |
|
148 | - |
|
149 | - return trailingslashit( $url ); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Initiate the settings and add the required action hooks. |
|
154 | - * |
|
155 | - * @since 1.0.8 Settings name wrong - FIXED |
|
156 | - */ |
|
157 | - public function init() { |
|
158 | - // Download fontawesome locally. |
|
159 | - add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 ); |
|
160 | - add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
161 | - |
|
162 | - $this->settings = $this->get_settings(); |
|
163 | - |
|
164 | - // Check if the official plugin is active and use that instead if so. |
|
165 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
166 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
167 | - add_action( 'admin_head', array( $this, 'add_generator' ), 99 ); |
|
168 | - } |
|
169 | - |
|
170 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
171 | - add_action( 'wp_head', array( $this, 'add_generator' ), 99 ); |
|
172 | - } |
|
173 | - |
|
174 | - if ( $this->settings['type'] == 'CSS' ) { |
|
175 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
176 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
177 | - //add_action( 'wp_footer', array( $this, 'enqueue_style' ), 5000 ); // not sure why this was added, seems to break frontend |
|
178 | - } |
|
179 | - |
|
180 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
181 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
182 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 ); |
|
183 | - } |
|
184 | - } else { |
|
185 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
186 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
187 | - } |
|
188 | - |
|
189 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
190 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
191 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 ); |
|
192 | - } |
|
193 | - } |
|
194 | - |
|
195 | - // remove font awesome if set to do so |
|
196 | - if ( $this->settings['dequeue'] == '1' ) { |
|
197 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Add FA to the FSE. |
|
205 | - * |
|
206 | - * @param $editor_settings |
|
207 | - * @param $block_editor_context |
|
208 | - * |
|
209 | - * @return array |
|
210 | - */ |
|
211 | - public function enqueue_editor_styles( $editor_settings, $block_editor_context ){ |
|
212 | - |
|
213 | - if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) { |
|
214 | - $url = $this->get_url(); |
|
215 | - $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css' href='$url' media='all' />"; |
|
216 | - } |
|
217 | - |
|
218 | - return $editor_settings; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Add FA to the FSE. |
|
223 | - * |
|
224 | - * @param $editor_settings |
|
225 | - * @param $block_editor_context |
|
226 | - * |
|
227 | - * @return array |
|
228 | - */ |
|
229 | - public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){ |
|
230 | - |
|
231 | - $url = $this->get_url(); |
|
232 | - $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>"; |
|
233 | - |
|
234 | - return $editor_settings; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Adds the Font Awesome styles. |
|
239 | - */ |
|
240 | - public function enqueue_style() { |
|
241 | - // build url |
|
242 | - $url = $this->get_url(); |
|
243 | - $version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null; |
|
244 | - |
|
245 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
246 | - wp_register_style( 'font-awesome', $url, array(), $version ); |
|
247 | - wp_enqueue_style( 'font-awesome' ); |
|
248 | - |
|
249 | - // RTL language support CSS. |
|
250 | - if ( is_rtl() ) { |
|
251 | - wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
252 | - } |
|
253 | - |
|
254 | - if ( $this->settings['shims'] ) { |
|
255 | - $url = $this->get_url( true ); |
|
256 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
257 | - wp_register_style( 'font-awesome-shims', $url, array(), $version ); |
|
258 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
259 | - } |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Adds the Font Awesome JS. |
|
264 | - */ |
|
265 | - public function enqueue_scripts() { |
|
266 | - // build url |
|
267 | - $url = $this->get_url(); |
|
268 | - |
|
269 | - $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
270 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
271 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
272 | - wp_enqueue_script( 'font-awesome' ); |
|
273 | - |
|
274 | - if ( $this->settings['shims'] ) { |
|
275 | - $url = $this->get_url( true ); |
|
276 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
277 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
278 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
279 | - } |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Get the url of the Font Awesome files. |
|
284 | - * |
|
285 | - * @param bool $shims If this is a shim file or not. |
|
286 | - * @param bool $local Load locally if allowed. |
|
287 | - * |
|
288 | - * @return string The url to the file. |
|
289 | - */ |
|
290 | - public function get_url( $shims = false, $local = true ) { |
|
291 | - $script = $shims ? 'v4-shims' : 'all'; |
|
292 | - $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
293 | - $type = $this->settings['type']; |
|
294 | - $version = $this->settings['version']; |
|
295 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
296 | - $url = ''; |
|
297 | - |
|
298 | - if ( $type == 'KIT' && $kit_url ) { |
|
299 | - if ( $shims ) { |
|
300 | - // if its a kit then we don't add shims here |
|
301 | - return ''; |
|
302 | - } |
|
303 | - $url .= $kit_url; // CDN |
|
304 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
305 | - } else { |
|
306 | - $v = ''; |
|
307 | - // Check and load locally. |
|
308 | - if ( $local && $this->has_local() ) { |
|
309 | - $script .= ".min"; |
|
310 | - $v .= '&ver=' . strip_tags( $this->settings['local_version'] ); |
|
311 | - $url .= $this->get_fonts_url(); // Local fonts url. |
|
312 | - } else { |
|
313 | - $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
314 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
315 | - } |
|
316 | - $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
317 | - $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
318 | - $url .= "?wpfas=true" . $v; // set our var so our version is not removed |
|
319 | - } |
|
320 | - |
|
321 | - return $url; |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
326 | - * |
|
327 | - * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
328 | - * |
|
329 | - * @param $url |
|
330 | - * @param $original_url |
|
331 | - * @param $_context |
|
332 | - * |
|
333 | - * @return string The filtered url. |
|
334 | - */ |
|
335 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
336 | - |
|
337 | - if ( $_context == 'display' |
|
338 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
339 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
340 | - ) {// it's a font-awesome-url (probably) |
|
341 | - |
|
342 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
343 | - if ( $this->settings['type'] == 'JS' ) { |
|
344 | - if ( $this->settings['js-pseudo'] ) { |
|
345 | - $url .= "' data-search-pseudo-elements defer='defer"; |
|
346 | - } else { |
|
347 | - $url .= "' defer='defer"; |
|
348 | - } |
|
349 | - } |
|
350 | - } else { |
|
351 | - $url = ''; // removing the url removes the file |
|
352 | - } |
|
353 | - |
|
354 | - } |
|
355 | - |
|
356 | - return $url; |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Register the database settings with WordPress. |
|
361 | - */ |
|
362 | - public function register_settings() { |
|
363 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Add the WordPress settings menu item. |
|
368 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
369 | - */ |
|
370 | - public function menu_item() { |
|
371 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
372 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
373 | - $this, |
|
374 | - 'settings_page' |
|
375 | - ) ); |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * Get the current Font Awesome output settings. |
|
380 | - * |
|
381 | - * @return array The array of settings. |
|
382 | - */ |
|
383 | - public function get_settings() { |
|
384 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
385 | - |
|
386 | - $defaults = array( |
|
387 | - 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
388 | - 'version' => '', // latest |
|
389 | - 'enqueue' => '', // front and backend |
|
390 | - 'shims' => '0', // default OFF now in 2020 |
|
391 | - 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
392 | - 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
393 | - 'pro' => '0', // if pro CDN url should be used |
|
394 | - 'local' => '0', // Store fonts locally. |
|
395 | - 'local_version' => '', // Local fonts version. |
|
396 | - 'kit-url' => '', // the kit url |
|
397 | - ); |
|
398 | - |
|
399 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
400 | - |
|
401 | - /** |
|
402 | - * Filter the Font Awesome settings. |
|
403 | - * |
|
404 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
405 | - */ |
|
406 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * The settings page html output. |
|
411 | - */ |
|
412 | - public function settings_page() { |
|
413 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
414 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'ayecode-connect' ) ); |
|
415 | - } |
|
416 | - |
|
417 | - // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
418 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
419 | - $this->get_latest_version( $force_api = true ); |
|
420 | - } |
|
421 | - |
|
422 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
423 | - ?> |
|
126 | + if ( ! defined( 'FAS_PRO' ) && $this->settings['pro'] ) { |
|
127 | + define( 'FAS_PRO', true ); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Get the url path to the current folder. |
|
133 | + * |
|
134 | + * @return string |
|
135 | + */ |
|
136 | + public function get_path_url() { |
|
137 | + $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) ); |
|
138 | + $content_url = untrailingslashit( WP_CONTENT_URL ); |
|
139 | + |
|
140 | + // Replace http:// to https://. |
|
141 | + if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) { |
|
142 | + $content_url = str_replace( 'http://', 'https://', $content_url ); |
|
143 | + } |
|
144 | + |
|
145 | + // Check if we are inside a plugin |
|
146 | + $file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
147 | + $url = str_replace( $content_dir, $content_url, $file_dir ); |
|
148 | + |
|
149 | + return trailingslashit( $url ); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Initiate the settings and add the required action hooks. |
|
154 | + * |
|
155 | + * @since 1.0.8 Settings name wrong - FIXED |
|
156 | + */ |
|
157 | + public function init() { |
|
158 | + // Download fontawesome locally. |
|
159 | + add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 ); |
|
160 | + add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
161 | + |
|
162 | + $this->settings = $this->get_settings(); |
|
163 | + |
|
164 | + // Check if the official plugin is active and use that instead if so. |
|
165 | + if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
166 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
167 | + add_action( 'admin_head', array( $this, 'add_generator' ), 99 ); |
|
168 | + } |
|
169 | + |
|
170 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
171 | + add_action( 'wp_head', array( $this, 'add_generator' ), 99 ); |
|
172 | + } |
|
173 | + |
|
174 | + if ( $this->settings['type'] == 'CSS' ) { |
|
175 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
176 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
177 | + //add_action( 'wp_footer', array( $this, 'enqueue_style' ), 5000 ); // not sure why this was added, seems to break frontend |
|
178 | + } |
|
179 | + |
|
180 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
181 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
182 | + add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 ); |
|
183 | + } |
|
184 | + } else { |
|
185 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
186 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
187 | + } |
|
188 | + |
|
189 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
190 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
191 | + add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 ); |
|
192 | + } |
|
193 | + } |
|
194 | + |
|
195 | + // remove font awesome if set to do so |
|
196 | + if ( $this->settings['dequeue'] == '1' ) { |
|
197 | + add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Add FA to the FSE. |
|
205 | + * |
|
206 | + * @param $editor_settings |
|
207 | + * @param $block_editor_context |
|
208 | + * |
|
209 | + * @return array |
|
210 | + */ |
|
211 | + public function enqueue_editor_styles( $editor_settings, $block_editor_context ){ |
|
212 | + |
|
213 | + if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) { |
|
214 | + $url = $this->get_url(); |
|
215 | + $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css' href='$url' media='all' />"; |
|
216 | + } |
|
217 | + |
|
218 | + return $editor_settings; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Add FA to the FSE. |
|
223 | + * |
|
224 | + * @param $editor_settings |
|
225 | + * @param $block_editor_context |
|
226 | + * |
|
227 | + * @return array |
|
228 | + */ |
|
229 | + public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){ |
|
230 | + |
|
231 | + $url = $this->get_url(); |
|
232 | + $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>"; |
|
233 | + |
|
234 | + return $editor_settings; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Adds the Font Awesome styles. |
|
239 | + */ |
|
240 | + public function enqueue_style() { |
|
241 | + // build url |
|
242 | + $url = $this->get_url(); |
|
243 | + $version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null; |
|
244 | + |
|
245 | + wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
246 | + wp_register_style( 'font-awesome', $url, array(), $version ); |
|
247 | + wp_enqueue_style( 'font-awesome' ); |
|
248 | + |
|
249 | + // RTL language support CSS. |
|
250 | + if ( is_rtl() ) { |
|
251 | + wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
252 | + } |
|
253 | + |
|
254 | + if ( $this->settings['shims'] ) { |
|
255 | + $url = $this->get_url( true ); |
|
256 | + wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
257 | + wp_register_style( 'font-awesome-shims', $url, array(), $version ); |
|
258 | + wp_enqueue_style( 'font-awesome-shims' ); |
|
259 | + } |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Adds the Font Awesome JS. |
|
264 | + */ |
|
265 | + public function enqueue_scripts() { |
|
266 | + // build url |
|
267 | + $url = $this->get_url(); |
|
268 | + |
|
269 | + $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
270 | + call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
271 | + wp_register_script( 'font-awesome', $url, array(), null ); |
|
272 | + wp_enqueue_script( 'font-awesome' ); |
|
273 | + |
|
274 | + if ( $this->settings['shims'] ) { |
|
275 | + $url = $this->get_url( true ); |
|
276 | + call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
277 | + wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
278 | + wp_enqueue_script( 'font-awesome-shims' ); |
|
279 | + } |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Get the url of the Font Awesome files. |
|
284 | + * |
|
285 | + * @param bool $shims If this is a shim file or not. |
|
286 | + * @param bool $local Load locally if allowed. |
|
287 | + * |
|
288 | + * @return string The url to the file. |
|
289 | + */ |
|
290 | + public function get_url( $shims = false, $local = true ) { |
|
291 | + $script = $shims ? 'v4-shims' : 'all'; |
|
292 | + $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
293 | + $type = $this->settings['type']; |
|
294 | + $version = $this->settings['version']; |
|
295 | + $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
296 | + $url = ''; |
|
297 | + |
|
298 | + if ( $type == 'KIT' && $kit_url ) { |
|
299 | + if ( $shims ) { |
|
300 | + // if its a kit then we don't add shims here |
|
301 | + return ''; |
|
302 | + } |
|
303 | + $url .= $kit_url; // CDN |
|
304 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
305 | + } else { |
|
306 | + $v = ''; |
|
307 | + // Check and load locally. |
|
308 | + if ( $local && $this->has_local() ) { |
|
309 | + $script .= ".min"; |
|
310 | + $v .= '&ver=' . strip_tags( $this->settings['local_version'] ); |
|
311 | + $url .= $this->get_fonts_url(); // Local fonts url. |
|
312 | + } else { |
|
313 | + $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
314 | + $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
315 | + } |
|
316 | + $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
317 | + $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
318 | + $url .= "?wpfas=true" . $v; // set our var so our version is not removed |
|
319 | + } |
|
320 | + |
|
321 | + return $url; |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
326 | + * |
|
327 | + * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
328 | + * |
|
329 | + * @param $url |
|
330 | + * @param $original_url |
|
331 | + * @param $_context |
|
332 | + * |
|
333 | + * @return string The filtered url. |
|
334 | + */ |
|
335 | + public function remove_font_awesome( $url, $original_url, $_context ) { |
|
336 | + |
|
337 | + if ( $_context == 'display' |
|
338 | + && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
339 | + && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
340 | + ) {// it's a font-awesome-url (probably) |
|
341 | + |
|
342 | + if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
343 | + if ( $this->settings['type'] == 'JS' ) { |
|
344 | + if ( $this->settings['js-pseudo'] ) { |
|
345 | + $url .= "' data-search-pseudo-elements defer='defer"; |
|
346 | + } else { |
|
347 | + $url .= "' defer='defer"; |
|
348 | + } |
|
349 | + } |
|
350 | + } else { |
|
351 | + $url = ''; // removing the url removes the file |
|
352 | + } |
|
353 | + |
|
354 | + } |
|
355 | + |
|
356 | + return $url; |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Register the database settings with WordPress. |
|
361 | + */ |
|
362 | + public function register_settings() { |
|
363 | + register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Add the WordPress settings menu item. |
|
368 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
369 | + */ |
|
370 | + public function menu_item() { |
|
371 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
372 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
373 | + $this, |
|
374 | + 'settings_page' |
|
375 | + ) ); |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * Get the current Font Awesome output settings. |
|
380 | + * |
|
381 | + * @return array The array of settings. |
|
382 | + */ |
|
383 | + public function get_settings() { |
|
384 | + $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
385 | + |
|
386 | + $defaults = array( |
|
387 | + 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
388 | + 'version' => '', // latest |
|
389 | + 'enqueue' => '', // front and backend |
|
390 | + 'shims' => '0', // default OFF now in 2020 |
|
391 | + 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
392 | + 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
393 | + 'pro' => '0', // if pro CDN url should be used |
|
394 | + 'local' => '0', // Store fonts locally. |
|
395 | + 'local_version' => '', // Local fonts version. |
|
396 | + 'kit-url' => '', // the kit url |
|
397 | + ); |
|
398 | + |
|
399 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
400 | + |
|
401 | + /** |
|
402 | + * Filter the Font Awesome settings. |
|
403 | + * |
|
404 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
405 | + */ |
|
406 | + return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * The settings page html output. |
|
411 | + */ |
|
412 | + public function settings_page() { |
|
413 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
414 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'ayecode-connect' ) ); |
|
415 | + } |
|
416 | + |
|
417 | + // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
418 | + if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
419 | + $this->get_latest_version( $force_api = true ); |
|
420 | + } |
|
421 | + |
|
422 | + if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
423 | + ?> |
|
424 | 424 | <style> |
425 | 425 | .wpfas-kit-show { |
426 | 426 | display: none; |
@@ -446,16 +446,16 @@ discard block |
||
446 | 446 | <h1><?php echo $this->name; ?></h1> |
447 | 447 | <form method="post" action="options.php" class="fas-settings-form"> |
448 | 448 | <?php |
449 | - settings_fields( 'wp-font-awesome-settings' ); |
|
450 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
451 | - $table_class = ''; |
|
452 | - if ( $this->settings['type'] ) { |
|
453 | - $table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set'; |
|
454 | - } |
|
455 | - if ( ! empty( $this->settings['pro'] ) ) { |
|
456 | - $table_class .= ' wpfas-has-pro'; |
|
457 | - } |
|
458 | - ?> |
|
449 | + settings_fields( 'wp-font-awesome-settings' ); |
|
450 | + do_settings_sections( 'wp-font-awesome-settings' ); |
|
451 | + $table_class = ''; |
|
452 | + if ( $this->settings['type'] ) { |
|
453 | + $table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set'; |
|
454 | + } |
|
455 | + if ( ! empty( $this->settings['pro'] ) ) { |
|
456 | + $table_class .= ' wpfas-has-pro'; |
|
457 | + } |
|
458 | + ?> |
|
459 | 459 | <?php if ( $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ) { ?> |
460 | 460 | <?php if ( $this->has_local() ) { ?> |
461 | 461 | <div class="notice notice-info"><p><strong><?php _e( 'Font Awesome fonts are loading locally.', 'ayecode-connect' ); ?></strong></p></div> |
@@ -480,12 +480,12 @@ discard block |
||
480 | 480 | <td> |
481 | 481 | <input class="regular-text" id="wpfas-kit-url" type="url" name="wp-font-awesome-settings[kit-url]" value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
482 | 482 | <span><?php |
483 | - echo wp_sprintf( |
|
484 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'ayecode-connect' ), |
|
485 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
486 | - '</a>' |
|
487 | - ); |
|
488 | - ?></span> |
|
483 | + echo wp_sprintf( |
|
484 | + __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'ayecode-connect' ), |
|
485 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
486 | + '</a>' |
|
487 | + ); |
|
488 | + ?></span> |
|
489 | 489 | </td> |
490 | 490 | </tr> |
491 | 491 | |
@@ -526,14 +526,14 @@ discard block |
||
526 | 526 | <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/> |
527 | 527 | <input type="checkbox" name="wp-font-awesome-settings[pro]" value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro" onchange="if(jQuery(this).is(':checked')){jQuery('.wpfas-table-settings').addClass('wpfas-has-pro')}else{jQuery('.wpfas-table-settings').removeClass('wpfas-has-pro')}"/> |
528 | 528 | <span><?php |
529 | - echo wp_sprintf( |
|
530 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'ayecode-connect' ), |
|
531 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
|
532 | - ' <i class="fas fa-external-link-alt"></i></a>', |
|
533 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
|
534 | - ' <i class="fas fa-external-link-alt"></i></a>' |
|
535 | - ); |
|
536 | - ?></span> |
|
529 | + echo wp_sprintf( |
|
530 | + __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'ayecode-connect' ), |
|
531 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
|
532 | + ' <i class="fas fa-external-link-alt"></i></a>', |
|
533 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
|
534 | + ' <i class="fas fa-external-link-alt"></i></a>' |
|
535 | + ); |
|
536 | + ?></span> |
|
537 | 537 | </td> |
538 | 538 | </tr> |
539 | 539 | |
@@ -587,8 +587,8 @@ discard block |
||
587 | 587 | </table> |
588 | 588 | <div class="fas-buttons"> |
589 | 589 | <?php |
590 | - submit_button(); |
|
591 | - ?> |
|
590 | + submit_button(); |
|
591 | + ?> |
|
592 | 592 | <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 24,000+ more icons with Font Awesome Pro','ayecode-connect'); ?> <i class="fas fa-external-link-alt"></i></a></p> |
593 | 593 | |
594 | 594 | </div> |
@@ -597,414 +597,414 @@ discard block |
||
597 | 597 | <div id="wpfas-version"><?php echo wp_sprintf(__( 'Version: %s (affiliate links provided)', 'ayecode-connect' ), $this->version ); ?></div> |
598 | 598 | </div> |
599 | 599 | <?php |
600 | - } |
|
601 | - } |
|
602 | - |
|
603 | - /** |
|
604 | - * Check a version number is valid and if so return it or else return an empty string. |
|
605 | - * |
|
606 | - * @param $version string The version number to check. |
|
607 | - * |
|
608 | - * @since 1.0.6 |
|
609 | - * |
|
610 | - * @return string Either a valid version number or an empty string. |
|
611 | - */ |
|
612 | - public function validate_version_number( $version ) { |
|
613 | - |
|
614 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
615 | - // valid |
|
616 | - } else { |
|
617 | - $version = '';// not validated |
|
618 | - } |
|
619 | - |
|
620 | - return $version; |
|
621 | - } |
|
622 | - |
|
623 | - |
|
624 | - /** |
|
625 | - * Get the latest version of Font Awesome. |
|
626 | - * |
|
627 | - * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
628 | - * |
|
629 | - * @since 1.0.7 |
|
630 | - * @return mixed|string The latest version number found. |
|
631 | - */ |
|
632 | - public function get_latest_version( $force_api = false ) { |
|
633 | - $latest_version = $this->latest; |
|
634 | - |
|
635 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
636 | - |
|
637 | - if ( $cache === false || $force_api ) { // its not set |
|
638 | - $api_ver = $this->get_latest_version_from_api(); |
|
639 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
640 | - $latest_version = $api_ver; |
|
641 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
642 | - } |
|
643 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
644 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
645 | - $latest_version = $cache; |
|
646 | - } |
|
647 | - } |
|
648 | - |
|
649 | - // Check and auto download fonts locally. |
|
650 | - if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) { |
|
651 | - if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) { |
|
652 | - $this->download_package( $latest_version ); |
|
653 | - } |
|
654 | - } |
|
655 | - |
|
656 | - return $latest_version; |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * Get the latest Font Awesome version from the github API. |
|
661 | - * |
|
662 | - * @since 1.0.7 |
|
663 | - * @return string The latest version number or `0` on API fail. |
|
664 | - */ |
|
665 | - public function get_latest_version_from_api() { |
|
666 | - $version = "0"; |
|
667 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
668 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
669 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
670 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
671 | - $version = $api_response['tag_name']; |
|
672 | - } |
|
673 | - } |
|
674 | - |
|
675 | - return $version; |
|
676 | - } |
|
677 | - |
|
678 | - /** |
|
679 | - * Inline CSS for RTL language support. |
|
680 | - * |
|
681 | - * @since 1.0.13 |
|
682 | - * @return string Inline CSS. |
|
683 | - */ |
|
684 | - public function rtl_inline_css() { |
|
685 | - $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
686 | - |
|
687 | - return $inline_css; |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Show any warnings as an admin notice. |
|
692 | - * |
|
693 | - * @return void |
|
694 | - */ |
|
695 | - public function admin_notices() { |
|
696 | - $settings = $this->settings; |
|
697 | - |
|
698 | - if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
699 | - if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
700 | - ?> |
|
600 | + } |
|
601 | + } |
|
602 | + |
|
603 | + /** |
|
604 | + * Check a version number is valid and if so return it or else return an empty string. |
|
605 | + * |
|
606 | + * @param $version string The version number to check. |
|
607 | + * |
|
608 | + * @since 1.0.6 |
|
609 | + * |
|
610 | + * @return string Either a valid version number or an empty string. |
|
611 | + */ |
|
612 | + public function validate_version_number( $version ) { |
|
613 | + |
|
614 | + if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
615 | + // valid |
|
616 | + } else { |
|
617 | + $version = '';// not validated |
|
618 | + } |
|
619 | + |
|
620 | + return $version; |
|
621 | + } |
|
622 | + |
|
623 | + |
|
624 | + /** |
|
625 | + * Get the latest version of Font Awesome. |
|
626 | + * |
|
627 | + * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
628 | + * |
|
629 | + * @since 1.0.7 |
|
630 | + * @return mixed|string The latest version number found. |
|
631 | + */ |
|
632 | + public function get_latest_version( $force_api = false ) { |
|
633 | + $latest_version = $this->latest; |
|
634 | + |
|
635 | + $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
636 | + |
|
637 | + if ( $cache === false || $force_api ) { // its not set |
|
638 | + $api_ver = $this->get_latest_version_from_api(); |
|
639 | + if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
640 | + $latest_version = $api_ver; |
|
641 | + set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
642 | + } |
|
643 | + } elseif ( $this->validate_version_number( $cache ) ) { |
|
644 | + if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
645 | + $latest_version = $cache; |
|
646 | + } |
|
647 | + } |
|
648 | + |
|
649 | + // Check and auto download fonts locally. |
|
650 | + if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) { |
|
651 | + if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) { |
|
652 | + $this->download_package( $latest_version ); |
|
653 | + } |
|
654 | + } |
|
655 | + |
|
656 | + return $latest_version; |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * Get the latest Font Awesome version from the github API. |
|
661 | + * |
|
662 | + * @since 1.0.7 |
|
663 | + * @return string The latest version number or `0` on API fail. |
|
664 | + */ |
|
665 | + public function get_latest_version_from_api() { |
|
666 | + $version = "0"; |
|
667 | + $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
668 | + if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
669 | + $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
670 | + if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
671 | + $version = $api_response['tag_name']; |
|
672 | + } |
|
673 | + } |
|
674 | + |
|
675 | + return $version; |
|
676 | + } |
|
677 | + |
|
678 | + /** |
|
679 | + * Inline CSS for RTL language support. |
|
680 | + * |
|
681 | + * @since 1.0.13 |
|
682 | + * @return string Inline CSS. |
|
683 | + */ |
|
684 | + public function rtl_inline_css() { |
|
685 | + $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
686 | + |
|
687 | + return $inline_css; |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Show any warnings as an admin notice. |
|
692 | + * |
|
693 | + * @return void |
|
694 | + */ |
|
695 | + public function admin_notices() { |
|
696 | + $settings = $this->settings; |
|
697 | + |
|
698 | + if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
699 | + if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
700 | + ?> |
|
701 | 701 | <div class="notice notice-error is-dismissible"> |
702 | 702 | <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'ayecode-connect' ); ?></p> |
703 | 703 | </div> |
704 | 704 | <?php |
705 | - } |
|
706 | - } else { |
|
707 | - if ( ! empty( $settings ) ) { |
|
708 | - if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
709 | - $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
|
710 | - ?> |
|
705 | + } |
|
706 | + } else { |
|
707 | + if ( ! empty( $settings ) ) { |
|
708 | + if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
709 | + $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
|
710 | + ?> |
|
711 | 711 | <div class="notice notice-error is-dismissible"> |
712 | 712 | <p><?php echo wp_sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'ayecode-connect' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p> |
713 | 713 | </div> |
714 | 714 | <?php |
715 | - } |
|
716 | - } |
|
717 | - } |
|
718 | - } |
|
719 | - |
|
720 | - /** |
|
721 | - * Handle fontawesome add settings to download fontawesome to store locally. |
|
722 | - * |
|
723 | - * @since 1.1.1 |
|
724 | - * |
|
725 | - * @param string $option The option name. |
|
726 | - * @param mixed $value The option value. |
|
727 | - */ |
|
728 | - public function add_option_wp_font_awesome_settings( $option, $value ) { |
|
729 | - // Do nothing if WordPress is being installed. |
|
730 | - if ( wp_installing() ) { |
|
731 | - return; |
|
732 | - } |
|
733 | - |
|
734 | - if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) { |
|
735 | - $version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version(); |
|
736 | - |
|
737 | - if ( ! empty( $version ) ) { |
|
738 | - $response = $this->download_package( $version, $value ); |
|
739 | - |
|
740 | - if ( is_wp_error( $response ) ) { |
|
741 | - add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' ); |
|
742 | - } |
|
743 | - } |
|
744 | - } |
|
745 | - } |
|
746 | - |
|
747 | - /** |
|
748 | - * Handle fontawesome update settings to download fontawesome to store locally. |
|
749 | - * |
|
750 | - * @since 1.1.0 |
|
751 | - * |
|
752 | - * @param mixed $old_value The old option value. |
|
753 | - * @param mixed $value The new option value. |
|
754 | - */ |
|
755 | - public function update_option_wp_font_awesome_settings( $old_value, $new_value ) { |
|
756 | - // Do nothing if WordPress is being installed. |
|
757 | - if ( wp_installing() ) { |
|
758 | - return; |
|
759 | - } |
|
760 | - |
|
761 | - if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) { |
|
762 | - // Old values |
|
763 | - $old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' ); |
|
764 | - $old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0; |
|
765 | - |
|
766 | - // New values |
|
767 | - $new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version(); |
|
768 | - |
|
769 | - if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
770 | - $response = $this->download_package( $new_version, $new_value ); |
|
771 | - |
|
772 | - if ( is_wp_error( $response ) ) { |
|
773 | - add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' ); |
|
774 | - } |
|
775 | - } |
|
776 | - } |
|
777 | - } |
|
778 | - |
|
779 | - /** |
|
780 | - * Get the fonts directory local path. |
|
781 | - * |
|
782 | - * @since 1.1.0 |
|
783 | - * |
|
784 | - * @param string Fonts directory local path. |
|
785 | - */ |
|
786 | - public function get_fonts_dir() { |
|
787 | - $upload_dir = wp_upload_dir( null, false ); |
|
788 | - |
|
789 | - return $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR; |
|
790 | - } |
|
791 | - |
|
792 | - /** |
|
793 | - * Get the fonts directory local url. |
|
794 | - * |
|
795 | - * @since 1.1.0 |
|
796 | - * |
|
797 | - * @param string Fonts directory local url. |
|
798 | - */ |
|
799 | - public function get_fonts_url() { |
|
800 | - $upload_dir = wp_upload_dir( null, false ); |
|
801 | - |
|
802 | - return $upload_dir['baseurl'] . '/ayefonts/fa/'; |
|
803 | - } |
|
804 | - |
|
805 | - /** |
|
806 | - * Check whether load locally active. |
|
807 | - * |
|
808 | - * @since 1.1.0 |
|
809 | - * |
|
810 | - * @return bool True if active else false. |
|
811 | - */ |
|
812 | - public function has_local() { |
|
813 | - if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
814 | - return true; |
|
815 | - } |
|
816 | - |
|
817 | - return false; |
|
818 | - } |
|
819 | - |
|
820 | - /** |
|
821 | - * Get the WP Filesystem access. |
|
822 | - * |
|
823 | - * @since 1.1.0 |
|
824 | - * |
|
825 | - * @return object The WP Filesystem. |
|
826 | - */ |
|
827 | - public function get_wp_filesystem() { |
|
828 | - if ( ! function_exists( 'get_filesystem_method' ) ) { |
|
829 | - require_once( ABSPATH . "/wp-admin/includes/file.php" ); |
|
830 | - } |
|
831 | - |
|
832 | - $access_type = get_filesystem_method(); |
|
833 | - |
|
834 | - if ( $access_type === 'direct' ) { |
|
835 | - /* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */ |
|
836 | - $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
837 | - |
|
838 | - /* Initialize the API */ |
|
839 | - if ( ! WP_Filesystem( $creds ) ) { |
|
840 | - /* Any problems and we exit */ |
|
841 | - return false; |
|
842 | - } |
|
843 | - |
|
844 | - global $wp_filesystem; |
|
845 | - |
|
846 | - return $wp_filesystem; |
|
847 | - /* Do our file manipulations below */ |
|
848 | - } else if ( defined( 'FTP_USER' ) ) { |
|
849 | - $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
850 | - |
|
851 | - /* Initialize the API */ |
|
852 | - if ( ! WP_Filesystem( $creds ) ) { |
|
853 | - /* Any problems and we exit */ |
|
854 | - return false; |
|
855 | - } |
|
856 | - |
|
857 | - global $wp_filesystem; |
|
858 | - |
|
859 | - return $wp_filesystem; |
|
860 | - } else { |
|
861 | - /* Don't have direct write access. Prompt user with our notice */ |
|
862 | - return false; |
|
863 | - } |
|
864 | - } |
|
865 | - |
|
866 | - /** |
|
867 | - * Download the fontawesome package file. |
|
868 | - * |
|
869 | - * @since 1.1.0 |
|
870 | - * |
|
871 | - * @param mixed $version The font awesome. |
|
872 | - * @param array $option Fontawesome settings. |
|
873 | - * @return WP_ERROR|bool Error on fail and true on success. |
|
874 | - */ |
|
875 | - public function download_package( $version, $option = array() ) { |
|
876 | - $filename = 'fontawesome-free-' . $version . '-web'; |
|
877 | - $url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip'; |
|
878 | - |
|
879 | - if ( ! function_exists( 'wp_handle_upload' ) ) { |
|
880 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
881 | - } |
|
882 | - |
|
883 | - $download_file = download_url( esc_url_raw( $url ) ); |
|
884 | - |
|
885 | - if ( is_wp_error( $download_file ) ) { |
|
886 | - return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'ayecode-connect' ) ); |
|
887 | - } else if ( empty( $download_file ) ) { |
|
888 | - return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'ayecode-connect' ) ); |
|
889 | - } |
|
890 | - |
|
891 | - $response = $this->extract_package( $download_file, $filename, true ); |
|
892 | - |
|
893 | - // Update local version. |
|
894 | - if ( is_wp_error( $response ) ) { |
|
895 | - return $response; |
|
896 | - } else if ( $response ) { |
|
897 | - if ( empty( $option ) ) { |
|
898 | - $option = get_option( 'wp-font-awesome-settings' ); |
|
899 | - } |
|
900 | - |
|
901 | - $option['local_version'] = $version; |
|
902 | - |
|
903 | - // Remove action to prevent looping. |
|
904 | - remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
905 | - |
|
906 | - update_option( 'wp-font-awesome-settings', $option ); |
|
907 | - |
|
908 | - return true; |
|
909 | - } |
|
910 | - |
|
911 | - return false; |
|
912 | - } |
|
913 | - |
|
914 | - /** |
|
915 | - * Extract the fontawesome package file. |
|
916 | - * |
|
917 | - * @since 1.1.0 |
|
918 | - * |
|
919 | - * @param string $package The package file path. |
|
920 | - * @param string $dirname Package file name. |
|
921 | - * @param bool $delete_package Delete temp file or not. |
|
922 | - * @return WP_Error|bool True on success WP_Error on fail. |
|
923 | - */ |
|
924 | - public function extract_package( $package, $dirname = '', $delete_package = false ) { |
|
925 | - global $wp_filesystem; |
|
926 | - |
|
927 | - $wp_filesystem = $this->get_wp_filesystem(); |
|
928 | - |
|
929 | - if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { |
|
930 | - return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'ayecode-connect' ) ); |
|
931 | - } else if ( empty( $wp_filesystem ) ) { |
|
932 | - return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'ayecode-connect' ) ); |
|
933 | - } |
|
934 | - |
|
935 | - $fonts_dir = $this->get_fonts_dir(); |
|
936 | - $fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR; |
|
937 | - |
|
938 | - if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
939 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
940 | - } |
|
941 | - |
|
942 | - // Unzip package to working directory. |
|
943 | - $result = unzip_file( $package, $fonts_tmp_dir ); |
|
944 | - |
|
945 | - if ( is_wp_error( $result ) ) { |
|
946 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
947 | - |
|
948 | - if ( 'incompatible_archive' === $result->get_error_code() ) { |
|
949 | - return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'ayecode-connect' ) ); |
|
950 | - } |
|
951 | - |
|
952 | - return $result; |
|
953 | - } |
|
954 | - |
|
955 | - if ( $wp_filesystem->is_dir( $fonts_dir ) ) { |
|
956 | - $wp_filesystem->delete( $fonts_dir, true ); |
|
957 | - } |
|
958 | - |
|
959 | - $extract_dir = $fonts_tmp_dir; |
|
960 | - |
|
961 | - if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) { |
|
962 | - $extract_dir .= $dirname . DIRECTORY_SEPARATOR; |
|
963 | - } |
|
964 | - |
|
965 | - try { |
|
966 | - $return = $wp_filesystem->move( $extract_dir, $fonts_dir, true ); |
|
967 | - } catch ( Exception $e ) { |
|
968 | - $return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'ayecode-connect' ) ); |
|
969 | - } |
|
970 | - |
|
971 | - if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
972 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
973 | - } |
|
974 | - |
|
975 | - // Once extracted, delete the package if required. |
|
976 | - if ( $delete_package ) { |
|
977 | - unlink( $package ); |
|
978 | - } |
|
979 | - |
|
980 | - return $return; |
|
981 | - } |
|
982 | - |
|
983 | - /** |
|
984 | - * Output the version in the header. |
|
985 | - */ |
|
986 | - public function add_generator() { |
|
987 | - $file = str_replace( array( "/", "\\" ), "/", realpath( __FILE__ ) ); |
|
988 | - $plugins_dir = str_replace( array( "/", "\\" ), "/", realpath( WP_PLUGIN_DIR ) ); |
|
989 | - |
|
990 | - // Find source plugin/theme. |
|
991 | - $source = array(); |
|
992 | - if ( strpos( $file, $plugins_dir ) !== false ) { |
|
993 | - $source = explode( "/", plugin_basename( $file ) ); |
|
994 | - } else if ( function_exists( 'get_theme_root' ) ) { |
|
995 | - $themes_dir = str_replace( array( "/", "\\" ), "/", realpath( get_theme_root() ) ); |
|
996 | - |
|
997 | - if ( strpos( $file, $themes_dir ) !== false ) { |
|
998 | - $source = explode( "/", ltrim( str_replace( $themes_dir, "", $file ), "/" ) ); |
|
999 | - } |
|
1000 | - } |
|
1001 | - |
|
1002 | - echo '<meta name="generator" content="WP Font Awesome Settings v' . esc_attr( $this->version ) . '"' . ( ! empty( $source[0] ) ? ' data-ac-source="' . esc_attr( $source[0] ) . '"' : '' ) . ' />'; |
|
1003 | - } |
|
1004 | - } |
|
1005 | - |
|
1006 | - /** |
|
1007 | - * Run the class if found. |
|
1008 | - */ |
|
1009 | - WP_Font_Awesome_Settings::instance(); |
|
715 | + } |
|
716 | + } |
|
717 | + } |
|
718 | + } |
|
719 | + |
|
720 | + /** |
|
721 | + * Handle fontawesome add settings to download fontawesome to store locally. |
|
722 | + * |
|
723 | + * @since 1.1.1 |
|
724 | + * |
|
725 | + * @param string $option The option name. |
|
726 | + * @param mixed $value The option value. |
|
727 | + */ |
|
728 | + public function add_option_wp_font_awesome_settings( $option, $value ) { |
|
729 | + // Do nothing if WordPress is being installed. |
|
730 | + if ( wp_installing() ) { |
|
731 | + return; |
|
732 | + } |
|
733 | + |
|
734 | + if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) { |
|
735 | + $version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version(); |
|
736 | + |
|
737 | + if ( ! empty( $version ) ) { |
|
738 | + $response = $this->download_package( $version, $value ); |
|
739 | + |
|
740 | + if ( is_wp_error( $response ) ) { |
|
741 | + add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' ); |
|
742 | + } |
|
743 | + } |
|
744 | + } |
|
745 | + } |
|
746 | + |
|
747 | + /** |
|
748 | + * Handle fontawesome update settings to download fontawesome to store locally. |
|
749 | + * |
|
750 | + * @since 1.1.0 |
|
751 | + * |
|
752 | + * @param mixed $old_value The old option value. |
|
753 | + * @param mixed $value The new option value. |
|
754 | + */ |
|
755 | + public function update_option_wp_font_awesome_settings( $old_value, $new_value ) { |
|
756 | + // Do nothing if WordPress is being installed. |
|
757 | + if ( wp_installing() ) { |
|
758 | + return; |
|
759 | + } |
|
760 | + |
|
761 | + if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) { |
|
762 | + // Old values |
|
763 | + $old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' ); |
|
764 | + $old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0; |
|
765 | + |
|
766 | + // New values |
|
767 | + $new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version(); |
|
768 | + |
|
769 | + if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
770 | + $response = $this->download_package( $new_version, $new_value ); |
|
771 | + |
|
772 | + if ( is_wp_error( $response ) ) { |
|
773 | + add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' ); |
|
774 | + } |
|
775 | + } |
|
776 | + } |
|
777 | + } |
|
778 | + |
|
779 | + /** |
|
780 | + * Get the fonts directory local path. |
|
781 | + * |
|
782 | + * @since 1.1.0 |
|
783 | + * |
|
784 | + * @param string Fonts directory local path. |
|
785 | + */ |
|
786 | + public function get_fonts_dir() { |
|
787 | + $upload_dir = wp_upload_dir( null, false ); |
|
788 | + |
|
789 | + return $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR; |
|
790 | + } |
|
791 | + |
|
792 | + /** |
|
793 | + * Get the fonts directory local url. |
|
794 | + * |
|
795 | + * @since 1.1.0 |
|
796 | + * |
|
797 | + * @param string Fonts directory local url. |
|
798 | + */ |
|
799 | + public function get_fonts_url() { |
|
800 | + $upload_dir = wp_upload_dir( null, false ); |
|
801 | + |
|
802 | + return $upload_dir['baseurl'] . '/ayefonts/fa/'; |
|
803 | + } |
|
804 | + |
|
805 | + /** |
|
806 | + * Check whether load locally active. |
|
807 | + * |
|
808 | + * @since 1.1.0 |
|
809 | + * |
|
810 | + * @return bool True if active else false. |
|
811 | + */ |
|
812 | + public function has_local() { |
|
813 | + if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
814 | + return true; |
|
815 | + } |
|
816 | + |
|
817 | + return false; |
|
818 | + } |
|
819 | + |
|
820 | + /** |
|
821 | + * Get the WP Filesystem access. |
|
822 | + * |
|
823 | + * @since 1.1.0 |
|
824 | + * |
|
825 | + * @return object The WP Filesystem. |
|
826 | + */ |
|
827 | + public function get_wp_filesystem() { |
|
828 | + if ( ! function_exists( 'get_filesystem_method' ) ) { |
|
829 | + require_once( ABSPATH . "/wp-admin/includes/file.php" ); |
|
830 | + } |
|
831 | + |
|
832 | + $access_type = get_filesystem_method(); |
|
833 | + |
|
834 | + if ( $access_type === 'direct' ) { |
|
835 | + /* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */ |
|
836 | + $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
837 | + |
|
838 | + /* Initialize the API */ |
|
839 | + if ( ! WP_Filesystem( $creds ) ) { |
|
840 | + /* Any problems and we exit */ |
|
841 | + return false; |
|
842 | + } |
|
843 | + |
|
844 | + global $wp_filesystem; |
|
845 | + |
|
846 | + return $wp_filesystem; |
|
847 | + /* Do our file manipulations below */ |
|
848 | + } else if ( defined( 'FTP_USER' ) ) { |
|
849 | + $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
850 | + |
|
851 | + /* Initialize the API */ |
|
852 | + if ( ! WP_Filesystem( $creds ) ) { |
|
853 | + /* Any problems and we exit */ |
|
854 | + return false; |
|
855 | + } |
|
856 | + |
|
857 | + global $wp_filesystem; |
|
858 | + |
|
859 | + return $wp_filesystem; |
|
860 | + } else { |
|
861 | + /* Don't have direct write access. Prompt user with our notice */ |
|
862 | + return false; |
|
863 | + } |
|
864 | + } |
|
865 | + |
|
866 | + /** |
|
867 | + * Download the fontawesome package file. |
|
868 | + * |
|
869 | + * @since 1.1.0 |
|
870 | + * |
|
871 | + * @param mixed $version The font awesome. |
|
872 | + * @param array $option Fontawesome settings. |
|
873 | + * @return WP_ERROR|bool Error on fail and true on success. |
|
874 | + */ |
|
875 | + public function download_package( $version, $option = array() ) { |
|
876 | + $filename = 'fontawesome-free-' . $version . '-web'; |
|
877 | + $url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip'; |
|
878 | + |
|
879 | + if ( ! function_exists( 'wp_handle_upload' ) ) { |
|
880 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
881 | + } |
|
882 | + |
|
883 | + $download_file = download_url( esc_url_raw( $url ) ); |
|
884 | + |
|
885 | + if ( is_wp_error( $download_file ) ) { |
|
886 | + return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'ayecode-connect' ) ); |
|
887 | + } else if ( empty( $download_file ) ) { |
|
888 | + return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'ayecode-connect' ) ); |
|
889 | + } |
|
890 | + |
|
891 | + $response = $this->extract_package( $download_file, $filename, true ); |
|
892 | + |
|
893 | + // Update local version. |
|
894 | + if ( is_wp_error( $response ) ) { |
|
895 | + return $response; |
|
896 | + } else if ( $response ) { |
|
897 | + if ( empty( $option ) ) { |
|
898 | + $option = get_option( 'wp-font-awesome-settings' ); |
|
899 | + } |
|
900 | + |
|
901 | + $option['local_version'] = $version; |
|
902 | + |
|
903 | + // Remove action to prevent looping. |
|
904 | + remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
905 | + |
|
906 | + update_option( 'wp-font-awesome-settings', $option ); |
|
907 | + |
|
908 | + return true; |
|
909 | + } |
|
910 | + |
|
911 | + return false; |
|
912 | + } |
|
913 | + |
|
914 | + /** |
|
915 | + * Extract the fontawesome package file. |
|
916 | + * |
|
917 | + * @since 1.1.0 |
|
918 | + * |
|
919 | + * @param string $package The package file path. |
|
920 | + * @param string $dirname Package file name. |
|
921 | + * @param bool $delete_package Delete temp file or not. |
|
922 | + * @return WP_Error|bool True on success WP_Error on fail. |
|
923 | + */ |
|
924 | + public function extract_package( $package, $dirname = '', $delete_package = false ) { |
|
925 | + global $wp_filesystem; |
|
926 | + |
|
927 | + $wp_filesystem = $this->get_wp_filesystem(); |
|
928 | + |
|
929 | + if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { |
|
930 | + return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'ayecode-connect' ) ); |
|
931 | + } else if ( empty( $wp_filesystem ) ) { |
|
932 | + return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'ayecode-connect' ) ); |
|
933 | + } |
|
934 | + |
|
935 | + $fonts_dir = $this->get_fonts_dir(); |
|
936 | + $fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR; |
|
937 | + |
|
938 | + if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
939 | + $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
940 | + } |
|
941 | + |
|
942 | + // Unzip package to working directory. |
|
943 | + $result = unzip_file( $package, $fonts_tmp_dir ); |
|
944 | + |
|
945 | + if ( is_wp_error( $result ) ) { |
|
946 | + $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
947 | + |
|
948 | + if ( 'incompatible_archive' === $result->get_error_code() ) { |
|
949 | + return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'ayecode-connect' ) ); |
|
950 | + } |
|
951 | + |
|
952 | + return $result; |
|
953 | + } |
|
954 | + |
|
955 | + if ( $wp_filesystem->is_dir( $fonts_dir ) ) { |
|
956 | + $wp_filesystem->delete( $fonts_dir, true ); |
|
957 | + } |
|
958 | + |
|
959 | + $extract_dir = $fonts_tmp_dir; |
|
960 | + |
|
961 | + if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) { |
|
962 | + $extract_dir .= $dirname . DIRECTORY_SEPARATOR; |
|
963 | + } |
|
964 | + |
|
965 | + try { |
|
966 | + $return = $wp_filesystem->move( $extract_dir, $fonts_dir, true ); |
|
967 | + } catch ( Exception $e ) { |
|
968 | + $return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'ayecode-connect' ) ); |
|
969 | + } |
|
970 | + |
|
971 | + if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
972 | + $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
973 | + } |
|
974 | + |
|
975 | + // Once extracted, delete the package if required. |
|
976 | + if ( $delete_package ) { |
|
977 | + unlink( $package ); |
|
978 | + } |
|
979 | + |
|
980 | + return $return; |
|
981 | + } |
|
982 | + |
|
983 | + /** |
|
984 | + * Output the version in the header. |
|
985 | + */ |
|
986 | + public function add_generator() { |
|
987 | + $file = str_replace( array( "/", "\\" ), "/", realpath( __FILE__ ) ); |
|
988 | + $plugins_dir = str_replace( array( "/", "\\" ), "/", realpath( WP_PLUGIN_DIR ) ); |
|
989 | + |
|
990 | + // Find source plugin/theme. |
|
991 | + $source = array(); |
|
992 | + if ( strpos( $file, $plugins_dir ) !== false ) { |
|
993 | + $source = explode( "/", plugin_basename( $file ) ); |
|
994 | + } else if ( function_exists( 'get_theme_root' ) ) { |
|
995 | + $themes_dir = str_replace( array( "/", "\\" ), "/", realpath( get_theme_root() ) ); |
|
996 | + |
|
997 | + if ( strpos( $file, $themes_dir ) !== false ) { |
|
998 | + $source = explode( "/", ltrim( str_replace( $themes_dir, "", $file ), "/" ) ); |
|
999 | + } |
|
1000 | + } |
|
1001 | + |
|
1002 | + echo '<meta name="generator" content="WP Font Awesome Settings v' . esc_attr( $this->version ) . '"' . ( ! empty( $source[0] ) ? ' data-ac-source="' . esc_attr( $source[0] ) . '"' : '' ) . ' />'; |
|
1003 | + } |
|
1004 | + } |
|
1005 | + |
|
1006 | + /** |
|
1007 | + * Run the class if found. |
|
1008 | + */ |
|
1009 | + WP_Font_Awesome_Settings::instance(); |
|
1010 | 1010 | } |
@@ -1,99 +1,99 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; |
|
4 | + exit; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | if ( ! class_exists( 'AyeCode_Deactivation_Survey' ) ) { |
8 | 8 | |
9 | - class AyeCode_Deactivation_Survey { |
|
9 | + class AyeCode_Deactivation_Survey { |
|
10 | 10 | |
11 | - /** |
|
12 | - * AyeCode_Deactivation_Survey instance. |
|
13 | - * |
|
14 | - * @access private |
|
15 | - * @since 1.0.0 |
|
16 | - * @var AyeCode_Deactivation_Survey There can be only one! |
|
17 | - */ |
|
18 | - private static $instance = null; |
|
11 | + /** |
|
12 | + * AyeCode_Deactivation_Survey instance. |
|
13 | + * |
|
14 | + * @access private |
|
15 | + * @since 1.0.0 |
|
16 | + * @var AyeCode_Deactivation_Survey There can be only one! |
|
17 | + */ |
|
18 | + private static $instance = null; |
|
19 | 19 | |
20 | - public static $plugins; |
|
20 | + public static $plugins; |
|
21 | 21 | |
22 | - public $version = "1.0.7"; |
|
22 | + public $version = "1.0.7"; |
|
23 | 23 | |
24 | - public static function instance( $plugin = array() ) { |
|
25 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_Deactivation_Survey ) ) { |
|
26 | - self::$instance = new AyeCode_Deactivation_Survey; |
|
27 | - self::$plugins = array(); |
|
24 | + public static function instance( $plugin = array() ) { |
|
25 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_Deactivation_Survey ) ) { |
|
26 | + self::$instance = new AyeCode_Deactivation_Survey; |
|
27 | + self::$plugins = array(); |
|
28 | 28 | |
29 | - add_action( 'admin_enqueue_scripts', array( self::$instance, 'scripts' ) ); |
|
29 | + add_action( 'admin_enqueue_scripts', array( self::$instance, 'scripts' ) ); |
|
30 | 30 | |
31 | - do_action( 'ayecode_deactivation_survey_loaded' ); |
|
32 | - } |
|
31 | + do_action( 'ayecode_deactivation_survey_loaded' ); |
|
32 | + } |
|
33 | 33 | |
34 | - if(!empty($plugin)){ |
|
35 | - self::$plugins[] = (object)$plugin; |
|
36 | - } |
|
34 | + if(!empty($plugin)){ |
|
35 | + self::$plugins[] = (object)$plugin; |
|
36 | + } |
|
37 | 37 | |
38 | - return self::$instance; |
|
39 | - } |
|
38 | + return self::$instance; |
|
39 | + } |
|
40 | 40 | |
41 | - public function scripts() { |
|
42 | - global $pagenow; |
|
41 | + public function scripts() { |
|
42 | + global $pagenow; |
|
43 | 43 | |
44 | - // Bail if we are not on the plugins page |
|
45 | - if ( $pagenow != "plugins.php" ) { |
|
46 | - return; |
|
47 | - } |
|
44 | + // Bail if we are not on the plugins page |
|
45 | + if ( $pagenow != "plugins.php" ) { |
|
46 | + return; |
|
47 | + } |
|
48 | 48 | |
49 | - // Enqueue scripts |
|
50 | - add_thickbox(); |
|
51 | - wp_enqueue_script('ayecode-deactivation-survey', plugin_dir_url(__FILE__) . 'ayecode-ds.js'); |
|
49 | + // Enqueue scripts |
|
50 | + add_thickbox(); |
|
51 | + wp_enqueue_script('ayecode-deactivation-survey', plugin_dir_url(__FILE__) . 'ayecode-ds.js'); |
|
52 | 52 | |
53 | - /* |
|
53 | + /* |
|
54 | 54 | * Localized strings. Strings can be localised by plugins using this class. |
55 | 55 | * We deliberately don't add textdomains here so that double textdomain warning is not given in theme review. |
56 | 56 | */ |
57 | - wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_strings', array( |
|
58 | - 'quick_feedback' => __( 'Quick Feedback', 'ayecode-connect' ), |
|
59 | - 'foreword' => __( 'If you would be kind enough, please tell us why you\'re deactivating?', 'ayecode-connect' ), |
|
60 | - 'better_plugins_name' => __( 'Please tell us which plugin?', 'ayecode-connect' ), |
|
61 | - 'please_tell_us' => __( 'Please tell us the reason so we can improve the plugin', 'ayecode-connect' ), |
|
62 | - 'do_not_attach_email' => __( 'Do not send my e-mail address with this feedback', 'ayecode-connect' ), |
|
63 | - 'brief_description' => __( 'Please give us any feedback that could help us improve', 'ayecode-connect' ), |
|
64 | - 'cancel' => __( 'Cancel', 'ayecode-connect' ), |
|
65 | - 'skip_and_deactivate' => __( 'Skip & Deactivate', 'ayecode-connect' ), |
|
66 | - 'submit_and_deactivate' => __( 'Submit & Deactivate', 'ayecode-connect' ), |
|
67 | - 'please_wait' => __( 'Please wait', 'ayecode-connect' ), |
|
68 | - 'get_support' => __( 'Get Support', 'ayecode-connect' ), |
|
69 | - 'documentation' => __( 'Documentation', 'ayecode-connect' ), |
|
70 | - 'thank_you' => __( 'Thank you!', 'ayecode-connect' ), |
|
71 | - )); |
|
72 | - |
|
73 | - // Plugins |
|
74 | - $plugins = apply_filters('ayecode_deactivation_survey_plugins', self::$plugins); |
|
75 | - |
|
76 | - // Reasons |
|
77 | - $defaultReasons = array( |
|
78 | - 'suddenly-stopped-working' => __( 'The plugin suddenly stopped working', 'ayecode-connect' ), |
|
79 | - 'plugin-broke-site' => __( 'The plugin broke my site', 'ayecode-connect' ), |
|
80 | - 'plugin-setup-difficult' => __( 'Too difficult to setup', 'ayecode-connect' ), |
|
81 | - 'plugin-design-difficult' => __( 'Too difficult to get the design i want', 'ayecode-connect' ), |
|
82 | - 'no-longer-needed' => __( 'I don\'t need this plugin any more', 'ayecode-connect' ), |
|
83 | - 'found-better-plugin' => __( 'I found a better plugin', 'ayecode-connect' ), |
|
84 | - 'temporary-deactivation' => __( 'It\'s a temporary deactivation, I\'m troubleshooting', 'ayecode-connect' ), |
|
85 | - 'other' => __( 'Other', 'ayecode-connect' ), |
|
86 | - ); |
|
87 | - |
|
88 | - foreach( $plugins as $plugin ) { |
|
89 | - $plugin->reasons = apply_filters( 'ayecode_deactivation_survey_reasons', $defaultReasons, $plugin ); |
|
90 | - $plugin->url = home_url(); |
|
91 | - $plugin->activated = 0; |
|
92 | - } |
|
93 | - |
|
94 | - // Send plugin data |
|
95 | - wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_plugins', $plugins); |
|
96 | - } |
|
97 | - } |
|
57 | + wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_strings', array( |
|
58 | + 'quick_feedback' => __( 'Quick Feedback', 'ayecode-connect' ), |
|
59 | + 'foreword' => __( 'If you would be kind enough, please tell us why you\'re deactivating?', 'ayecode-connect' ), |
|
60 | + 'better_plugins_name' => __( 'Please tell us which plugin?', 'ayecode-connect' ), |
|
61 | + 'please_tell_us' => __( 'Please tell us the reason so we can improve the plugin', 'ayecode-connect' ), |
|
62 | + 'do_not_attach_email' => __( 'Do not send my e-mail address with this feedback', 'ayecode-connect' ), |
|
63 | + 'brief_description' => __( 'Please give us any feedback that could help us improve', 'ayecode-connect' ), |
|
64 | + 'cancel' => __( 'Cancel', 'ayecode-connect' ), |
|
65 | + 'skip_and_deactivate' => __( 'Skip & Deactivate', 'ayecode-connect' ), |
|
66 | + 'submit_and_deactivate' => __( 'Submit & Deactivate', 'ayecode-connect' ), |
|
67 | + 'please_wait' => __( 'Please wait', 'ayecode-connect' ), |
|
68 | + 'get_support' => __( 'Get Support', 'ayecode-connect' ), |
|
69 | + 'documentation' => __( 'Documentation', 'ayecode-connect' ), |
|
70 | + 'thank_you' => __( 'Thank you!', 'ayecode-connect' ), |
|
71 | + )); |
|
72 | + |
|
73 | + // Plugins |
|
74 | + $plugins = apply_filters('ayecode_deactivation_survey_plugins', self::$plugins); |
|
75 | + |
|
76 | + // Reasons |
|
77 | + $defaultReasons = array( |
|
78 | + 'suddenly-stopped-working' => __( 'The plugin suddenly stopped working', 'ayecode-connect' ), |
|
79 | + 'plugin-broke-site' => __( 'The plugin broke my site', 'ayecode-connect' ), |
|
80 | + 'plugin-setup-difficult' => __( 'Too difficult to setup', 'ayecode-connect' ), |
|
81 | + 'plugin-design-difficult' => __( 'Too difficult to get the design i want', 'ayecode-connect' ), |
|
82 | + 'no-longer-needed' => __( 'I don\'t need this plugin any more', 'ayecode-connect' ), |
|
83 | + 'found-better-plugin' => __( 'I found a better plugin', 'ayecode-connect' ), |
|
84 | + 'temporary-deactivation' => __( 'It\'s a temporary deactivation, I\'m troubleshooting', 'ayecode-connect' ), |
|
85 | + 'other' => __( 'Other', 'ayecode-connect' ), |
|
86 | + ); |
|
87 | + |
|
88 | + foreach( $plugins as $plugin ) { |
|
89 | + $plugin->reasons = apply_filters( 'ayecode_deactivation_survey_reasons', $defaultReasons, $plugin ); |
|
90 | + $plugin->url = home_url(); |
|
91 | + $plugin->activated = 0; |
|
92 | + } |
|
93 | + |
|
94 | + // Send plugin data |
|
95 | + wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_plugins', $plugins); |
|
96 | + } |
|
97 | + } |
|
98 | 98 | |
99 | 99 | } |
100 | 100 | \ No newline at end of file |
@@ -3,102 +3,102 @@ discard block |
||
3 | 3 | class SD_Hello_World extends WP_Super_Duper { |
4 | 4 | |
5 | 5 | |
6 | - public $arguments; |
|
7 | - |
|
8 | - /** |
|
9 | - * Sets up the widgets name etc |
|
10 | - */ |
|
11 | - public function __construct() { |
|
12 | - |
|
13 | - $options = array( |
|
14 | - 'textdomain' => 'super-duper', |
|
15 | - // textdomain of the plugin/theme (used to prefix the Gutenberg block) |
|
16 | - 'block-icon' => 'fas fa-globe-americas', |
|
17 | - // Dash icon name for the block: https://developer.wordpress.org/resource/dashicons/#arrow-right |
|
18 | - // OR font-awesome 5 class name: fas fa-globe-americas |
|
19 | - 'block-category' => 'widgets', |
|
20 | - // the category for the block, 'common', 'formatting', 'layout', 'widgets', 'embed'. |
|
21 | - 'block-keywords' => "['hello','world']", |
|
22 | - // used in the block search, MAX 3 |
|
23 | - 'block-output' => array( // the block visual output elements as an array |
|
24 | - array( |
|
25 | - 'element' => 'p', |
|
26 | - 'title' => __( 'Placeholder', 'ayecode-connect' ), |
|
27 | - 'class' => '[%className%]', |
|
28 | - 'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%] |
|
29 | - ) |
|
30 | - ), |
|
31 | - 'block-wrap' => '', // You can specify the type of element to wrap the block `div` or `span` etc.. Or blank for no wrap at all. |
|
32 | - 'class_name' => __CLASS__, |
|
33 | - // The calling class name |
|
34 | - 'base_id' => 'hello_world', |
|
35 | - // this is used as the widget id and the shortcode id. |
|
36 | - 'name' => __( 'Hello World', 'ayecode-connect' ), |
|
37 | - // the name of the widget/block |
|
38 | - 'widget_ops' => array( |
|
39 | - 'classname' => 'hello-world-class', |
|
40 | - // widget class |
|
41 | - 'description' => esc_html__( 'This is an example that will take a text parameter and output it after `Hello:`.', 'ayecode-connect' ), |
|
42 | - // widget description |
|
43 | - ), |
|
44 | - 'no_wrap' => true, // This will prevent the widget being wrapped in the containing widget class div. |
|
45 | - 'arguments' => array( // these are the arguments that will be used in the widget, shortcode and block settings. |
|
46 | - 'after_text' => array( // this is the input name='' |
|
47 | - 'title' => __( 'Text after hello:', 'ayecode-connect' ), |
|
48 | - // input title |
|
49 | - 'desc' => __( 'This is the text that will appear after `Hello:`.', 'ayecode-connect' ), |
|
50 | - // input description |
|
51 | - 'type' => 'text', |
|
52 | - // the type of input, test, select, checkbox etc. |
|
53 | - 'placeholder' => 'World', |
|
54 | - // the input placeholder text. |
|
55 | - 'desc_tip' => true, |
|
56 | - // if the input should show the widget description text as a tooltip. |
|
57 | - 'default' => 'World', |
|
58 | - // the input default value. |
|
59 | - 'advanced' => false |
|
60 | - // not yet implemented |
|
61 | - ), |
|
62 | - ) |
|
63 | - ); |
|
64 | - |
|
65 | - parent::__construct( $options ); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * This is the output function for the widget, shortcode and block (front end). |
|
71 | - * |
|
72 | - * @param array $args The arguments values. |
|
73 | - * @param array $widget_args The widget arguments when used. |
|
74 | - * @param string $content The shortcode content argument |
|
75 | - * |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
79 | - |
|
80 | - /** |
|
81 | - * @var string $after_text |
|
82 | - * @var string $another_input This is added by filter below. |
|
83 | - */ |
|
84 | - extract( $args, EXTR_SKIP ); |
|
85 | - |
|
86 | - /* |
|
6 | + public $arguments; |
|
7 | + |
|
8 | + /** |
|
9 | + * Sets up the widgets name etc |
|
10 | + */ |
|
11 | + public function __construct() { |
|
12 | + |
|
13 | + $options = array( |
|
14 | + 'textdomain' => 'super-duper', |
|
15 | + // textdomain of the plugin/theme (used to prefix the Gutenberg block) |
|
16 | + 'block-icon' => 'fas fa-globe-americas', |
|
17 | + // Dash icon name for the block: https://developer.wordpress.org/resource/dashicons/#arrow-right |
|
18 | + // OR font-awesome 5 class name: fas fa-globe-americas |
|
19 | + 'block-category' => 'widgets', |
|
20 | + // the category for the block, 'common', 'formatting', 'layout', 'widgets', 'embed'. |
|
21 | + 'block-keywords' => "['hello','world']", |
|
22 | + // used in the block search, MAX 3 |
|
23 | + 'block-output' => array( // the block visual output elements as an array |
|
24 | + array( |
|
25 | + 'element' => 'p', |
|
26 | + 'title' => __( 'Placeholder', 'ayecode-connect' ), |
|
27 | + 'class' => '[%className%]', |
|
28 | + 'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%] |
|
29 | + ) |
|
30 | + ), |
|
31 | + 'block-wrap' => '', // You can specify the type of element to wrap the block `div` or `span` etc.. Or blank for no wrap at all. |
|
32 | + 'class_name' => __CLASS__, |
|
33 | + // The calling class name |
|
34 | + 'base_id' => 'hello_world', |
|
35 | + // this is used as the widget id and the shortcode id. |
|
36 | + 'name' => __( 'Hello World', 'ayecode-connect' ), |
|
37 | + // the name of the widget/block |
|
38 | + 'widget_ops' => array( |
|
39 | + 'classname' => 'hello-world-class', |
|
40 | + // widget class |
|
41 | + 'description' => esc_html__( 'This is an example that will take a text parameter and output it after `Hello:`.', 'ayecode-connect' ), |
|
42 | + // widget description |
|
43 | + ), |
|
44 | + 'no_wrap' => true, // This will prevent the widget being wrapped in the containing widget class div. |
|
45 | + 'arguments' => array( // these are the arguments that will be used in the widget, shortcode and block settings. |
|
46 | + 'after_text' => array( // this is the input name='' |
|
47 | + 'title' => __( 'Text after hello:', 'ayecode-connect' ), |
|
48 | + // input title |
|
49 | + 'desc' => __( 'This is the text that will appear after `Hello:`.', 'ayecode-connect' ), |
|
50 | + // input description |
|
51 | + 'type' => 'text', |
|
52 | + // the type of input, test, select, checkbox etc. |
|
53 | + 'placeholder' => 'World', |
|
54 | + // the input placeholder text. |
|
55 | + 'desc_tip' => true, |
|
56 | + // if the input should show the widget description text as a tooltip. |
|
57 | + 'default' => 'World', |
|
58 | + // the input default value. |
|
59 | + 'advanced' => false |
|
60 | + // not yet implemented |
|
61 | + ), |
|
62 | + ) |
|
63 | + ); |
|
64 | + |
|
65 | + parent::__construct( $options ); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * This is the output function for the widget, shortcode and block (front end). |
|
71 | + * |
|
72 | + * @param array $args The arguments values. |
|
73 | + * @param array $widget_args The widget arguments when used. |
|
74 | + * @param string $content The shortcode content argument |
|
75 | + * |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
79 | + |
|
80 | + /** |
|
81 | + * @var string $after_text |
|
82 | + * @var string $another_input This is added by filter below. |
|
83 | + */ |
|
84 | + extract( $args, EXTR_SKIP ); |
|
85 | + |
|
86 | + /* |
|
87 | 87 | * This value is added by filter so might not exist if filter is removed so we check. |
88 | 88 | */ |
89 | - if ( ! isset( $another_input ) ) { |
|
90 | - $another_input = ''; |
|
91 | - } |
|
89 | + if ( ! isset( $another_input ) ) { |
|
90 | + $another_input = ''; |
|
91 | + } |
|
92 | 92 | |
93 | - return "Hello: " . $after_text . "" . $another_input; |
|
93 | + return "Hello: " . $after_text . "" . $another_input; |
|
94 | 94 | |
95 | - } |
|
95 | + } |
|
96 | 96 | |
97 | 97 | } |
98 | 98 | |
99 | 99 | // register it. |
100 | 100 | add_action( 'widgets_init', function () { |
101 | - register_widget( 'SD_Hello_World' ); |
|
101 | + register_widget( 'SD_Hello_World' ); |
|
102 | 102 | } ); |
103 | 103 | |
104 | 104 | |
@@ -111,26 +111,26 @@ discard block |
||
111 | 111 | */ |
112 | 112 | function _my_extra_arguments( $options ) { |
113 | 113 | |
114 | - /* |
|
114 | + /* |
|
115 | 115 | * Add a new input option. |
116 | 116 | */ |
117 | - $options['arguments']['another_input'] = array( |
|
118 | - 'name' => 'another_input', // this is the input name='' |
|
119 | - 'title' => __( 'Another input:', 'ayecode-connect' ), // input title |
|
120 | - 'desc' => __( 'This is an input added via filter.', 'ayecode-connect' ), // input description |
|
121 | - 'type' => 'text', // the type of input, test, select, checkbox etc. |
|
122 | - 'placeholder' => 'Placeholder text', // the input placeholder text. |
|
123 | - 'desc_tip' => true, // if the input should show the widget description text as a tooltip. |
|
124 | - 'default' => '', // the input default value. |
|
125 | - 'advanced' => false // not yet implemented |
|
126 | - ); |
|
127 | - |
|
128 | - /* |
|
117 | + $options['arguments']['another_input'] = array( |
|
118 | + 'name' => 'another_input', // this is the input name='' |
|
119 | + 'title' => __( 'Another input:', 'ayecode-connect' ), // input title |
|
120 | + 'desc' => __( 'This is an input added via filter.', 'ayecode-connect' ), // input description |
|
121 | + 'type' => 'text', // the type of input, test, select, checkbox etc. |
|
122 | + 'placeholder' => 'Placeholder text', // the input placeholder text. |
|
123 | + 'desc_tip' => true, // if the input should show the widget description text as a tooltip. |
|
124 | + 'default' => '', // the input default value. |
|
125 | + 'advanced' => false // not yet implemented |
|
126 | + ); |
|
127 | + |
|
128 | + /* |
|
129 | 129 | * Output the new option in the block output also. |
130 | 130 | */ |
131 | - $options['block-output']['element::p']['content'] = $options['block-output']['element::p']['content'] . " [%another_input%]";; |
|
131 | + $options['block-output']['element::p']['content'] = $options['block-output']['element::p']['content'] . " [%another_input%]";; |
|
132 | 132 | |
133 | - return $options; |
|
133 | + return $options; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | //add_filter( 'wp_super_duper_options_hello_world', '_my_extra_arguments' ); |
137 | 137 | \ No newline at end of file |
@@ -3,241 +3,241 @@ |
||
3 | 3 | class SD_Map extends WP_Super_Duper { |
4 | 4 | |
5 | 5 | |
6 | - public $arguments; |
|
7 | - |
|
8 | - /** |
|
9 | - * Sets up the widgets name etc |
|
10 | - */ |
|
11 | - public function __construct() { |
|
12 | - |
|
13 | - $options = array( |
|
14 | - 'textdomain' => 'super-duper', |
|
15 | - // textdomain of the plugin/theme (used to prefix the Gutenberg block) |
|
16 | - 'block-icon' => 'admin-site', |
|
17 | - // Dash icon name for the block: https://developer.wordpress.org/resource/dashicons/#arrow-right |
|
18 | - 'block-category' => 'widgets', |
|
19 | - // the category for the block, 'common', 'formatting', 'layout', 'widgets', 'embed'. |
|
20 | - 'block-keywords' => "['map','super','google']", |
|
21 | - // used in the block search, MAX 3 |
|
22 | - 'block-output' => array( // the block visual output elements as an array |
|
23 | - array( |
|
24 | - 'element' => 'p', |
|
25 | - 'content' => __('A Google API key is required to use this block, we recommend installing our plugin which makes it easy and sets it globally, or you can set a key in the block settings sidebar: ', 'ayecode-connect' ), |
|
26 | - //'element_require' => '"1"=='.get_option( 'rgmk_google_map_api_key', '"0"') ? '"0"' : '"1"', |
|
27 | - 'element_require' => get_option( 'rgmk_google_map_api_key', false) ? '1==0' : '1==1 && [%api_key%]==""', |
|
28 | - ), |
|
29 | - array( |
|
30 | - 'element' => 'a', |
|
31 | - 'content' => __('API KEY for Google Maps', 'ayecode-connect' ), |
|
32 | - 'element_require' => get_option( 'rgmk_google_map_api_key', false) ? '1==0' : '1==1 && [%api_key%]==""', |
|
33 | - 'href' => 'https://wordpress.org/plugins/api-key-for-google-maps/', |
|
34 | - ), |
|
35 | - array( |
|
36 | - 'element' => 'img', |
|
37 | - 'class' => '[%className%]', |
|
38 | - //'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%] |
|
39 | - 'element_require' => '[%type%]=="image"', |
|
40 | - 'src' => get_option( 'rgmk_google_map_api_key', false) ? "https://maps.googleapis.com/maps/api/staticmap?center=[%location%]&maptype=[%maptype%]&zoom=[%zoom%]&size=[%static_width%]x[%static_height%]&key=".get_option( 'rgmk_google_map_api_key') : "https://maps.googleapis.com/maps/api/staticmap?center=[%location%]&maptype=[%maptype%]&zoom=[%zoom%]&size=[%static_width%]x[%static_height%]&key=[%api_key%]" |
|
41 | - ), |
|
42 | - array( |
|
43 | - 'element' => 'div', |
|
44 | - 'class' => 'sd-map-iframe-cover', |
|
45 | - 'style' => '{overflow:"hidden", position:"relative"}', |
|
46 | - array( |
|
47 | - 'element' => 'iframe', |
|
48 | - 'title' => __( 'Placeholderx', 'ayecode-connect' ), |
|
49 | - 'class' => '[%className%]', |
|
50 | - 'width' => '[%width%]', |
|
51 | - 'height' => '[%height%]', |
|
52 | - 'frameborder' => '0', |
|
53 | - 'allowfullscreen' => 'true', |
|
54 | - 'style' => '{border:0}', |
|
55 | - 'element_require' => '[%type%]!="image"', |
|
56 | - 'src' => get_option( 'rgmk_google_map_api_key', false) ? "https://www.google.com/maps/embed/v1/[%type%]?q=[%location%]&maptype=[%maptype%]&zoom=[%zoom%]&key=".get_option( 'rgmk_google_map_api_key') : "https://www.google.com/maps/embed/v1/[%type%]?q=[%location%]&maptype=[%maptype%]&zoom=[%zoom%]&key=[%api_key%]" |
|
57 | - ), |
|
58 | - ), |
|
59 | - array( |
|
60 | - 'element' => 'style', |
|
61 | - 'content' => '.sd-map-iframe-cover:hover:before {background: #4a4a4a88; content: "'.__( 'Click here, Settings are in the block settings sidebar', 'ayecode-connect' ).'";} .sd-map-iframe-cover:before{cursor: pointer; content: ""; width: 100%; height: 100%; position: absolute; top: 0; bottom: 0;padding-top: 33%; text-align: center; color: #fff; font-size: 20px; font-weight: bold;}', |
|
62 | - 'element_require' => '[%type%]!="image"', |
|
63 | - ), |
|
64 | - ), |
|
65 | - 'class_name' => __CLASS__, |
|
66 | - // The calling class name |
|
67 | - 'base_id' => 'sd_map', |
|
68 | - // this is used as the widget id and the shortcode id. |
|
69 | - 'name' => __( 'Map', 'ayecode-connect' ), |
|
70 | - // the name of the widget/block |
|
71 | - 'widget_ops' => array( |
|
72 | - 'classname' => 'sd-map-class', |
|
73 | - // widget class |
|
74 | - 'description' => esc_html__( 'This is an example that will take a text parameter and output it after `Hello:`.', 'ayecode-connect' ), |
|
75 | - // widget description |
|
76 | - ), |
|
77 | - 'arguments' => array( // these are the arguments that will be used in the widget, shortcode and block settings. |
|
78 | - 'type' => array( |
|
79 | - 'title' => __('Map Type:', 'ayecode-connect'), |
|
80 | - 'desc' => __('Select the map type to use.', 'ayecode-connect'), |
|
81 | - 'type' => 'select', |
|
82 | - 'options' => array( |
|
83 | - "image" => __('Static Image', 'ayecode-connect'), |
|
84 | - "place" => __('Place', 'ayecode-connect'), |
|
6 | + public $arguments; |
|
7 | + |
|
8 | + /** |
|
9 | + * Sets up the widgets name etc |
|
10 | + */ |
|
11 | + public function __construct() { |
|
12 | + |
|
13 | + $options = array( |
|
14 | + 'textdomain' => 'super-duper', |
|
15 | + // textdomain of the plugin/theme (used to prefix the Gutenberg block) |
|
16 | + 'block-icon' => 'admin-site', |
|
17 | + // Dash icon name for the block: https://developer.wordpress.org/resource/dashicons/#arrow-right |
|
18 | + 'block-category' => 'widgets', |
|
19 | + // the category for the block, 'common', 'formatting', 'layout', 'widgets', 'embed'. |
|
20 | + 'block-keywords' => "['map','super','google']", |
|
21 | + // used in the block search, MAX 3 |
|
22 | + 'block-output' => array( // the block visual output elements as an array |
|
23 | + array( |
|
24 | + 'element' => 'p', |
|
25 | + 'content' => __('A Google API key is required to use this block, we recommend installing our plugin which makes it easy and sets it globally, or you can set a key in the block settings sidebar: ', 'ayecode-connect' ), |
|
26 | + //'element_require' => '"1"=='.get_option( 'rgmk_google_map_api_key', '"0"') ? '"0"' : '"1"', |
|
27 | + 'element_require' => get_option( 'rgmk_google_map_api_key', false) ? '1==0' : '1==1 && [%api_key%]==""', |
|
28 | + ), |
|
29 | + array( |
|
30 | + 'element' => 'a', |
|
31 | + 'content' => __('API KEY for Google Maps', 'ayecode-connect' ), |
|
32 | + 'element_require' => get_option( 'rgmk_google_map_api_key', false) ? '1==0' : '1==1 && [%api_key%]==""', |
|
33 | + 'href' => 'https://wordpress.org/plugins/api-key-for-google-maps/', |
|
34 | + ), |
|
35 | + array( |
|
36 | + 'element' => 'img', |
|
37 | + 'class' => '[%className%]', |
|
38 | + //'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%] |
|
39 | + 'element_require' => '[%type%]=="image"', |
|
40 | + 'src' => get_option( 'rgmk_google_map_api_key', false) ? "https://maps.googleapis.com/maps/api/staticmap?center=[%location%]&maptype=[%maptype%]&zoom=[%zoom%]&size=[%static_width%]x[%static_height%]&key=".get_option( 'rgmk_google_map_api_key') : "https://maps.googleapis.com/maps/api/staticmap?center=[%location%]&maptype=[%maptype%]&zoom=[%zoom%]&size=[%static_width%]x[%static_height%]&key=[%api_key%]" |
|
41 | + ), |
|
42 | + array( |
|
43 | + 'element' => 'div', |
|
44 | + 'class' => 'sd-map-iframe-cover', |
|
45 | + 'style' => '{overflow:"hidden", position:"relative"}', |
|
46 | + array( |
|
47 | + 'element' => 'iframe', |
|
48 | + 'title' => __( 'Placeholderx', 'ayecode-connect' ), |
|
49 | + 'class' => '[%className%]', |
|
50 | + 'width' => '[%width%]', |
|
51 | + 'height' => '[%height%]', |
|
52 | + 'frameborder' => '0', |
|
53 | + 'allowfullscreen' => 'true', |
|
54 | + 'style' => '{border:0}', |
|
55 | + 'element_require' => '[%type%]!="image"', |
|
56 | + 'src' => get_option( 'rgmk_google_map_api_key', false) ? "https://www.google.com/maps/embed/v1/[%type%]?q=[%location%]&maptype=[%maptype%]&zoom=[%zoom%]&key=".get_option( 'rgmk_google_map_api_key') : "https://www.google.com/maps/embed/v1/[%type%]?q=[%location%]&maptype=[%maptype%]&zoom=[%zoom%]&key=[%api_key%]" |
|
57 | + ), |
|
58 | + ), |
|
59 | + array( |
|
60 | + 'element' => 'style', |
|
61 | + 'content' => '.sd-map-iframe-cover:hover:before {background: #4a4a4a88; content: "'.__( 'Click here, Settings are in the block settings sidebar', 'ayecode-connect' ).'";} .sd-map-iframe-cover:before{cursor: pointer; content: ""; width: 100%; height: 100%; position: absolute; top: 0; bottom: 0;padding-top: 33%; text-align: center; color: #fff; font-size: 20px; font-weight: bold;}', |
|
62 | + 'element_require' => '[%type%]!="image"', |
|
63 | + ), |
|
64 | + ), |
|
65 | + 'class_name' => __CLASS__, |
|
66 | + // The calling class name |
|
67 | + 'base_id' => 'sd_map', |
|
68 | + // this is used as the widget id and the shortcode id. |
|
69 | + 'name' => __( 'Map', 'ayecode-connect' ), |
|
70 | + // the name of the widget/block |
|
71 | + 'widget_ops' => array( |
|
72 | + 'classname' => 'sd-map-class', |
|
73 | + // widget class |
|
74 | + 'description' => esc_html__( 'This is an example that will take a text parameter and output it after `Hello:`.', 'ayecode-connect' ), |
|
75 | + // widget description |
|
76 | + ), |
|
77 | + 'arguments' => array( // these are the arguments that will be used in the widget, shortcode and block settings. |
|
78 | + 'type' => array( |
|
79 | + 'title' => __('Map Type:', 'ayecode-connect'), |
|
80 | + 'desc' => __('Select the map type to use.', 'ayecode-connect'), |
|
81 | + 'type' => 'select', |
|
82 | + 'options' => array( |
|
83 | + "image" => __('Static Image', 'ayecode-connect'), |
|
84 | + "place" => __('Place', 'ayecode-connect'), |
|
85 | 85 | // "directions" => __('Directions', 'ayecode-connect'), |
86 | 86 | // "search" => __('Search', 'ayecode-connect'), |
87 | 87 | // "view" => __('View', 'ayecode-connect'), |
88 | 88 | // "streetview" => __('Streetview', 'ayecode-connect'), |
89 | - ), |
|
90 | - 'default' => 'image', |
|
91 | - 'desc_tip' => true, |
|
92 | - 'advanced' => false |
|
93 | - ), |
|
94 | - 'location' => array( |
|
95 | - 'type' => 'text', |
|
96 | - 'title' => __( 'Location:', 'ayecode-connect' ), |
|
97 | - 'desc' => __( 'Enter the location to show on the map, place, city, zip code or GPS.', 'ayecode-connect' ), |
|
98 | - 'placeholder' => 'Place, city, zip code or GPS', |
|
99 | - 'desc_tip' => true, |
|
100 | - 'default' => 'Ireland', |
|
101 | - 'advanced' => false |
|
102 | - ), |
|
103 | - 'static_width' => array( |
|
104 | - 'type' => 'number', |
|
105 | - 'title' => __( 'Width:', 'ayecode-connect' ), |
|
106 | - 'desc' => __( 'This is the width of the map, for static maps you can only use px values.', 'ayecode-connect' ), |
|
107 | - 'placeholder' => '600', |
|
108 | - 'desc_tip' => true, |
|
109 | - 'default' => '600', |
|
110 | - 'custom_attributes' => array( |
|
111 | - 'max' => '2000', |
|
112 | - 'min' => '100', |
|
113 | - ), |
|
114 | - 'element_require' => '[%type%]=="image"', |
|
115 | - 'advanced' => false |
|
116 | - ), |
|
117 | - 'static_height' => array( |
|
118 | - 'type' => 'number', |
|
119 | - 'title' => __( 'Height:', 'ayecode-connect' ), |
|
120 | - 'desc' => __( 'This is the height of the map, for static maps you can only use px values.', 'ayecode-connect' ), |
|
121 | - 'placeholder' => '400', |
|
122 | - 'desc_tip' => true, |
|
123 | - 'default' => '400', |
|
124 | - 'custom_attributes' => array( |
|
125 | - 'max' => '2000', |
|
126 | - 'min' => '100', |
|
127 | - 'required' => 'required', |
|
128 | - ), |
|
129 | - 'element_require' => '[%type%]=="image"', |
|
130 | - 'advanced' => false |
|
131 | - ), |
|
132 | - 'width' => array( |
|
133 | - 'type' => 'text', |
|
134 | - 'title' => __( 'Width:', 'ayecode-connect' ), |
|
135 | - 'desc' => __( 'This is the width of the map, you can use % or px here.', 'ayecode-connect' ), |
|
136 | - 'placeholder' => '100%', |
|
137 | - 'desc_tip' => true, |
|
138 | - 'default' => '100%', |
|
139 | - 'element_require' => '[%type%]!="image"', |
|
140 | - 'advanced' => false |
|
141 | - ), |
|
142 | - 'height' => array( |
|
143 | - 'type' => 'text', |
|
144 | - 'title' => __( 'Height:', 'ayecode-connect' ), |
|
145 | - 'desc' => __( 'This is the height of the map, you can use %, px or vh here.', 'ayecode-connect' ), |
|
146 | - 'placeholder' => '425px', |
|
147 | - 'desc_tip' => true, |
|
148 | - 'default' => '425px', |
|
149 | - 'element_require' => '[%type%]!="image"', |
|
150 | - 'advanced' => false |
|
151 | - ), |
|
152 | - 'maptype' => array( |
|
153 | - 'type' => 'select', |
|
154 | - 'title' => __( 'Mapview:', 'ayecode-connect' ), |
|
155 | - 'desc' => __( 'This is the type of map view that will be used by default.', 'ayecode-connect' ), |
|
156 | - 'options' => array( |
|
157 | - "roadmap" => __( 'Road Map', 'ayecode-connect' ), |
|
158 | - "satellite" => __( 'Satellite Map', 'ayecode-connect' ), |
|
89 | + ), |
|
90 | + 'default' => 'image', |
|
91 | + 'desc_tip' => true, |
|
92 | + 'advanced' => false |
|
93 | + ), |
|
94 | + 'location' => array( |
|
95 | + 'type' => 'text', |
|
96 | + 'title' => __( 'Location:', 'ayecode-connect' ), |
|
97 | + 'desc' => __( 'Enter the location to show on the map, place, city, zip code or GPS.', 'ayecode-connect' ), |
|
98 | + 'placeholder' => 'Place, city, zip code or GPS', |
|
99 | + 'desc_tip' => true, |
|
100 | + 'default' => 'Ireland', |
|
101 | + 'advanced' => false |
|
102 | + ), |
|
103 | + 'static_width' => array( |
|
104 | + 'type' => 'number', |
|
105 | + 'title' => __( 'Width:', 'ayecode-connect' ), |
|
106 | + 'desc' => __( 'This is the width of the map, for static maps you can only use px values.', 'ayecode-connect' ), |
|
107 | + 'placeholder' => '600', |
|
108 | + 'desc_tip' => true, |
|
109 | + 'default' => '600', |
|
110 | + 'custom_attributes' => array( |
|
111 | + 'max' => '2000', |
|
112 | + 'min' => '100', |
|
113 | + ), |
|
114 | + 'element_require' => '[%type%]=="image"', |
|
115 | + 'advanced' => false |
|
116 | + ), |
|
117 | + 'static_height' => array( |
|
118 | + 'type' => 'number', |
|
119 | + 'title' => __( 'Height:', 'ayecode-connect' ), |
|
120 | + 'desc' => __( 'This is the height of the map, for static maps you can only use px values.', 'ayecode-connect' ), |
|
121 | + 'placeholder' => '400', |
|
122 | + 'desc_tip' => true, |
|
123 | + 'default' => '400', |
|
124 | + 'custom_attributes' => array( |
|
125 | + 'max' => '2000', |
|
126 | + 'min' => '100', |
|
127 | + 'required' => 'required', |
|
128 | + ), |
|
129 | + 'element_require' => '[%type%]=="image"', |
|
130 | + 'advanced' => false |
|
131 | + ), |
|
132 | + 'width' => array( |
|
133 | + 'type' => 'text', |
|
134 | + 'title' => __( 'Width:', 'ayecode-connect' ), |
|
135 | + 'desc' => __( 'This is the width of the map, you can use % or px here.', 'ayecode-connect' ), |
|
136 | + 'placeholder' => '100%', |
|
137 | + 'desc_tip' => true, |
|
138 | + 'default' => '100%', |
|
139 | + 'element_require' => '[%type%]!="image"', |
|
140 | + 'advanced' => false |
|
141 | + ), |
|
142 | + 'height' => array( |
|
143 | + 'type' => 'text', |
|
144 | + 'title' => __( 'Height:', 'ayecode-connect' ), |
|
145 | + 'desc' => __( 'This is the height of the map, you can use %, px or vh here.', 'ayecode-connect' ), |
|
146 | + 'placeholder' => '425px', |
|
147 | + 'desc_tip' => true, |
|
148 | + 'default' => '425px', |
|
149 | + 'element_require' => '[%type%]!="image"', |
|
150 | + 'advanced' => false |
|
151 | + ), |
|
152 | + 'maptype' => array( |
|
153 | + 'type' => 'select', |
|
154 | + 'title' => __( 'Mapview:', 'ayecode-connect' ), |
|
155 | + 'desc' => __( 'This is the type of map view that will be used by default.', 'ayecode-connect' ), |
|
156 | + 'options' => array( |
|
157 | + "roadmap" => __( 'Road Map', 'ayecode-connect' ), |
|
158 | + "satellite" => __( 'Satellite Map', 'ayecode-connect' ), |
|
159 | 159 | // "hybrid" => __( 'Hybrid Map', 'ayecode-connect' ), |
160 | 160 | // "terrain" => __( 'Terrain Map', 'ayecode-connect' ), |
161 | - ), |
|
162 | - 'desc_tip' => true, |
|
163 | - 'default' => 'roadmap', |
|
164 | - 'advanced' => true |
|
165 | - ), |
|
166 | - 'zoom' => array( |
|
167 | - 'type' => 'select', |
|
168 | - 'title' => __( 'Zoom level:', 'ayecode-connect' ), |
|
169 | - 'desc' => __( 'This is the zoom level of the map, `auto` is recommended.', 'ayecode-connect' ), |
|
170 | - 'options' => range( 1, 19 ), |
|
171 | - 'placeholder' => '', |
|
172 | - 'desc_tip' => true, |
|
173 | - 'default' => '7', |
|
174 | - 'advanced' => true |
|
175 | - ), |
|
176 | - 'api_key' => array( |
|
177 | - 'type' => 'text', |
|
178 | - 'title' => __( 'Api Key:', 'ayecode-connect' ), |
|
179 | - 'desc' => __( 'This is the height of the map, you can use %, px or vh here.', 'ayecode-connect' ), |
|
180 | - 'placeholder' => '', |
|
181 | - 'desc_tip' => true, |
|
182 | - 'default' => '', |
|
183 | - 'element_require' => get_option( 'rgmk_google_map_api_key', false) ? '1==0' : '1==1', |
|
184 | - 'advanced' => false |
|
185 | - ), |
|
186 | - ) |
|
187 | - ); |
|
188 | - |
|
189 | - parent::__construct( $options ); |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * This is the output function for the widget, shortcode and block (front end). |
|
195 | - * |
|
196 | - * @param array $args The arguments values. |
|
197 | - * @param array $widget_args The widget arguments when used. |
|
198 | - * @param string $content The shortcode content argument |
|
199 | - * |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
203 | - |
|
204 | - // options |
|
205 | - $defaults = array( |
|
206 | - 'type' => 'image', // image, place |
|
207 | - 'location' => 'Ireland', |
|
208 | - 'static_width' => '600', |
|
209 | - 'static_height' => '400', |
|
210 | - 'width'=> '100%', |
|
211 | - 'height'=> '425px', |
|
212 | - 'maptype' => 'roadmap', |
|
213 | - 'zoom' => '7', |
|
214 | - 'api_key' => 'AIzaSyBK3ZcmK0ljxl5agNyJNQh_G24Thq1btuE', |
|
215 | - ); |
|
216 | - |
|
217 | - /** |
|
218 | - * Parse incoming $args into an array and merge it with $defaults |
|
219 | - */ |
|
220 | - $args = wp_parse_args($args, $defaults ); |
|
221 | - |
|
222 | - $output = ''; |
|
223 | - |
|
224 | - |
|
225 | - // check if we have a global API key |
|
226 | - $args['api_key'] = get_option( 'rgmk_google_map_api_key', false ) ? get_option( 'rgmk_google_map_api_key' ) : $args['api_key']; |
|
227 | - |
|
228 | - if($args['type']=='image'){ |
|
229 | - $output .= "<img src='https://maps.googleapis.com/maps/api/staticmap?center=".esc_attr($args['location'])."&maptype=".esc_attr($args['maptype'])."&zoom=".esc_attr($args['zoom'])."&size=".esc_attr($args['static_width'])."x".esc_attr($args['static_height'])."&key=".esc_attr($args['api_key'])."' />"; |
|
230 | - }else{ |
|
231 | - $output .= "<iframe width='".esc_attr($args['width'])."' height='".esc_attr($args['height'])."' frameborder='0' allowfullscreen style='border:0;' src='https://www.google.com/maps/embed/v1/".esc_attr($args['type'])."?q=".esc_attr($args['location'])."&maptype=".esc_attr($args['maptype'])."&zoom=".esc_attr($args['zoom'])."&key=".esc_attr($args['api_key'])."' ></iframe> "; |
|
232 | - } |
|
233 | - |
|
234 | - return $output; |
|
235 | - |
|
236 | - } |
|
161 | + ), |
|
162 | + 'desc_tip' => true, |
|
163 | + 'default' => 'roadmap', |
|
164 | + 'advanced' => true |
|
165 | + ), |
|
166 | + 'zoom' => array( |
|
167 | + 'type' => 'select', |
|
168 | + 'title' => __( 'Zoom level:', 'ayecode-connect' ), |
|
169 | + 'desc' => __( 'This is the zoom level of the map, `auto` is recommended.', 'ayecode-connect' ), |
|
170 | + 'options' => range( 1, 19 ), |
|
171 | + 'placeholder' => '', |
|
172 | + 'desc_tip' => true, |
|
173 | + 'default' => '7', |
|
174 | + 'advanced' => true |
|
175 | + ), |
|
176 | + 'api_key' => array( |
|
177 | + 'type' => 'text', |
|
178 | + 'title' => __( 'Api Key:', 'ayecode-connect' ), |
|
179 | + 'desc' => __( 'This is the height of the map, you can use %, px or vh here.', 'ayecode-connect' ), |
|
180 | + 'placeholder' => '', |
|
181 | + 'desc_tip' => true, |
|
182 | + 'default' => '', |
|
183 | + 'element_require' => get_option( 'rgmk_google_map_api_key', false) ? '1==0' : '1==1', |
|
184 | + 'advanced' => false |
|
185 | + ), |
|
186 | + ) |
|
187 | + ); |
|
188 | + |
|
189 | + parent::__construct( $options ); |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * This is the output function for the widget, shortcode and block (front end). |
|
195 | + * |
|
196 | + * @param array $args The arguments values. |
|
197 | + * @param array $widget_args The widget arguments when used. |
|
198 | + * @param string $content The shortcode content argument |
|
199 | + * |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
203 | + |
|
204 | + // options |
|
205 | + $defaults = array( |
|
206 | + 'type' => 'image', // image, place |
|
207 | + 'location' => 'Ireland', |
|
208 | + 'static_width' => '600', |
|
209 | + 'static_height' => '400', |
|
210 | + 'width'=> '100%', |
|
211 | + 'height'=> '425px', |
|
212 | + 'maptype' => 'roadmap', |
|
213 | + 'zoom' => '7', |
|
214 | + 'api_key' => 'AIzaSyBK3ZcmK0ljxl5agNyJNQh_G24Thq1btuE', |
|
215 | + ); |
|
216 | + |
|
217 | + /** |
|
218 | + * Parse incoming $args into an array and merge it with $defaults |
|
219 | + */ |
|
220 | + $args = wp_parse_args($args, $defaults ); |
|
221 | + |
|
222 | + $output = ''; |
|
223 | + |
|
224 | + |
|
225 | + // check if we have a global API key |
|
226 | + $args['api_key'] = get_option( 'rgmk_google_map_api_key', false ) ? get_option( 'rgmk_google_map_api_key' ) : $args['api_key']; |
|
227 | + |
|
228 | + if($args['type']=='image'){ |
|
229 | + $output .= "<img src='https://maps.googleapis.com/maps/api/staticmap?center=".esc_attr($args['location'])."&maptype=".esc_attr($args['maptype'])."&zoom=".esc_attr($args['zoom'])."&size=".esc_attr($args['static_width'])."x".esc_attr($args['static_height'])."&key=".esc_attr($args['api_key'])."' />"; |
|
230 | + }else{ |
|
231 | + $output .= "<iframe width='".esc_attr($args['width'])."' height='".esc_attr($args['height'])."' frameborder='0' allowfullscreen style='border:0;' src='https://www.google.com/maps/embed/v1/".esc_attr($args['type'])."?q=".esc_attr($args['location'])."&maptype=".esc_attr($args['maptype'])."&zoom=".esc_attr($args['zoom'])."&key=".esc_attr($args['api_key'])."' ></iframe> "; |
|
232 | + } |
|
233 | + |
|
234 | + return $output; |
|
235 | + |
|
236 | + } |
|
237 | 237 | |
238 | 238 | } |
239 | 239 | |
240 | 240 | // register it. |
241 | 241 | add_action( 'widgets_init', function () { |
242 | - register_widget( 'SD_Map' ); |
|
242 | + register_widget( 'SD_Map' ); |
|
243 | 243 | } ); |
@@ -12,185 +12,185 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Checkout { |
14 | 14 | |
15 | - /** |
|
16 | - * @var GetPaid_Payment_Form_Submission |
|
17 | - */ |
|
18 | - protected $payment_form_submission; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - * @param GetPaid_Payment_Form_Submission $submission |
|
24 | - */ |
|
25 | - public function __construct( $submission ) { |
|
26 | - $this->payment_form_submission = $submission; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Processes the checkout. |
|
31 | - * |
|
32 | - */ |
|
33 | - public function process_checkout() { |
|
34 | - |
|
35 | - // Validate the submission. |
|
36 | - $this->validate_submission(); |
|
37 | - |
|
38 | - // Prepare the invoice. |
|
39 | - $items = $this->get_submission_items(); |
|
40 | - $invoice = $this->get_submission_invoice(); |
|
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | - $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | - |
|
44 | - $this->prepare_billing_info( $invoice ); |
|
45 | - |
|
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | - |
|
48 | - // Save the invoice. |
|
49 | - $invoice->set_is_viewed( true ); |
|
50 | - $invoice->recalculate_total(); |
|
15 | + /** |
|
16 | + * @var GetPaid_Payment_Form_Submission |
|
17 | + */ |
|
18 | + protected $payment_form_submission; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + * @param GetPaid_Payment_Form_Submission $submission |
|
24 | + */ |
|
25 | + public function __construct( $submission ) { |
|
26 | + $this->payment_form_submission = $submission; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Processes the checkout. |
|
31 | + * |
|
32 | + */ |
|
33 | + public function process_checkout() { |
|
34 | + |
|
35 | + // Validate the submission. |
|
36 | + $this->validate_submission(); |
|
37 | + |
|
38 | + // Prepare the invoice. |
|
39 | + $items = $this->get_submission_items(); |
|
40 | + $invoice = $this->get_submission_invoice(); |
|
41 | + $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | + $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | + |
|
44 | + $this->prepare_billing_info( $invoice ); |
|
45 | + |
|
46 | + $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | + |
|
48 | + // Save the invoice. |
|
49 | + $invoice->set_is_viewed( true ); |
|
50 | + $invoice->recalculate_total(); |
|
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
54 | 54 | |
55 | - // Send to the gateway. |
|
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | - } |
|
55 | + // Send to the gateway. |
|
56 | + $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Validates the submission. |
|
61 | - * |
|
62 | - */ |
|
63 | - protected function validate_submission() { |
|
59 | + /** |
|
60 | + * Validates the submission. |
|
61 | + * |
|
62 | + */ |
|
63 | + protected function validate_submission() { |
|
64 | 64 | |
65 | - $submission = $this->payment_form_submission; |
|
66 | - $data = $submission->get_data(); |
|
65 | + $submission = $this->payment_form_submission; |
|
66 | + $data = $submission->get_data(); |
|
67 | 67 | |
68 | - // Do we have an error? |
|
68 | + // Do we have an error? |
|
69 | 69 | if ( ! empty( $submission->last_error ) ) { |
70 | - wp_send_json_error( $submission->last_error ); |
|
70 | + wp_send_json_error( $submission->last_error ); |
|
71 | 71 | } |
72 | 72 | |
73 | - // We need a billing email. |
|
73 | + // We need a billing email. |
|
74 | 74 | if ( ! $submission->has_billing_email() ) { |
75 | 75 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | - } |
|
78 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | + if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | + } |
|
82 | 82 | |
83 | - // Ensure the gateway is active. |
|
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | - } |
|
83 | + // Ensure the gateway is active. |
|
84 | + if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | + wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | + } |
|
87 | 87 | |
88 | - // Clear any existing errors. |
|
89 | - wpinv_clear_errors(); |
|
88 | + // Clear any existing errors. |
|
89 | + wpinv_clear_errors(); |
|
90 | 90 | |
91 | - // Allow themes and plugins to hook to errors |
|
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
91 | + // Allow themes and plugins to hook to errors |
|
92 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
93 | 93 | |
94 | - // Do we have any errors? |
|
94 | + // Do we have any errors? |
|
95 | 95 | if ( wpinv_get_errors() ) { |
96 | 96 | wp_send_json_error( getpaid_get_errors_html() ); |
97 | - } |
|
97 | + } |
|
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Retrieves submission items. |
|
103 | - * |
|
104 | - * @return GetPaid_Form_Item[] |
|
105 | - */ |
|
106 | - protected function get_submission_items() { |
|
101 | + /** |
|
102 | + * Retrieves submission items. |
|
103 | + * |
|
104 | + * @return GetPaid_Form_Item[] |
|
105 | + */ |
|
106 | + protected function get_submission_items() { |
|
107 | 107 | |
108 | - $items = $this->payment_form_submission->get_items(); |
|
108 | + $items = $this->payment_form_submission->get_items(); |
|
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | 111 | if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
112 | 112 | wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
113 | - } |
|
114 | - |
|
115 | - return $items; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Retrieves submission invoice. |
|
120 | - * |
|
121 | - * @return WPInv_Invoice |
|
122 | - */ |
|
123 | - protected function get_submission_invoice() { |
|
124 | - $submission = $this->payment_form_submission; |
|
125 | - |
|
126 | - if ( ! $submission->has_invoice() ) { |
|
127 | - $invoice = new WPInv_Invoice(); |
|
128 | - $invoice->set_created_via( 'payment_form' ); |
|
129 | - return $invoice; |
|
130 | 113 | } |
131 | 114 | |
132 | - $invoice = $submission->get_invoice(); |
|
115 | + return $items; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Retrieves submission invoice. |
|
120 | + * |
|
121 | + * @return WPInv_Invoice |
|
122 | + */ |
|
123 | + protected function get_submission_invoice() { |
|
124 | + $submission = $this->payment_form_submission; |
|
133 | 125 | |
134 | - // Make sure that it is neither paid or refunded. |
|
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | - } |
|
126 | + if ( ! $submission->has_invoice() ) { |
|
127 | + $invoice = new WPInv_Invoice(); |
|
128 | + $invoice->set_created_via( 'payment_form' ); |
|
129 | + return $invoice; |
|
130 | + } |
|
138 | 131 | |
139 | - return $invoice; |
|
140 | - } |
|
132 | + $invoice = $submission->get_invoice(); |
|
141 | 133 | |
142 | - /** |
|
143 | - * Processes the submission invoice. |
|
144 | - * |
|
145 | - * @param WPInv_Invoice $invoice |
|
146 | - * @param GetPaid_Form_Item[] $items |
|
147 | - * @return WPInv_Invoice |
|
148 | - */ |
|
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
134 | + // Make sure that it is neither paid or refunded. |
|
135 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | + } |
|
150 | 138 | |
151 | - $submission = $this->payment_form_submission; |
|
139 | + return $invoice; |
|
140 | + } |
|
152 | 141 | |
153 | - // Set-up the invoice details. |
|
154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | - $invoice->set_submission_id( $submission->id ); |
|
157 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
142 | + /** |
|
143 | + * Processes the submission invoice. |
|
144 | + * |
|
145 | + * @param WPInv_Invoice $invoice |
|
146 | + * @param GetPaid_Form_Item[] $items |
|
147 | + * @return WPInv_Invoice |
|
148 | + */ |
|
149 | + protected function process_submission_invoice( $invoice, $items ) { |
|
150 | + |
|
151 | + $submission = $this->payment_form_submission; |
|
152 | + |
|
153 | + // Set-up the invoice details. |
|
154 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | + $invoice->set_submission_id( $submission->id ); |
|
157 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
158 | 158 | $invoice->set_items( $items ); |
159 | 159 | $invoice->set_fees( $submission->get_fees() ); |
160 | 160 | $invoice->set_taxes( $submission->get_taxes() ); |
161 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
162 | - $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
163 | - $invoice->set_currency( $submission->get_currency() ); |
|
161 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
162 | + $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
163 | + $invoice->set_currency( $submission->get_currency() ); |
|
164 | 164 | |
165 | - if ( $submission->has_shipping() ) { |
|
166 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
167 | - } |
|
165 | + if ( $submission->has_shipping() ) { |
|
166 | + $invoice->set_shipping( $submission->get_shipping() ); |
|
167 | + } |
|
168 | 168 | |
169 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
170 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
169 | + $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
170 | + $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
171 | 171 | |
172 | - if ( $submission->has_discount_code() ) { |
|
172 | + if ( $submission->has_discount_code() ) { |
|
173 | 173 | $invoice->set_discount_code( $submission->get_discount_code() ); |
174 | - } |
|
175 | - |
|
176 | - getpaid_maybe_add_default_address( $invoice ); |
|
177 | - return $invoice; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Retrieves the submission's customer. |
|
182 | - * |
|
183 | - * @return int The customer id. |
|
184 | - */ |
|
185 | - protected function get_submission_customer() { |
|
186 | - $submission = $this->payment_form_submission; |
|
187 | - |
|
188 | - // If this is an existing invoice... |
|
189 | - if ( $submission->has_invoice() ) { |
|
190 | - return $submission->get_invoice()->get_user_id(); |
|
191 | - } |
|
192 | - |
|
193 | - // (Maybe) create the user. |
|
174 | + } |
|
175 | + |
|
176 | + getpaid_maybe_add_default_address( $invoice ); |
|
177 | + return $invoice; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Retrieves the submission's customer. |
|
182 | + * |
|
183 | + * @return int The customer id. |
|
184 | + */ |
|
185 | + protected function get_submission_customer() { |
|
186 | + $submission = $this->payment_form_submission; |
|
187 | + |
|
188 | + // If this is an existing invoice... |
|
189 | + if ( $submission->has_invoice() ) { |
|
190 | + return $submission->get_invoice()->get_user_id(); |
|
191 | + } |
|
192 | + |
|
193 | + // (Maybe) create the user. |
|
194 | 194 | $user = get_current_user_id(); |
195 | 195 | |
196 | 196 | if ( empty( $user ) ) { |
@@ -198,16 +198,16 @@ discard block |
||
198 | 198 | } |
199 | 199 | |
200 | 200 | if ( empty( $user ) ) { |
201 | - $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
202 | - $name = implode( '', array_filter( $name ) ); |
|
201 | + $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
202 | + $name = implode( '', array_filter( $name ) ); |
|
203 | 203 | $user = wpinv_create_user( $submission->get_billing_email(), $name ); |
204 | 204 | |
205 | - // (Maybe) send new user notification. |
|
206 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
207 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
208 | - wp_send_new_user_notifications( $user, 'user' ); |
|
209 | - } |
|
210 | - } |
|
205 | + // (Maybe) send new user notification. |
|
206 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
207 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
208 | + wp_send_new_user_notifications( $user, 'user' ); |
|
209 | + } |
|
210 | + } |
|
211 | 211 | |
212 | 212 | if ( is_wp_error( $user ) ) { |
213 | 213 | wp_send_json_error( $user->get_error_message() ); |
@@ -215,49 +215,49 @@ discard block |
||
215 | 215 | |
216 | 216 | if ( is_numeric( $user ) ) { |
217 | 217 | return $user; |
218 | - } |
|
218 | + } |
|
219 | 219 | |
220 | - return $user->ID; |
|
220 | + return $user->ID; |
|
221 | 221 | |
222 | - } |
|
222 | + } |
|
223 | 223 | |
224 | - /** |
|
224 | + /** |
|
225 | 225 | * Prepares submission data for saving to the database. |
226 | 226 | * |
227 | - * @return array |
|
227 | + * @return array |
|
228 | 228 | */ |
229 | 229 | public function prepare_submission_data_for_saving() { |
230 | 230 | |
231 | - $submission = $this->payment_form_submission; |
|
231 | + $submission = $this->payment_form_submission; |
|
232 | 232 | |
233 | - // Prepared submission details. |
|
233 | + // Prepared submission details. |
|
234 | 234 | $prepared = array( |
235 | - 'all' => array(), |
|
236 | - 'meta' => array(), |
|
237 | - ); |
|
235 | + 'all' => array(), |
|
236 | + 'meta' => array(), |
|
237 | + ); |
|
238 | 238 | |
239 | 239 | // Raw submission details. |
240 | - $data = $submission->get_data(); |
|
240 | + $data = $submission->get_data(); |
|
241 | 241 | |
242 | - // Loop through the submitted details. |
|
242 | + // Loop through the submitted details. |
|
243 | 243 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
244 | 244 | |
245 | - // Skip premade fields. |
|
245 | + // Skip premade fields. |
|
246 | 246 | if ( ! empty( $field['premade'] ) ) { |
247 | 247 | continue; |
248 | 248 | } |
249 | 249 | |
250 | - // Ensure address is provided. |
|
251 | - if ( 'address' === $field['type'] ) { |
|
250 | + // Ensure address is provided. |
|
251 | + if ( 'address' === $field['type'] ) { |
|
252 | 252 | $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
253 | 253 | |
254 | - foreach ( $field['fields'] as $address_field ) { |
|
254 | + foreach ( $field['fields'] as $address_field ) { |
|
255 | 255 | |
256 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
257 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
258 | - } |
|
259 | - } |
|
260 | - } |
|
256 | + if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
257 | + wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
258 | + } |
|
259 | + } |
|
260 | + } |
|
261 | 261 | |
262 | 262 | // If it is required and not set, abort. |
263 | 263 | if ( ! $submission->is_required_field_set( $field ) ) { |
@@ -267,31 +267,31 @@ discard block |
||
267 | 267 | // Handle misc fields. |
268 | 268 | if ( isset( $data[ $field['id'] ] ) ) { |
269 | 269 | |
270 | - // Uploads. |
|
271 | - if ( 'file_upload' === $field['type'] ) { |
|
272 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
270 | + // Uploads. |
|
271 | + if ( 'file_upload' === $field['type'] ) { |
|
272 | + $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
273 | 273 | |
274 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
275 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
276 | - } |
|
274 | + if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
275 | + wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
276 | + } |
|
277 | 277 | |
278 | - $value = array(); |
|
278 | + $value = array(); |
|
279 | 279 | |
280 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
281 | - $value[] = sprintf( |
|
282 | - '<a href="%s" target="_blank">%s</a>', |
|
283 | - esc_url_raw( $url ), |
|
284 | - esc_html( $name ) |
|
285 | - ); |
|
286 | - } |
|
280 | + foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
281 | + $value[] = sprintf( |
|
282 | + '<a href="%s" target="_blank">%s</a>', |
|
283 | + esc_url_raw( $url ), |
|
284 | + esc_html( $name ) |
|
285 | + ); |
|
286 | + } |
|
287 | 287 | |
288 | - $value = implode( ' | ', $value ); |
|
288 | + $value = implode( ' | ', $value ); |
|
289 | 289 | |
290 | - } elseif ( 'checkbox' === $field['type'] ) { |
|
291 | - $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
292 | - } else { |
|
293 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
294 | - } |
|
290 | + } elseif ( 'checkbox' === $field['type'] ) { |
|
291 | + $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
292 | + } else { |
|
293 | + $value = wp_kses_post( $data[ $field['id'] ] ); |
|
294 | + } |
|
295 | 295 | |
296 | 296 | $label = $field['id']; |
297 | 297 | |
@@ -299,192 +299,192 @@ discard block |
||
299 | 299 | $label = $field['label']; |
300 | 300 | } |
301 | 301 | |
302 | - if ( ! empty( $field['add_meta'] ) ) { |
|
303 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
304 | - } |
|
305 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
302 | + if ( ! empty( $field['add_meta'] ) ) { |
|
303 | + $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
304 | + } |
|
305 | + $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
306 | 306 | |
307 | 307 | } |
308 | - } |
|
308 | + } |
|
309 | 309 | |
310 | - return $prepared; |
|
310 | + return $prepared; |
|
311 | 311 | |
312 | - } |
|
312 | + } |
|
313 | 313 | |
314 | - /** |
|
314 | + /** |
|
315 | 315 | * Retrieves address details. |
316 | 316 | * |
317 | - * @return array |
|
318 | - * @param WPInv_Invoice $invoice |
|
319 | - * @param string $type |
|
317 | + * @return array |
|
318 | + * @param WPInv_Invoice $invoice |
|
319 | + * @param string $type |
|
320 | 320 | */ |
321 | 321 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
322 | 322 | |
323 | - $data = $this->payment_form_submission->get_data(); |
|
324 | - $type = sanitize_key( $type ); |
|
325 | - $address = array(); |
|
326 | - $prepared = array(); |
|
323 | + $data = $this->payment_form_submission->get_data(); |
|
324 | + $type = sanitize_key( $type ); |
|
325 | + $address = array(); |
|
326 | + $prepared = array(); |
|
327 | 327 | |
328 | - if ( ! empty( $data[ $type ] ) ) { |
|
329 | - $address = $data[ $type ]; |
|
330 | - } |
|
328 | + if ( ! empty( $data[ $type ] ) ) { |
|
329 | + $address = $data[ $type ]; |
|
330 | + } |
|
331 | 331 | |
332 | - // Clean address details. |
|
333 | - foreach ( $address as $key => $value ) { |
|
334 | - $key = sanitize_key( $key ); |
|
335 | - $key = str_replace( 'wpinv_', '', $key ); |
|
336 | - $value = wpinv_clean( $value ); |
|
337 | - $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
338 | - } |
|
332 | + // Clean address details. |
|
333 | + foreach ( $address as $key => $value ) { |
|
334 | + $key = sanitize_key( $key ); |
|
335 | + $key = str_replace( 'wpinv_', '', $key ); |
|
336 | + $value = wpinv_clean( $value ); |
|
337 | + $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
338 | + } |
|
339 | 339 | |
340 | - // Filter address details. |
|
341 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
340 | + // Filter address details. |
|
341 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
342 | 342 | |
343 | - // Remove non-whitelisted values. |
|
344 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
343 | + // Remove non-whitelisted values. |
|
344 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
345 | 345 | |
346 | - } |
|
346 | + } |
|
347 | 347 | |
348 | - /** |
|
348 | + /** |
|
349 | 349 | * Prepares the billing details. |
350 | 350 | * |
351 | - * @return array |
|
352 | - * @param WPInv_Invoice $invoice |
|
351 | + * @return array |
|
352 | + * @param WPInv_Invoice $invoice |
|
353 | 353 | */ |
354 | 354 | protected function prepare_billing_info( &$invoice ) { |
355 | 355 | |
356 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
356 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
357 | 357 | |
358 | - // Update the invoice with the billing details. |
|
359 | - $invoice->set_props( $billing_address ); |
|
358 | + // Update the invoice with the billing details. |
|
359 | + $invoice->set_props( $billing_address ); |
|
360 | 360 | |
361 | - } |
|
361 | + } |
|
362 | 362 | |
363 | - /** |
|
363 | + /** |
|
364 | 364 | * Prepares the shipping details. |
365 | 365 | * |
366 | - * @return array |
|
367 | - * @param WPInv_Invoice $invoice |
|
366 | + * @return array |
|
367 | + * @param WPInv_Invoice $invoice |
|
368 | 368 | */ |
369 | 369 | protected function prepare_shipping_info( $invoice ) { |
370 | 370 | |
371 | - $data = $this->payment_form_submission->get_data(); |
|
371 | + $data = $this->payment_form_submission->get_data(); |
|
372 | 372 | |
373 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
374 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
375 | - } |
|
373 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
374 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
375 | + } |
|
376 | 376 | |
377 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
377 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
378 | 378 | |
379 | - } |
|
379 | + } |
|
380 | 380 | |
381 | - /** |
|
382 | - * Confirms the submission is valid and send users to the gateway. |
|
383 | - * |
|
384 | - * @param WPInv_Invoice $invoice |
|
385 | - * @param array $prepared_payment_form_data |
|
386 | - * @param array $shipping |
|
387 | - */ |
|
388 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
381 | + /** |
|
382 | + * Confirms the submission is valid and send users to the gateway. |
|
383 | + * |
|
384 | + * @param WPInv_Invoice $invoice |
|
385 | + * @param array $prepared_payment_form_data |
|
386 | + * @param array $shipping |
|
387 | + */ |
|
388 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
389 | 389 | |
390 | - // Ensure the invoice exists. |
|
390 | + // Ensure the invoice exists. |
|
391 | 391 | if ( ! $invoice->exists() ) { |
392 | 392 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
393 | 393 | } |
394 | 394 | |
395 | - // Save payment form data. |
|
396 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
395 | + // Save payment form data. |
|
396 | + $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
397 | 397 | delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
398 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
399 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
398 | + delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
399 | + if ( ! empty( $prepared_payment_form_data ) ) { |
|
400 | 400 | |
401 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
402 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
403 | - } |
|
401 | + if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
402 | + update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
403 | + } |
|
404 | 404 | |
405 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
406 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
407 | - } |
|
408 | - } |
|
405 | + if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
406 | + update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
407 | + } |
|
408 | + } |
|
409 | 409 | |
410 | - // Save payment form data. |
|
411 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
410 | + // Save payment form data. |
|
411 | + $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
412 | 412 | if ( ! empty( $shipping ) ) { |
413 | 413 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
414 | - } |
|
414 | + } |
|
415 | 415 | |
416 | - // Backwards compatibility. |
|
416 | + // Backwards compatibility. |
|
417 | 417 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
418 | 418 | |
419 | - try { |
|
420 | - $this->process_payment( $invoice ); |
|
421 | - } catch ( Exception $e ) { |
|
422 | - wpinv_set_error( 'payment_error', $e->getMessage() ); |
|
423 | - } |
|
419 | + try { |
|
420 | + $this->process_payment( $invoice ); |
|
421 | + } catch ( Exception $e ) { |
|
422 | + wpinv_set_error( 'payment_error', $e->getMessage() ); |
|
423 | + } |
|
424 | 424 | |
425 | 425 | // If we are here, there was an error. |
426 | - wpinv_send_back_to_checkout( $invoice ); |
|
426 | + wpinv_send_back_to_checkout( $invoice ); |
|
427 | 427 | |
428 | - } |
|
428 | + } |
|
429 | 429 | |
430 | - /** |
|
431 | - * Processes the actual payment. |
|
432 | - * |
|
433 | - * @param WPInv_Invoice $invoice |
|
434 | - */ |
|
435 | - protected function process_payment( $invoice ) { |
|
430 | + /** |
|
431 | + * Processes the actual payment. |
|
432 | + * |
|
433 | + * @param WPInv_Invoice $invoice |
|
434 | + */ |
|
435 | + protected function process_payment( $invoice ) { |
|
436 | 436 | |
437 | - // Clear any checkout errors. |
|
438 | - wpinv_clear_errors(); |
|
437 | + // Clear any checkout errors. |
|
438 | + wpinv_clear_errors(); |
|
439 | 439 | |
440 | - // No need to send free invoices to the gateway. |
|
441 | - if ( $invoice->is_free() ) { |
|
442 | - $this->process_free_payment( $invoice ); |
|
443 | - } |
|
440 | + // No need to send free invoices to the gateway. |
|
441 | + if ( $invoice->is_free() ) { |
|
442 | + $this->process_free_payment( $invoice ); |
|
443 | + } |
|
444 | 444 | |
445 | - $submission = $this->payment_form_submission; |
|
445 | + $submission = $this->payment_form_submission; |
|
446 | 446 | |
447 | - // Fires before sending to the gateway. |
|
448 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
447 | + // Fires before sending to the gateway. |
|
448 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
449 | 449 | |
450 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
451 | - $submission_data = $submission->get_data(); |
|
452 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
453 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
450 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
451 | + $submission_data = $submission->get_data(); |
|
452 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
453 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
454 | 454 | |
455 | - // Validate the currency. |
|
456 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
457 | - wpinv_set_error( 'invalid_currency' ); |
|
458 | - } |
|
455 | + // Validate the currency. |
|
456 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
457 | + wpinv_set_error( 'invalid_currency' ); |
|
458 | + } |
|
459 | 459 | |
460 | - // Check to see if we have any errors. |
|
461 | - if ( wpinv_get_errors() ) { |
|
462 | - wpinv_send_back_to_checkout( $invoice ); |
|
463 | - } |
|
460 | + // Check to see if we have any errors. |
|
461 | + if ( wpinv_get_errors() ) { |
|
462 | + wpinv_send_back_to_checkout( $invoice ); |
|
463 | + } |
|
464 | 464 | |
465 | - // Send info to the gateway for payment processing |
|
466 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
465 | + // Send info to the gateway for payment processing |
|
466 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
467 | 467 | |
468 | - // Backwards compatibility. |
|
469 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
468 | + // Backwards compatibility. |
|
469 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
470 | 470 | |
471 | - } |
|
471 | + } |
|
472 | 472 | |
473 | - /** |
|
474 | - * Marks the invoice as paid in case the checkout is free. |
|
475 | - * |
|
476 | - * @param WPInv_Invoice $invoice |
|
477 | - */ |
|
478 | - protected function process_free_payment( $invoice ) { |
|
473 | + /** |
|
474 | + * Marks the invoice as paid in case the checkout is free. |
|
475 | + * |
|
476 | + * @param WPInv_Invoice $invoice |
|
477 | + */ |
|
478 | + protected function process_free_payment( $invoice ) { |
|
479 | 479 | |
480 | - $invoice->set_gateway( 'none' ); |
|
481 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
482 | - $invoice->mark_paid(); |
|
483 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
480 | + $invoice->set_gateway( 'none' ); |
|
481 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
482 | + $invoice->mark_paid(); |
|
483 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
484 | 484 | |
485 | - } |
|
485 | + } |
|
486 | 486 | |
487 | - /** |
|
487 | + /** |
|
488 | 488 | * Sends a redrect response to payment details. |
489 | 489 | * |
490 | 490 | */ |
@@ -25,8 +25,8 @@ discard block |
||
25 | 25 | $defaults[ $key ] = $setting['std']; |
26 | 26 | } |
27 | 27 | } |
28 | - } |
|
29 | - } |
|
28 | + } |
|
29 | + } |
|
30 | 30 | |
31 | 31 | return $defaults; |
32 | 32 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * |
145 | 145 | */ |
146 | 146 | function wpinv_register_settings() { |
147 | - do_action( 'getpaid_before_register_settings' ); |
|
147 | + do_action( 'getpaid_before_register_settings' ); |
|
148 | 148 | |
149 | 149 | // Loop through all tabs. |
150 | 150 | foreach ( wpinv_get_registered_settings() as $tab => $sections ) { |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | $settings = $sections; |
160 | 160 | } |
161 | 161 | |
162 | - do_action( "getpaid_register_{$tab}_{$section}" ); |
|
162 | + do_action( "getpaid_register_{$tab}_{$section}" ); |
|
163 | 163 | |
164 | 164 | // Register the setting section. |
165 | 165 | add_settings_section( |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | // Creates our settings in the options table. |
181 | 181 | register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' ); |
182 | 182 | |
183 | - do_action( 'getpaid_after_register_settings' ); |
|
183 | + do_action( 'getpaid_after_register_settings' ); |
|
184 | 184 | } |
185 | 185 | add_action( 'admin_init', 'wpinv_register_settings' ); |
186 | 186 | |
@@ -197,13 +197,13 @@ discard block |
||
197 | 197 | $name = isset( $option['name'] ) ? $option['name'] : ''; |
198 | 198 | $cb = "wpinv_{$option['type']}_callback"; |
199 | 199 | $section = "wpinv_settings_{$tab}_$section"; |
200 | - $is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page']; |
|
200 | + $is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page']; |
|
201 | 201 | |
202 | - if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) { |
|
203 | - $tip = wpinv_clean( $option['desc'] ); |
|
204 | - $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
205 | - unset( $option['desc'] ); |
|
206 | - } |
|
202 | + if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) { |
|
203 | + $tip = wpinv_clean( $option['desc'] ); |
|
204 | + $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
205 | + unset( $option['desc'] ); |
|
206 | + } |
|
207 | 207 | |
208 | 208 | // Loop through all tabs. |
209 | 209 | add_settings_field( |
@@ -230,9 +230,9 @@ discard block |
||
230 | 230 | 'faux' => isset( $option['faux'] ) ? $option['faux'] : false, |
231 | 231 | 'onchange' => isset( $option['onchange'] ) ? $option['onchange'] : '', |
232 | 232 | 'custom' => isset( $option['custom'] ) ? $option['custom'] : '', |
233 | - 'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '', |
|
234 | - 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
235 | - 'style' => isset( $option['style'] ) ? $option['style'] : '', |
|
233 | + 'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '', |
|
234 | + 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
235 | + 'style' => isset( $option['style'] ) ? $option['style'] : '', |
|
236 | 236 | 'cols' => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50, |
237 | 237 | 'rows' => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5, |
238 | 238 | ) |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | * @return array |
247 | 247 | */ |
248 | 248 | function wpinv_get_registered_settings() { |
249 | - return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) ); |
|
249 | + return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) ); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -265,18 +265,18 @@ discard block |
||
265 | 265 | */ |
266 | 266 | function wpinv_settings_sanitize( $input = array() ) { |
267 | 267 | |
268 | - $wpinv_options = wpinv_get_options(); |
|
269 | - $raw_referrer = wp_get_raw_referer(); |
|
268 | + $wpinv_options = wpinv_get_options(); |
|
269 | + $raw_referrer = wp_get_raw_referer(); |
|
270 | 270 | |
271 | 271 | if ( empty( $raw_referrer ) ) { |
272 | - return array_merge( $wpinv_options, $input ); |
|
272 | + return array_merge( $wpinv_options, $input ); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | wp_parse_str( $raw_referrer, $referrer ); |
276 | 276 | |
277 | - if ( in_array( 'gp-setup', $referrer ) ) { |
|
278 | - return array_merge( $wpinv_options, $input ); |
|
279 | - } |
|
277 | + if ( in_array( 'gp-setup', $referrer ) ) { |
|
278 | + return array_merge( $wpinv_options, $input ); |
|
279 | + } |
|
280 | 280 | |
281 | 281 | $settings = wpinv_get_registered_settings(); |
282 | 282 | $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general'; |
@@ -298,10 +298,10 @@ discard block |
||
298 | 298 | } |
299 | 299 | |
300 | 300 | // General filter |
301 | - $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
301 | + $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
302 | 302 | |
303 | - // Key specific filter. |
|
304 | - $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
303 | + // Key specific filter. |
|
304 | + $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | // Loop through the whitelist and unset any that are empty for the tab being saved |
@@ -344,14 +344,14 @@ discard block |
||
344 | 344 | |
345 | 345 | foreach ( $new_rates as $rate ) { |
346 | 346 | |
347 | - $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
348 | - $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
349 | - $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
350 | - $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
351 | - $rate['global'] = empty( $rate['state'] ); |
|
352 | - $tax_rates[] = $rate; |
|
347 | + $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
348 | + $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
349 | + $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
350 | + $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
351 | + $rate['global'] = empty( $rate['state'] ); |
|
352 | + $tax_rates[] = $rate; |
|
353 | 353 | |
354 | - } |
|
354 | + } |
|
355 | 355 | |
356 | 356 | update_option( 'wpinv_tax_rates', $tax_rates ); |
357 | 357 | |
@@ -364,21 +364,21 @@ discard block |
||
364 | 364 | return $input; |
365 | 365 | } |
366 | 366 | |
367 | - if ( empty( $_POST['wpinv_tax_rules_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_tax_rules_nonce'], 'wpinv_tax_rules' ) ) { |
|
368 | - return $input; |
|
369 | - } |
|
367 | + if ( empty( $_POST['wpinv_tax_rules_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_tax_rules_nonce'], 'wpinv_tax_rules' ) ) { |
|
368 | + return $input; |
|
369 | + } |
|
370 | 370 | |
371 | 371 | $new_rules = ! empty( $_POST['tax_rules'] ) ? wp_kses_post_deep( array_values( $_POST['tax_rules'] ) ) : array(); |
372 | 372 | $tax_rules = array(); |
373 | 373 | |
374 | 374 | foreach ( $new_rules as $rule ) { |
375 | 375 | |
376 | - $rule['key'] = sanitize_title_with_dashes( $rule['key'] ); |
|
377 | - $rule['label'] = sanitize_text_field( $rule['label'] ); |
|
378 | - $rule['tax_base'] = sanitize_text_field( $rule['tax_base'] ); |
|
379 | - $tax_rules[] = $rule; |
|
376 | + $rule['key'] = sanitize_title_with_dashes( $rule['key'] ); |
|
377 | + $rule['label'] = sanitize_text_field( $rule['label'] ); |
|
378 | + $rule['tax_base'] = sanitize_text_field( $rule['tax_base'] ); |
|
379 | + $tax_rules[] = $rule; |
|
380 | 380 | |
381 | - } |
|
381 | + } |
|
382 | 382 | |
383 | 383 | update_option( 'wpinv_tax_rules', $tax_rules ); |
384 | 384 | |
@@ -391,11 +391,11 @@ discard block |
||
391 | 391 | $tabs['general'] = __( 'General', 'invoicing' ); |
392 | 392 | $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' ); |
393 | 393 | $tabs['taxes'] = __( 'Taxes', 'invoicing' ); |
394 | - $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
394 | + $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
395 | 395 | |
396 | - if ( count( getpaid_get_integration_settings() ) > 0 ) { |
|
397 | - $tabs['integrations'] = __( 'Integrations', 'invoicing' ); |
|
398 | - } |
|
396 | + if ( count( getpaid_get_integration_settings() ) > 0 ) { |
|
397 | + $tabs['integrations'] = __( 'Integrations', 'invoicing' ); |
|
398 | + } |
|
399 | 399 | |
400 | 400 | $tabs['privacy'] = __( 'Privacy', 'invoicing' ); |
401 | 401 | $tabs['misc'] = __( 'Misc', 'invoicing' ); |
@@ -426,53 +426,53 @@ discard block |
||
426 | 426 | 'general' => apply_filters( |
427 | 427 | 'wpinv_settings_sections_general', |
428 | 428 | array( |
429 | - 'main' => __( 'General Settings', 'invoicing' ), |
|
430 | - 'page_section' => __( 'Page Settings', 'invoicing' ), |
|
431 | - 'currency_section' => __( 'Currency Settings', 'invoicing' ), |
|
432 | - 'labels' => __( 'Label Texts', 'invoicing' ), |
|
429 | + 'main' => __( 'General Settings', 'invoicing' ), |
|
430 | + 'page_section' => __( 'Page Settings', 'invoicing' ), |
|
431 | + 'currency_section' => __( 'Currency Settings', 'invoicing' ), |
|
432 | + 'labels' => __( 'Label Texts', 'invoicing' ), |
|
433 | 433 | ) |
434 | 434 | ), |
435 | 435 | 'gateways' => apply_filters( |
436 | 436 | 'wpinv_settings_sections_gateways', |
437 | 437 | array( |
438 | - 'main' => __( 'Gateway Settings', 'invoicing' ), |
|
438 | + 'main' => __( 'Gateway Settings', 'invoicing' ), |
|
439 | 439 | ) |
440 | 440 | ), |
441 | 441 | 'taxes' => apply_filters( |
442 | 442 | 'wpinv_settings_sections_taxes', |
443 | 443 | array( |
444 | - 'main' => __( 'Tax Settings', 'invoicing' ), |
|
445 | - 'rules' => __( 'Tax Rules', 'invoicing' ), |
|
446 | - 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
447 | - 'vat' => __( 'EU VAT Settings', 'invoicing' ), |
|
444 | + 'main' => __( 'Tax Settings', 'invoicing' ), |
|
445 | + 'rules' => __( 'Tax Rules', 'invoicing' ), |
|
446 | + 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
447 | + 'vat' => __( 'EU VAT Settings', 'invoicing' ), |
|
448 | 448 | ) |
449 | 449 | ), |
450 | 450 | 'emails' => apply_filters( |
451 | 451 | 'wpinv_settings_sections_emails', |
452 | 452 | array( |
453 | - 'main' => __( 'Email Settings', 'invoicing' ), |
|
453 | + 'main' => __( 'Email Settings', 'invoicing' ), |
|
454 | 454 | ) |
455 | 455 | ), |
456 | 456 | |
457 | - 'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ), |
|
457 | + 'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ), |
|
458 | 458 | |
459 | 459 | 'privacy' => apply_filters( |
460 | 460 | 'wpinv_settings_sections_privacy', |
461 | 461 | array( |
462 | - 'main' => __( 'Privacy policy', 'invoicing' ), |
|
462 | + 'main' => __( 'Privacy policy', 'invoicing' ), |
|
463 | 463 | ) |
464 | 464 | ), |
465 | 465 | 'misc' => apply_filters( |
466 | 466 | 'wpinv_settings_sections_misc', |
467 | 467 | array( |
468 | - 'main' => __( 'Miscellaneous', 'invoicing' ), |
|
469 | - 'custom-css' => __( 'Custom CSS', 'invoicing' ), |
|
468 | + 'main' => __( 'Miscellaneous', 'invoicing' ), |
|
469 | + 'custom-css' => __( 'Custom CSS', 'invoicing' ), |
|
470 | 470 | ) |
471 | 471 | ), |
472 | 472 | 'tools' => apply_filters( |
473 | 473 | 'wpinv_settings_sections_tools', |
474 | 474 | array( |
475 | - 'main' => __( 'Diagnostic Tools', 'invoicing' ), |
|
475 | + 'main' => __( 'Diagnostic Tools', 'invoicing' ), |
|
476 | 476 | ) |
477 | 477 | ), |
478 | 478 | ); |
@@ -483,46 +483,46 @@ discard block |
||
483 | 483 | } |
484 | 484 | |
485 | 485 | function wpinv_get_pages( $with_slug = false, $default_label = null ) { |
486 | - $pages_options = array(); |
|
486 | + $pages_options = array(); |
|
487 | 487 | |
488 | - if ( $default_label !== null && $default_label !== false ) { |
|
489 | - $pages_options = array( '' => $default_label ); // Blank option |
|
490 | - } |
|
488 | + if ( $default_label !== null && $default_label !== false ) { |
|
489 | + $pages_options = array( '' => $default_label ); // Blank option |
|
490 | + } |
|
491 | 491 | |
492 | - $pages = get_pages(); |
|
493 | - if ( $pages ) { |
|
494 | - foreach ( $pages as $page ) { |
|
495 | - $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
492 | + $pages = get_pages(); |
|
493 | + if ( $pages ) { |
|
494 | + foreach ( $pages as $page ) { |
|
495 | + $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
496 | 496 | $pages_options[ $page->ID ] = $title; |
497 | - } |
|
498 | - } |
|
497 | + } |
|
498 | + } |
|
499 | 499 | |
500 | - return $pages_options; |
|
500 | + return $pages_options; |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | function wpinv_header_callback( $args ) { |
504 | - if ( ! empty( $args['desc'] ) ) { |
|
504 | + if ( ! empty( $args['desc'] ) ) { |
|
505 | 505 | echo wp_kses_post( $args['desc'] ); |
506 | 506 | } |
507 | 507 | } |
508 | 508 | |
509 | 509 | function wpinv_hidden_callback( $args ) { |
510 | 510 | |
511 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
512 | - $value = wpinv_get_option( $args['id'], $std ); |
|
511 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
512 | + $value = wpinv_get_option( $args['id'], $std ); |
|
513 | 513 | |
514 | - if ( isset( $args['set_value'] ) ) { |
|
515 | - $value = $args['set_value']; |
|
516 | - } |
|
514 | + if ( isset( $args['set_value'] ) ) { |
|
515 | + $value = $args['set_value']; |
|
516 | + } |
|
517 | 517 | |
518 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
519 | - $args['readonly'] = true; |
|
520 | - $name = ''; |
|
521 | - } else { |
|
522 | - $name = 'wpinv_settings[' . esc_attr( $args['id'] ) . ']'; |
|
523 | - } |
|
518 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
519 | + $args['readonly'] = true; |
|
520 | + $name = ''; |
|
521 | + } else { |
|
522 | + $name = 'wpinv_settings[' . esc_attr( $args['id'] ) . ']'; |
|
523 | + } |
|
524 | 524 | |
525 | - echo '<input type="hidden" id="wpinv_settings[' . esc_attr( $args['id'] ) . ']" name="' . esc_attr( $name ) . '" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
525 | + echo '<input type="hidden" id="wpinv_settings[' . esc_attr( $args['id'] ) . ']" name="' . esc_attr( $name ) . '" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
526 | 526 | |
527 | 527 | } |
528 | 528 | |
@@ -531,12 +531,12 @@ discard block |
||
531 | 531 | */ |
532 | 532 | function wpinv_checkbox_callback( $args ) { |
533 | 533 | |
534 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
535 | - $std = wpinv_get_option( $args['id'], $std ); |
|
536 | - $id = esc_attr( $args['id'] ); |
|
534 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
535 | + $std = wpinv_get_option( $args['id'], $std ); |
|
536 | + $id = esc_attr( $args['id'] ); |
|
537 | 537 | |
538 | - getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
539 | - ?> |
|
538 | + getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
539 | + ?> |
|
540 | 540 | <label> |
541 | 541 | <input id="wpinv-settings-<?php echo esc_attr( $id ); ?>" name="wpinv_settings[<?php echo esc_attr( $id ); ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox" /> |
542 | 542 | <?php echo wp_kses_post( $args['desc'] ); ?> |
@@ -546,75 +546,75 @@ discard block |
||
546 | 546 | |
547 | 547 | function wpinv_multicheck_callback( $args ) { |
548 | 548 | |
549 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
550 | - $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
549 | + $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
550 | + $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
551 | 551 | |
552 | - if ( ! empty( $args['options'] ) ) { |
|
552 | + if ( ! empty( $args['options'] ) ) { |
|
553 | 553 | |
554 | - $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
555 | - $value = wpinv_get_option( $args['id'], $std ); |
|
554 | + $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
555 | + $value = wpinv_get_option( $args['id'], $std ); |
|
556 | 556 | |
557 | - echo '<div class="wpi-mcheck-rows wpi-mcheck-' . esc_attr( $sanitize_id . $class ) . '">'; |
|
557 | + echo '<div class="wpi-mcheck-rows wpi-mcheck-' . esc_attr( $sanitize_id . $class ) . '">'; |
|
558 | 558 | foreach ( $args['options'] as $key => $option ) : |
559 | - $sanitize_key = esc_attr( wpinv_sanitize_key( $key ) ); |
|
560 | - if ( in_array( $sanitize_key, $value ) ) { |
|
561 | - $enabled = $sanitize_key; |
|
562 | - } else { |
|
563 | - $enabled = null; |
|
564 | - } |
|
565 | - echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
566 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
567 | - endforeach; |
|
568 | - echo '</div>'; |
|
569 | - echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
570 | - } |
|
559 | + $sanitize_key = esc_attr( wpinv_sanitize_key( $key ) ); |
|
560 | + if ( in_array( $sanitize_key, $value ) ) { |
|
561 | + $enabled = $sanitize_key; |
|
562 | + } else { |
|
563 | + $enabled = null; |
|
564 | + } |
|
565 | + echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
566 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
567 | + endforeach; |
|
568 | + echo '</div>'; |
|
569 | + echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
570 | + } |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | function wpinv_payment_icons_callback( $args ) { |
574 | 574 | |
575 | 575 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
576 | - $value = wpinv_get_option( $args['id'], false ); |
|
576 | + $value = wpinv_get_option( $args['id'], false ); |
|
577 | 577 | |
578 | - if ( ! empty( $args['options'] ) ) { |
|
579 | - foreach ( $args['options'] as $key => $option ) { |
|
578 | + if ( ! empty( $args['options'] ) ) { |
|
579 | + foreach ( $args['options'] as $key => $option ) { |
|
580 | 580 | $sanitize_key = wpinv_sanitize_key( $key ); |
581 | 581 | |
582 | - if ( empty( $value ) ) { |
|
583 | - $enabled = $option; |
|
584 | - } else { |
|
585 | - $enabled = null; |
|
586 | - } |
|
587 | - |
|
588 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
589 | - |
|
590 | - echo '<input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
591 | - |
|
592 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
593 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
594 | - } else { |
|
595 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
596 | - |
|
597 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
598 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
599 | - } else { |
|
600 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
601 | - $content_dir = WP_CONTENT_DIR; |
|
602 | - |
|
603 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
604 | - // Replaces backslashes with forward slashes for Windows systems |
|
605 | - $image = wp_normalize_path( $image ); |
|
606 | - $content_dir = wp_normalize_path( $content_dir ); |
|
607 | - } |
|
608 | - |
|
609 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
610 | - } |
|
611 | - |
|
612 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
613 | - } |
|
614 | - echo wp_kses_post( $option ) . '</label>'; |
|
615 | - } |
|
616 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
617 | - } |
|
582 | + if ( empty( $value ) ) { |
|
583 | + $enabled = $option; |
|
584 | + } else { |
|
585 | + $enabled = null; |
|
586 | + } |
|
587 | + |
|
588 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
589 | + |
|
590 | + echo '<input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
591 | + |
|
592 | + if ( wpinv_string_is_image_url( $key ) ) { |
|
593 | + echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
594 | + } else { |
|
595 | + $card = strtolower( str_replace( ' ', '', $option ) ); |
|
596 | + |
|
597 | + if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
598 | + $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
599 | + } else { |
|
600 | + $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
601 | + $content_dir = WP_CONTENT_DIR; |
|
602 | + |
|
603 | + if ( function_exists( 'wp_normalize_path' ) ) { |
|
604 | + // Replaces backslashes with forward slashes for Windows systems |
|
605 | + $image = wp_normalize_path( $image ); |
|
606 | + $content_dir = wp_normalize_path( $content_dir ); |
|
607 | + } |
|
608 | + |
|
609 | + $image = str_replace( $content_dir, content_url(), $image ); |
|
610 | + } |
|
611 | + |
|
612 | + echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
613 | + } |
|
614 | + echo wp_kses_post( $option ) . '</label>'; |
|
615 | + } |
|
616 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
617 | + } |
|
618 | 618 | } |
619 | 619 | |
620 | 620 | /** |
@@ -622,9 +622,9 @@ discard block |
||
622 | 622 | */ |
623 | 623 | function wpinv_radio_callback( $args ) { |
624 | 624 | |
625 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
626 | - $std = wpinv_get_option( $args['id'], $std ); |
|
627 | - ?> |
|
625 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
626 | + $std = wpinv_get_option( $args['id'], $std ); |
|
627 | + ?> |
|
628 | 628 | <fieldset> |
629 | 629 | <ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;"> |
630 | 630 | <?php foreach ( $args['options'] as $key => $option ) : ?> |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | </ul> |
639 | 639 | </fieldset> |
640 | 640 | <?php |
641 | - getpaid_settings_description_callback( $args ); |
|
641 | + getpaid_settings_description_callback( $args ); |
|
642 | 642 | } |
643 | 643 | |
644 | 644 | /** |
@@ -646,10 +646,10 @@ discard block |
||
646 | 646 | */ |
647 | 647 | function getpaid_settings_description_callback( $args ) { |
648 | 648 | |
649 | - if ( ! empty( $args['desc'] ) ) { |
|
650 | - $description = $args['desc']; |
|
651 | - echo wp_kses_post( "<p class='description'>$description</p>" ); |
|
652 | - } |
|
649 | + if ( ! empty( $args['desc'] ) ) { |
|
650 | + $description = $args['desc']; |
|
651 | + echo wp_kses_post( "<p class='description'>$description</p>" ); |
|
652 | + } |
|
653 | 653 | |
654 | 654 | } |
655 | 655 | |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | */ |
659 | 659 | function wpinv_gateways_callback() { |
660 | 660 | |
661 | - ?> |
|
661 | + ?> |
|
662 | 662 | </td> |
663 | 663 | </tr> |
664 | 664 | <tr class="bsui"> |
@@ -672,26 +672,26 @@ discard block |
||
672 | 672 | |
673 | 673 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
674 | 674 | $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
675 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
676 | - $value = wpinv_get_option( $args['id'], $std ); |
|
675 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
676 | + $value = wpinv_get_option( $args['id'], $std ); |
|
677 | 677 | |
678 | - echo '<select name="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" class="' . esc_attr( $class ) . '" >'; |
|
678 | + echo '<select name="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" class="' . esc_attr( $class ) . '" >'; |
|
679 | 679 | |
680 | - foreach ( $args['options'] as $key => $option ) : |
|
680 | + foreach ( $args['options'] as $key => $option ) : |
|
681 | 681 | |
682 | - echo '<option value="' . esc_attr( $key ) . '" '; |
|
682 | + echo '<option value="' . esc_attr( $key ) . '" '; |
|
683 | 683 | |
684 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
684 | + if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
685 | 685 | selected( $key, $args['selected'] ); |
686 | 686 | } else { |
687 | 687 | selected( $key, $value ); |
688 | 688 | } |
689 | 689 | |
690 | - echo '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
691 | - endforeach; |
|
690 | + echo '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
691 | + endforeach; |
|
692 | 692 | |
693 | - echo '</select>'; |
|
694 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
693 | + echo '</select>'; |
|
694 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /** |
@@ -702,38 +702,38 @@ discard block |
||
702 | 702 | */ |
703 | 703 | function wpinv_settings_attrs_helper( $args ) { |
704 | 704 | |
705 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
706 | - $id = esc_attr( $args['id'] ); |
|
707 | - $value = is_scalar( $value ) ? $value : ''; |
|
708 | - |
|
709 | - $attrs = array( |
|
710 | - 'name' => ! empty( $args['faux'] ) ? false : "wpinv_settings[$id]", |
|
711 | - 'readonly' => ! empty( $args['faux'] ), |
|
712 | - 'value' => ! empty( $args['faux'] ) ? $value : wpinv_get_option( $args['id'], $value ), |
|
713 | - 'id' => 'wpinv-settings-' . $args['id'], |
|
714 | - 'style' => $args['style'], |
|
715 | - 'class' => $args['class'], |
|
716 | - 'placeholder' => $args['placeholder'], |
|
717 | - 'data-placeholder' => $args['placeholder'], |
|
718 | - ); |
|
705 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
706 | + $id = esc_attr( $args['id'] ); |
|
707 | + $value = is_scalar( $value ) ? $value : ''; |
|
708 | + |
|
709 | + $attrs = array( |
|
710 | + 'name' => ! empty( $args['faux'] ) ? false : "wpinv_settings[$id]", |
|
711 | + 'readonly' => ! empty( $args['faux'] ), |
|
712 | + 'value' => ! empty( $args['faux'] ) ? $value : wpinv_get_option( $args['id'], $value ), |
|
713 | + 'id' => 'wpinv-settings-' . $args['id'], |
|
714 | + 'style' => $args['style'], |
|
715 | + 'class' => $args['class'], |
|
716 | + 'placeholder' => $args['placeholder'], |
|
717 | + 'data-placeholder' => $args['placeholder'], |
|
718 | + ); |
|
719 | 719 | |
720 | - if ( ! empty( $args['onchange'] ) ) { |
|
721 | - $attrs['onchange'] = $args['onchange']; |
|
722 | - } |
|
720 | + if ( ! empty( $args['onchange'] ) ) { |
|
721 | + $attrs['onchange'] = $args['onchange']; |
|
722 | + } |
|
723 | 723 | |
724 | - foreach ( $attrs as $key => $value ) { |
|
724 | + foreach ( $attrs as $key => $value ) { |
|
725 | 725 | |
726 | - if ( false === $value ) { |
|
727 | - continue; |
|
728 | - } |
|
726 | + if ( false === $value ) { |
|
727 | + continue; |
|
728 | + } |
|
729 | 729 | |
730 | - if ( true === $value ) { |
|
731 | - echo ' ' . esc_attr( $key ); |
|
732 | - } else { |
|
733 | - echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
734 | - } |
|
730 | + if ( true === $value ) { |
|
731 | + echo ' ' . esc_attr( $key ); |
|
732 | + } else { |
|
733 | + echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
734 | + } |
|
735 | 735 | |
736 | - } |
|
736 | + } |
|
737 | 737 | |
738 | 738 | } |
739 | 739 | |
@@ -742,7 +742,7 @@ discard block |
||
742 | 742 | */ |
743 | 743 | function wpinv_text_callback( $args ) { |
744 | 744 | |
745 | - ?> |
|
745 | + ?> |
|
746 | 746 | <label style="width: 100%;"> |
747 | 747 | <input type="text" <?php wpinv_settings_attrs_helper( $args ); ?>> |
748 | 748 | <?php getpaid_settings_description_callback( $args ); ?> |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | */ |
757 | 757 | function wpinv_number_callback( $args ) { |
758 | 758 | |
759 | - ?> |
|
759 | + ?> |
|
760 | 760 | <label style="width: 100%;"> |
761 | 761 | <input type="number" step="<?php echo esc_attr( $args['step'] ); ?>" max="<?php echo intval( $args['max'] ); ?>" min="<?php echo intval( $args['min'] ); ?>" <?php wpinv_settings_attrs_helper( $args ); ?>> |
762 | 762 | <?php getpaid_settings_description_callback( $args ); ?> |
@@ -768,34 +768,34 @@ discard block |
||
768 | 768 | function wpinv_textarea_callback( $args ) { |
769 | 769 | |
770 | 770 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
771 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
772 | - $value = wpinv_get_option( $args['id'], $std ); |
|
771 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
772 | + $value = wpinv_get_option( $args['id'], $std ); |
|
773 | 773 | |
774 | 774 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
775 | 775 | $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
776 | 776 | |
777 | - echo '<textarea class="' . esc_attr( $class ) . ' txtarea-' . esc_attr( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . esc_attr( $args['cols'] ) . '" rows="' . esc_attr( $args['rows'] ) . '" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
778 | - echo '<br /><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
777 | + echo '<textarea class="' . esc_attr( $class ) . ' txtarea-' . esc_attr( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . esc_attr( $args['cols'] ) . '" rows="' . esc_attr( $args['rows'] ) . '" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
778 | + echo '<br /><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
779 | 779 | |
780 | 780 | } |
781 | 781 | |
782 | 782 | function wpinv_password_callback( $args ) { |
783 | 783 | |
784 | 784 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
785 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
786 | - $value = wpinv_get_option( $args['id'], $std ); |
|
785 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
786 | + $value = wpinv_get_option( $args['id'], $std ); |
|
787 | 787 | |
788 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
789 | - echo '<input type="password" class="' . esc_attr( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
790 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
788 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
789 | + echo '<input type="password" class="' . esc_attr( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
790 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
791 | 791 | |
792 | 792 | } |
793 | 793 | |
794 | 794 | function wpinv_missing_callback( $args ) { |
795 | - printf( |
|
796 | - esc_html__( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
797 | - '<strong>' . esc_html( $args['id'] ) . '</strong>' |
|
798 | - ); |
|
795 | + printf( |
|
796 | + esc_html__( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
797 | + '<strong>' . esc_html( $args['id'] ) . '</strong>' |
|
798 | + ); |
|
799 | 799 | } |
800 | 800 | |
801 | 801 | /** |
@@ -803,13 +803,13 @@ discard block |
||
803 | 803 | */ |
804 | 804 | function wpinv_select_callback( $args ) { |
805 | 805 | |
806 | - $desc = wp_kses_post( $args['desc'] ); |
|
807 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
808 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
809 | - $value = wpinv_get_option( $args['id'], $value ); |
|
810 | - $rand = uniqid( 'random_id' ); |
|
806 | + $desc = wp_kses_post( $args['desc'] ); |
|
807 | + $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
808 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
809 | + $value = wpinv_get_option( $args['id'], $value ); |
|
810 | + $rand = uniqid( 'random_id' ); |
|
811 | 811 | |
812 | - ?> |
|
812 | + ?> |
|
813 | 813 | <label style="width: 100%;"> |
814 | 814 | <select <?php wpinv_settings_attrs_helper( $args ); ?> data-allow-clear="true"> |
815 | 815 | <?php foreach ( $args['options'] as $option => $name ) : ?> |
@@ -842,50 +842,50 @@ discard block |
||
842 | 842 | function wpinv_color_select_callback( $args ) { |
843 | 843 | |
844 | 844 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
845 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
846 | - $value = wpinv_get_option( $args['id'], $std ); |
|
845 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
846 | + $value = wpinv_get_option( $args['id'], $std ); |
|
847 | 847 | |
848 | - echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
848 | + echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
849 | 849 | |
850 | - foreach ( $args['options'] as $option => $color ) { |
|
851 | - echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $color['label'] ) . '</option>'; |
|
852 | - } |
|
850 | + foreach ( $args['options'] as $option => $color ) { |
|
851 | + echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $color['label'] ) . '</option>'; |
|
852 | + } |
|
853 | 853 | |
854 | - echo '</select>'; |
|
855 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
854 | + echo '</select>'; |
|
855 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
856 | 856 | |
857 | 857 | } |
858 | 858 | |
859 | 859 | function wpinv_rich_editor_callback( $args ) { |
860 | - global $wp_version; |
|
860 | + global $wp_version; |
|
861 | 861 | |
862 | 862 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
863 | 863 | |
864 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
865 | - $value = wpinv_get_option( $args['id'], $std ); |
|
864 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
865 | + $value = wpinv_get_option( $args['id'], $std ); |
|
866 | 866 | |
867 | - if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
868 | - $value = $std; |
|
869 | - } |
|
867 | + if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
868 | + $value = $std; |
|
869 | + } |
|
870 | 870 | |
871 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
871 | + $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
872 | 872 | |
873 | - echo '<div class="getpaid-settings-editor-input">'; |
|
874 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
875 | - wp_editor( |
|
873 | + echo '<div class="getpaid-settings-editor-input">'; |
|
874 | + if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
875 | + wp_editor( |
|
876 | 876 | stripslashes( $value ), |
877 | 877 | 'wpinv_settings_' . esc_attr( $args['id'] ), |
878 | 878 | array( |
879 | - 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', |
|
880 | - 'textarea_rows' => absint( $rows ), |
|
881 | - 'media_buttons' => false, |
|
879 | + 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', |
|
880 | + 'textarea_rows' => absint( $rows ), |
|
881 | + 'media_buttons' => false, |
|
882 | 882 | ) |
883 | 883 | ); |
884 | - } else { |
|
885 | - echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
886 | - } |
|
884 | + } else { |
|
885 | + echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
886 | + } |
|
887 | 887 | |
888 | - echo '</div><br/><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
888 | + echo '</div><br/><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
889 | 889 | |
890 | 890 | } |
891 | 891 | |
@@ -893,51 +893,51 @@ discard block |
||
893 | 893 | |
894 | 894 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
895 | 895 | |
896 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
897 | - $value = wpinv_get_option( $args['id'], $std ); |
|
896 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
897 | + $value = wpinv_get_option( $args['id'], $std ); |
|
898 | 898 | |
899 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
900 | - echo '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
901 | - echo '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . esc_attr__( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
902 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
899 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
900 | + echo '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
901 | + echo '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . esc_attr__( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
902 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
903 | 903 | |
904 | 904 | } |
905 | 905 | |
906 | 906 | function wpinv_color_callback( $args ) { |
907 | 907 | |
908 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
909 | - $value = wpinv_get_option( $args['id'], $std ); |
|
908 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
909 | + $value = wpinv_get_option( $args['id'], $std ); |
|
910 | 910 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
911 | 911 | |
912 | - echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />'; |
|
913 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
912 | + echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />'; |
|
913 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
914 | 914 | |
915 | 915 | } |
916 | 916 | |
917 | 917 | function wpinv_country_states_callback( $args ) { |
918 | 918 | |
919 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
920 | - $value = wpinv_get_option( $args['id'], $std ); |
|
919 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
920 | + $value = wpinv_get_option( $args['id'], $std ); |
|
921 | 921 | |
922 | 922 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
923 | 923 | |
924 | - if ( isset( $args['placeholder'] ) ) { |
|
925 | - $placeholder = $args['placeholder']; |
|
926 | - } else { |
|
927 | - $placeholder = ''; |
|
928 | - } |
|
924 | + if ( isset( $args['placeholder'] ) ) { |
|
925 | + $placeholder = $args['placeholder']; |
|
926 | + } else { |
|
927 | + $placeholder = ''; |
|
928 | + } |
|
929 | 929 | |
930 | - $states = wpinv_get_country_states(); |
|
930 | + $states = wpinv_get_country_states(); |
|
931 | 931 | |
932 | - $class = empty( $states ) ? 'wpinv-no-states' : 'wpi_select2'; |
|
933 | - echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="' . esc_attr( $class ) . '" data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
932 | + $class = empty( $states ) ? 'wpinv-no-states' : 'wpi_select2'; |
|
933 | + echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="' . esc_attr( $class ) . '" data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
934 | 934 | |
935 | - foreach ( $states as $option => $name ) { |
|
936 | - echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $name ) . '</option>'; |
|
937 | - } |
|
935 | + foreach ( $states as $option => $name ) { |
|
936 | + echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $name ) . '</option>'; |
|
937 | + } |
|
938 | 938 | |
939 | - echo '</select>'; |
|
940 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
939 | + echo '</select>'; |
|
940 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
941 | 941 | |
942 | 942 | } |
943 | 943 | |
@@ -946,7 +946,7 @@ discard block |
||
946 | 946 | */ |
947 | 947 | function wpinv_tax_rates_callback() { |
948 | 948 | |
949 | - ?> |
|
949 | + ?> |
|
950 | 950 | </td> |
951 | 951 | </tr> |
952 | 952 | <tr class="bsui"> |
@@ -962,9 +962,9 @@ discard block |
||
962 | 962 | */ |
963 | 963 | function wpinv_tax_rate_callback( $tax_rate, $key ) { |
964 | 964 | |
965 | - $key = sanitize_key( $key ); |
|
966 | - $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
967 | - include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
965 | + $key = sanitize_key( $key ); |
|
966 | + $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
967 | + include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
968 | 968 | |
969 | 969 | } |
970 | 970 | |
@@ -973,7 +973,7 @@ discard block |
||
973 | 973 | */ |
974 | 974 | function wpinv_tax_rules_callback() { |
975 | 975 | |
976 | - ?> |
|
976 | + ?> |
|
977 | 977 | </td> |
978 | 978 | </tr> |
979 | 979 | <tr class="bsui"> |
@@ -1011,14 +1011,14 @@ discard block |
||
1011 | 1011 | <td> |
1012 | 1012 | <a href=" |
1013 | 1013 | <?php |
1014 | - echo esc_url( |
|
1015 | - wp_nonce_url( |
|
1016 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
1017 | - 'getpaid-nonce', |
|
1018 | - 'getpaid-nonce' |
|
1019 | - ) |
|
1020 | - ); |
|
1021 | - ?> |
|
1014 | + echo esc_url( |
|
1015 | + wp_nonce_url( |
|
1016 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
1017 | + 'getpaid-nonce', |
|
1018 | + 'getpaid-nonce' |
|
1019 | + ) |
|
1020 | + ); |
|
1021 | + ?> |
|
1022 | 1022 | " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
1023 | 1023 | </td> |
1024 | 1024 | </tr> |
@@ -1030,14 +1030,14 @@ discard block |
||
1030 | 1030 | <td> |
1031 | 1031 | <a href=" |
1032 | 1032 | <?php |
1033 | - echo esc_url( |
|
1034 | - wp_nonce_url( |
|
1035 | - add_query_arg( 'getpaid-admin-action', 'refresh_permalinks' ), |
|
1036 | - 'getpaid-nonce', |
|
1037 | - 'getpaid-nonce' |
|
1038 | - ) |
|
1039 | - ); |
|
1040 | - ?> |
|
1033 | + echo esc_url( |
|
1034 | + wp_nonce_url( |
|
1035 | + add_query_arg( 'getpaid-admin-action', 'refresh_permalinks' ), |
|
1036 | + 'getpaid-nonce', |
|
1037 | + 'getpaid-nonce' |
|
1038 | + ) |
|
1039 | + ); |
|
1040 | + ?> |
|
1041 | 1041 | " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
1042 | 1042 | </td> |
1043 | 1043 | </tr> |
@@ -1049,14 +1049,14 @@ discard block |
||
1049 | 1049 | <td> |
1050 | 1050 | <a href=" |
1051 | 1051 | <?php |
1052 | - echo esc_url( |
|
1053 | - wp_nonce_url( |
|
1054 | - add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
1055 | - 'getpaid-nonce', |
|
1056 | - 'getpaid-nonce' |
|
1057 | - ) |
|
1058 | - ); |
|
1059 | - ?> |
|
1052 | + echo esc_url( |
|
1053 | + wp_nonce_url( |
|
1054 | + add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
1055 | + 'getpaid-nonce', |
|
1056 | + 'getpaid-nonce' |
|
1057 | + ) |
|
1058 | + ); |
|
1059 | + ?> |
|
1060 | 1060 | " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
1061 | 1061 | </td> |
1062 | 1062 | </tr> |
@@ -1068,14 +1068,14 @@ discard block |
||
1068 | 1068 | <td> |
1069 | 1069 | <a href=" |
1070 | 1070 | <?php |
1071 | - echo esc_url( |
|
1072 | - wp_nonce_url( |
|
1073 | - add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ), |
|
1074 | - 'getpaid-nonce', |
|
1075 | - 'getpaid-nonce' |
|
1076 | - ) |
|
1077 | - ); |
|
1078 | - ?> |
|
1071 | + echo esc_url( |
|
1072 | + wp_nonce_url( |
|
1073 | + add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ), |
|
1074 | + 'getpaid-nonce', |
|
1075 | + 'getpaid-nonce' |
|
1076 | + ) |
|
1077 | + ); |
|
1078 | + ?> |
|
1079 | 1079 | " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
1080 | 1080 | </td> |
1081 | 1081 | </tr> |
@@ -1088,14 +1088,14 @@ discard block |
||
1088 | 1088 | <td> |
1089 | 1089 | <a href=" |
1090 | 1090 | <?php |
1091 | - echo esc_url( |
|
1092 | - wp_nonce_url( |
|
1093 | - add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ), |
|
1094 | - 'getpaid-nonce', |
|
1095 | - 'getpaid-nonce' |
|
1096 | - ) |
|
1097 | - ); |
|
1098 | - ?> |
|
1091 | + echo esc_url( |
|
1092 | + wp_nonce_url( |
|
1093 | + add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ), |
|
1094 | + 'getpaid-nonce', |
|
1095 | + 'getpaid-nonce' |
|
1096 | + ) |
|
1097 | + ); |
|
1098 | + ?> |
|
1099 | 1099 | " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
1100 | 1100 | </td> |
1101 | 1101 | </tr> |
@@ -1108,8 +1108,8 @@ discard block |
||
1108 | 1108 | <td> |
1109 | 1109 | <a href=" |
1110 | 1110 | <?php |
1111 | - echo esc_url( admin_url( 'index.php?page=gp-setup' ) ); |
|
1112 | - ?> |
|
1111 | + echo esc_url( admin_url( 'index.php?page=gp-setup' ) ); |
|
1112 | + ?> |
|
1113 | 1113 | " class="button button-primary"><?php esc_html_e( 'Launch', 'invoicing' ); ?></a> |
1114 | 1114 | </td> |
1115 | 1115 | </tr> |
@@ -1123,19 +1123,19 @@ discard block |
||
1123 | 1123 | |
1124 | 1124 | |
1125 | 1125 | function wpinv_descriptive_text_callback( $args ) { |
1126 | - echo wp_kses_post( $args['desc'] ); |
|
1126 | + echo wp_kses_post( $args['desc'] ); |
|
1127 | 1127 | } |
1128 | 1128 | |
1129 | 1129 | function wpinv_raw_html_callback( $args ) { |
1130 | - echo wp_kses( $args['desc'], getpaid_allowed_html() ); |
|
1130 | + echo wp_kses( $args['desc'], getpaid_allowed_html() ); |
|
1131 | 1131 | } |
1132 | 1132 | |
1133 | 1133 | function wpinv_hook_callback( $args ) { |
1134 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
1134 | + do_action( 'wpinv_' . $args['id'], $args ); |
|
1135 | 1135 | } |
1136 | 1136 | |
1137 | 1137 | function wpinv_set_settings_cap() { |
1138 | - return wpinv_get_capability(); |
|
1138 | + return wpinv_get_capability(); |
|
1139 | 1139 | } |
1140 | 1140 | add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
1141 | 1141 | |
@@ -1161,47 +1161,47 @@ discard block |
||
1161 | 1161 | * @return array |
1162 | 1162 | */ |
1163 | 1163 | function wpinv_get_email_merge_tags( $subscription = false ) { |
1164 | - $merge_tags = array( |
|
1165 | - '{site_title}' => __( 'Site Title', 'invoicing' ), |
|
1166 | - '{name}' => __( "Customer's full name", 'invoicing' ), |
|
1167 | - '{first_name}' => __( "Customer's first name", 'invoicing' ), |
|
1168 | - '{last_name}' => __( "Customer's last name", 'invoicing' ), |
|
1169 | - '{email}' => __( "Customer's email address", 'invoicing' ), |
|
1170 | - '{invoice_number}' => __( 'The invoice number', 'invoicing' ), |
|
1171 | - '{invoice_currency}' => __( 'The invoice currency', 'invoicing' ), |
|
1172 | - '{invoice_total}' => __( 'The invoice total', 'invoicing' ), |
|
1173 | - '{invoice_link}' => __( 'The invoice link', 'invoicing' ), |
|
1174 | - '{invoice_pay_link}' => __( 'The payment link', 'invoicing' ), |
|
1175 | - '{invoice_receipt_link}' => __( 'The receipt link', 'invoicing' ), |
|
1176 | - '{invoice_date}' => __( 'The date the invoice was created', 'invoicing' ), |
|
1177 | - '{invoice_due_date}' => __( 'The date the invoice is due', 'invoicing' ), |
|
1178 | - '{date}' => __( "Today's date", 'invoicing' ), |
|
1179 | - '{is_was}' => __( 'If due date of invoice is past, displays "was" otherwise displays "is"', 'invoicing' ), |
|
1180 | - '{invoice_label}' => __( 'Invoices/quotes singular name. Ex: Invoice/Quote', 'invoicing' ), |
|
1181 | - '{invoice_quote}' => __( 'Invoices/quotes singular name in small letters. Ex: invoice/quote', 'invoicing' ), |
|
1182 | - '{invoice_description}' => __( 'The description of the invoice', 'invoicing' ), |
|
1183 | - ); |
|
1184 | - |
|
1185 | - if ( $subscription ) { |
|
1186 | - $merge_tags = array_merge( |
|
1187 | - $merge_tags, |
|
1188 | - array( |
|
1189 | - '{subscription_renewal_date}' => __( 'The next renewal date of the subscription', 'invoicing' ), |
|
1190 | - '{subscription_created}' => __( "The subscription's creation date", 'invoicing' ), |
|
1191 | - '{subscription_status}' => __( "The subscription's status", 'invoicing' ), |
|
1192 | - '{subscription_profile_id}' => __( "The subscription's remote profile id", 'invoicing' ), |
|
1193 | - '{subscription_id}' => __( "The subscription's id", 'invoicing' ), |
|
1194 | - '{subscription_recurring_amount}' => __( 'The renewal amount of the subscription', 'invoicing' ), |
|
1195 | - '{subscription_initial_amount}' => __( 'The initial amount of the subscription', 'invoicing' ), |
|
1196 | - '{subscription_recurring_period}' => __( 'The recurring period of the subscription (e.g 1 year)', 'invoicing' ), |
|
1197 | - '{subscription_bill_times}' => __( 'The maximum number of times the subscription can be renewed', 'invoicing' ), |
|
1198 | - '{subscription_url}' => __( 'The URL to manage a subscription', 'invoicing' ), |
|
1199 | - '{subscription_name}' => __( 'The name of the recurring item', 'invoicing' ), |
|
1200 | - ) |
|
1201 | - ); |
|
1202 | - } |
|
1203 | - |
|
1204 | - return $merge_tags; |
|
1164 | + $merge_tags = array( |
|
1165 | + '{site_title}' => __( 'Site Title', 'invoicing' ), |
|
1166 | + '{name}' => __( "Customer's full name", 'invoicing' ), |
|
1167 | + '{first_name}' => __( "Customer's first name", 'invoicing' ), |
|
1168 | + '{last_name}' => __( "Customer's last name", 'invoicing' ), |
|
1169 | + '{email}' => __( "Customer's email address", 'invoicing' ), |
|
1170 | + '{invoice_number}' => __( 'The invoice number', 'invoicing' ), |
|
1171 | + '{invoice_currency}' => __( 'The invoice currency', 'invoicing' ), |
|
1172 | + '{invoice_total}' => __( 'The invoice total', 'invoicing' ), |
|
1173 | + '{invoice_link}' => __( 'The invoice link', 'invoicing' ), |
|
1174 | + '{invoice_pay_link}' => __( 'The payment link', 'invoicing' ), |
|
1175 | + '{invoice_receipt_link}' => __( 'The receipt link', 'invoicing' ), |
|
1176 | + '{invoice_date}' => __( 'The date the invoice was created', 'invoicing' ), |
|
1177 | + '{invoice_due_date}' => __( 'The date the invoice is due', 'invoicing' ), |
|
1178 | + '{date}' => __( "Today's date", 'invoicing' ), |
|
1179 | + '{is_was}' => __( 'If due date of invoice is past, displays "was" otherwise displays "is"', 'invoicing' ), |
|
1180 | + '{invoice_label}' => __( 'Invoices/quotes singular name. Ex: Invoice/Quote', 'invoicing' ), |
|
1181 | + '{invoice_quote}' => __( 'Invoices/quotes singular name in small letters. Ex: invoice/quote', 'invoicing' ), |
|
1182 | + '{invoice_description}' => __( 'The description of the invoice', 'invoicing' ), |
|
1183 | + ); |
|
1184 | + |
|
1185 | + if ( $subscription ) { |
|
1186 | + $merge_tags = array_merge( |
|
1187 | + $merge_tags, |
|
1188 | + array( |
|
1189 | + '{subscription_renewal_date}' => __( 'The next renewal date of the subscription', 'invoicing' ), |
|
1190 | + '{subscription_created}' => __( "The subscription's creation date", 'invoicing' ), |
|
1191 | + '{subscription_status}' => __( "The subscription's status", 'invoicing' ), |
|
1192 | + '{subscription_profile_id}' => __( "The subscription's remote profile id", 'invoicing' ), |
|
1193 | + '{subscription_id}' => __( "The subscription's id", 'invoicing' ), |
|
1194 | + '{subscription_recurring_amount}' => __( 'The renewal amount of the subscription', 'invoicing' ), |
|
1195 | + '{subscription_initial_amount}' => __( 'The initial amount of the subscription', 'invoicing' ), |
|
1196 | + '{subscription_recurring_period}' => __( 'The recurring period of the subscription (e.g 1 year)', 'invoicing' ), |
|
1197 | + '{subscription_bill_times}' => __( 'The maximum number of times the subscription can be renewed', 'invoicing' ), |
|
1198 | + '{subscription_url}' => __( 'The URL to manage a subscription', 'invoicing' ), |
|
1199 | + '{subscription_name}' => __( 'The name of the recurring item', 'invoicing' ), |
|
1200 | + ) |
|
1201 | + ); |
|
1202 | + } |
|
1203 | + |
|
1204 | + return $merge_tags; |
|
1205 | 1205 | } |
1206 | 1206 | |
1207 | 1207 | |
@@ -1213,28 +1213,28 @@ discard block |
||
1213 | 1213 | * @return string |
1214 | 1214 | */ |
1215 | 1215 | function wpinv_get_merge_tags_help_text( $subscription = false ) { |
1216 | - $merge_tags = wpinv_get_email_merge_tags( $subscription ); |
|
1216 | + $merge_tags = wpinv_get_email_merge_tags( $subscription ); |
|
1217 | 1217 | |
1218 | - $output = '<div class="bsui">'; |
|
1218 | + $output = '<div class="bsui">'; |
|
1219 | 1219 | |
1220 | - $link = sprintf( |
|
1221 | - '<strong class="getpaid-merge-tags text-primary" role="button">%s</strong>', |
|
1222 | - esc_html__( 'View available merge tags.', 'invoicing' ) |
|
1223 | - ); |
|
1220 | + $link = sprintf( |
|
1221 | + '<strong class="getpaid-merge-tags text-primary" role="button">%s</strong>', |
|
1222 | + esc_html__( 'View available merge tags.', 'invoicing' ) |
|
1223 | + ); |
|
1224 | 1224 | |
1225 | - $description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' ); |
|
1225 | + $description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' ); |
|
1226 | 1226 | |
1227 | - $output .= "$description $link"; |
|
1227 | + $output .= "$description $link"; |
|
1228 | 1228 | |
1229 | - $output .= '<div class="getpaid-merge-tags-content mt-2 p-1 d-none">'; |
|
1230 | - $output .= '<p class="mb-2">' . esc_html__( 'The following wildcards can be used in email subjects, heading and content:', 'invoicing' ) . '</p>'; |
|
1229 | + $output .= '<div class="getpaid-merge-tags-content mt-2 p-1 d-none">'; |
|
1230 | + $output .= '<p class="mb-2">' . esc_html__( 'The following wildcards can be used in email subjects, heading and content:', 'invoicing' ) . '</p>'; |
|
1231 | 1231 | |
1232 | - $output .= '<ul class="p-0 m-0">'; |
|
1233 | - foreach($merge_tags as $tag => $tag_description) { |
|
1234 | - $output .= "<li class='mb-2'><strong class='text-dark'>$tag</strong> — $tag_description</li>"; |
|
1235 | - } |
|
1232 | + $output .= '<ul class="p-0 m-0">'; |
|
1233 | + foreach($merge_tags as $tag => $tag_description) { |
|
1234 | + $output .= "<li class='mb-2'><strong class='text-dark'>$tag</strong> — $tag_description</li>"; |
|
1235 | + } |
|
1236 | 1236 | |
1237 | - $output .= '</ul></div></div>'; |
|
1237 | + $output .= '</ul></div></div>'; |
|
1238 | 1238 | |
1239 | - return $output; |
|
1239 | + return $output; |
|
1240 | 1240 | } |
@@ -16,496 +16,496 @@ |
||
16 | 16 | */ |
17 | 17 | class GetPaid_REST_Date_Based_Controller extends GetPaid_REST_Controller { |
18 | 18 | |
19 | - /** |
|
20 | - * Group response items by day or month. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - public $groupby = 'day'; |
|
25 | - |
|
26 | - /** |
|
27 | - * Returns an array with arguments to request the previous report. |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - public $previous_range = array(); |
|
32 | - |
|
33 | - /** |
|
34 | - * The period interval. |
|
35 | - * |
|
36 | - * @var int |
|
37 | - */ |
|
38 | - public $interval; |
|
39 | - |
|
40 | - /** |
|
41 | - * Retrieves the before and after dates. |
|
42 | - * |
|
43 | - * @param WP_REST_Request $request Request object. |
|
44 | - * @return array The appropriate date range. |
|
45 | - */ |
|
46 | - public function get_date_range( $request ) { |
|
47 | - |
|
48 | - // Check if the period is x_days. |
|
49 | - if ( preg_match( '/^(\d+)_days$/', $request['period'], $matches ) ) { |
|
50 | - $date_range = $this->get_x_days_date_range( absint( $matches[1] ) ); |
|
51 | - } elseif ( is_callable( array( $this, 'get_' . $request['period'] . '_date_range' ) ) ) { |
|
52 | - $date_range = call_user_func( array( $this, 'get_' . $request['period'] . '_date_range' ), $request ); |
|
53 | - } else { |
|
54 | - $request['period'] = '7_days'; |
|
55 | - $date_range = $this->get_x_days_date_range(); |
|
56 | - } |
|
57 | - |
|
58 | - // 3 months max for day view. |
|
59 | - $before = strtotime( $date_range['before'] ); |
|
60 | - $after = strtotime( $date_range['after'] ); |
|
61 | - if ( floor( ( $before - $after ) / MONTH_IN_SECONDS ) > 2 ) { |
|
62 | - $this->groupby = 'month'; |
|
63 | - } |
|
64 | - |
|
65 | - $this->prepare_interval( $date_range ); |
|
66 | - |
|
67 | - return $date_range; |
|
68 | - |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Groups by month or days. |
|
73 | - * |
|
74 | - * @param array $range Date range. |
|
75 | - * @return array The appropriate date range. |
|
76 | - */ |
|
77 | - public function prepare_interval( $range ) { |
|
78 | - |
|
79 | - $before = strtotime( $range['before'] ); |
|
80 | - $after = strtotime( $range['after'] ); |
|
81 | - if ( 'day' === $this->groupby ) { |
|
82 | - $difference = max( DAY_IN_SECONDS, ( DAY_IN_SECONDS + $before - $after ) ); // Prevent division by 0; |
|
83 | - $this->interval = absint( ceil( max( 1, $difference / DAY_IN_SECONDS ) ) ); |
|
84 | - return; |
|
85 | - } |
|
86 | - |
|
87 | - $this->interval = 0; |
|
88 | - $min_date = strtotime( gmdate( 'Y-m-01', $after ) ); |
|
89 | - |
|
90 | - while ( $min_date <= $before ) { |
|
91 | - $this->interval ++; |
|
92 | - $min_date = strtotime( '+1 MONTH', $min_date ); |
|
93 | - } |
|
94 | - |
|
95 | - $this->interval = max( 1, $this->interval ); |
|
96 | - |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Retrieves a custom date range. |
|
101 | - * |
|
102 | - * @param WP_REST_Request $request Request object. |
|
103 | - * @return array The appropriate date range. |
|
104 | - */ |
|
105 | - public function get_custom_date_range( $request ) { |
|
106 | - |
|
107 | - $after = max( strtotime( '-20 years' ), strtotime( sanitize_text_field( $request['after'] ) ) ); |
|
108 | - $before = gmdate( 'Y-m-d' ); |
|
19 | + /** |
|
20 | + * Group response items by day or month. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + public $groupby = 'day'; |
|
25 | + |
|
26 | + /** |
|
27 | + * Returns an array with arguments to request the previous report. |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + public $previous_range = array(); |
|
32 | + |
|
33 | + /** |
|
34 | + * The period interval. |
|
35 | + * |
|
36 | + * @var int |
|
37 | + */ |
|
38 | + public $interval; |
|
39 | + |
|
40 | + /** |
|
41 | + * Retrieves the before and after dates. |
|
42 | + * |
|
43 | + * @param WP_REST_Request $request Request object. |
|
44 | + * @return array The appropriate date range. |
|
45 | + */ |
|
46 | + public function get_date_range( $request ) { |
|
47 | + |
|
48 | + // Check if the period is x_days. |
|
49 | + if ( preg_match( '/^(\d+)_days$/', $request['period'], $matches ) ) { |
|
50 | + $date_range = $this->get_x_days_date_range( absint( $matches[1] ) ); |
|
51 | + } elseif ( is_callable( array( $this, 'get_' . $request['period'] . '_date_range' ) ) ) { |
|
52 | + $date_range = call_user_func( array( $this, 'get_' . $request['period'] . '_date_range' ), $request ); |
|
53 | + } else { |
|
54 | + $request['period'] = '7_days'; |
|
55 | + $date_range = $this->get_x_days_date_range(); |
|
56 | + } |
|
57 | + |
|
58 | + // 3 months max for day view. |
|
59 | + $before = strtotime( $date_range['before'] ); |
|
60 | + $after = strtotime( $date_range['after'] ); |
|
61 | + if ( floor( ( $before - $after ) / MONTH_IN_SECONDS ) > 2 ) { |
|
62 | + $this->groupby = 'month'; |
|
63 | + } |
|
64 | + |
|
65 | + $this->prepare_interval( $date_range ); |
|
66 | + |
|
67 | + return $date_range; |
|
68 | + |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Groups by month or days. |
|
73 | + * |
|
74 | + * @param array $range Date range. |
|
75 | + * @return array The appropriate date range. |
|
76 | + */ |
|
77 | + public function prepare_interval( $range ) { |
|
78 | + |
|
79 | + $before = strtotime( $range['before'] ); |
|
80 | + $after = strtotime( $range['after'] ); |
|
81 | + if ( 'day' === $this->groupby ) { |
|
82 | + $difference = max( DAY_IN_SECONDS, ( DAY_IN_SECONDS + $before - $after ) ); // Prevent division by 0; |
|
83 | + $this->interval = absint( ceil( max( 1, $difference / DAY_IN_SECONDS ) ) ); |
|
84 | + return; |
|
85 | + } |
|
86 | + |
|
87 | + $this->interval = 0; |
|
88 | + $min_date = strtotime( gmdate( 'Y-m-01', $after ) ); |
|
89 | + |
|
90 | + while ( $min_date <= $before ) { |
|
91 | + $this->interval ++; |
|
92 | + $min_date = strtotime( '+1 MONTH', $min_date ); |
|
93 | + } |
|
94 | + |
|
95 | + $this->interval = max( 1, $this->interval ); |
|
96 | + |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Retrieves a custom date range. |
|
101 | + * |
|
102 | + * @param WP_REST_Request $request Request object. |
|
103 | + * @return array The appropriate date range. |
|
104 | + */ |
|
105 | + public function get_custom_date_range( $request ) { |
|
106 | + |
|
107 | + $after = max( strtotime( '-20 years' ), strtotime( sanitize_text_field( $request['after'] ) ) ); |
|
108 | + $before = gmdate( 'Y-m-d' ); |
|
109 | 109 | |
110 | - if ( ! empty( $request['before'] ) ) { |
|
111 | - $before = min( strtotime( $before ), strtotime( sanitize_text_field( $request['before'] ) ) ); |
|
112 | - } |
|
113 | - |
|
114 | - // Set the previous date range. |
|
115 | - $difference = $before - $after; |
|
116 | - $this->previous_range = array( |
|
117 | - 'period' => 'custom', |
|
118 | - 'before' => gmdate( 'Y-m-d', $before - $difference - DAY_IN_SECONDS ), |
|
119 | - 'after' => gmdate( 'Y-m-d', $after - $difference - DAY_IN_SECONDS ), |
|
120 | - ); |
|
121 | - |
|
122 | - // Generate the report. |
|
123 | - return array( |
|
124 | - 'before' => gmdate( 'Y-m-d', $before ), |
|
125 | - 'after' => gmdate( 'Y-m-d', $after ), |
|
126 | - ); |
|
127 | - |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Retrieves todays date range. |
|
132 | - * |
|
133 | - * @return array The appropriate date range. |
|
134 | - */ |
|
135 | - public function get_today_date_range() { |
|
136 | - |
|
137 | - // Set the previous date range. |
|
138 | - $this->previous_range = array( |
|
139 | - 'period' => 'yesterday', |
|
140 | - ); |
|
141 | - |
|
142 | - // Generate the report. |
|
143 | - return array( |
|
144 | - 'before' => gmdate( 'Y-m-d' ), |
|
145 | - 'after' => gmdate( 'Y-m-d' ), |
|
146 | - ); |
|
147 | - |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Retrieves yesterdays date range. |
|
152 | - * |
|
153 | - * @return array The appropriate date range. |
|
154 | - */ |
|
155 | - public function get_yesterday_date_range() { |
|
156 | - |
|
157 | - // Set the previous date range. |
|
158 | - $this->previous_range = array( |
|
159 | - 'period' => 'custom', |
|
160 | - 'before' => gmdate( 'Y-m-d', strtotime( '-2 days' ) ), |
|
161 | - 'after' => gmdate( 'Y-m-d', strtotime( '-2 days' ) ), |
|
162 | - ); |
|
163 | - |
|
164 | - // Generate the report. |
|
165 | - return array( |
|
166 | - 'before' => gmdate( 'Y-m-d', strtotime( '-1 day' ) ), |
|
167 | - 'after' => gmdate( 'Y-m-d', strtotime( '-1 day' ) ), |
|
168 | - ); |
|
169 | - |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Retrieves this week's date range. |
|
174 | - * |
|
175 | - * @return array The appropriate date range. |
|
176 | - */ |
|
177 | - public function get_week_date_range() { |
|
178 | - |
|
179 | - // Set the previous date range. |
|
180 | - $this->previous_range = array( |
|
181 | - 'period' => 'last_week', |
|
182 | - ); |
|
183 | - |
|
184 | - // Generate the report. |
|
185 | - $week_starts = absint( get_option( 'start_of_week' ) ); |
|
186 | - return array( |
|
187 | - 'before' => gmdate( 'Y-m-d' ), |
|
188 | - 'after' => gmdate( 'Y-m-d', strtotime( 'next Sunday -' . ( 7 - $week_starts ) . ' days' ) ), |
|
189 | - ); |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Retrieves last week's date range. |
|
194 | - * |
|
195 | - * @return array The appropriate date range. |
|
196 | - */ |
|
197 | - public function get_last_week_date_range() { |
|
198 | - |
|
199 | - $week_starts = absint( get_option( 'start_of_week' ) ); |
|
200 | - $week_starts = strtotime( 'last Sunday -' . ( 7 - $week_starts ) . ' days' ); |
|
201 | - $date_range = array( |
|
202 | - 'before' => gmdate( 'Y-m-d', $week_starts + 6 * DAY_IN_SECONDS ), |
|
203 | - 'after' => gmdate( 'Y-m-d', $week_starts ), |
|
204 | - ); |
|
205 | - |
|
206 | - // Set the previous date range. |
|
207 | - $week_starts = $week_starts - 7 * DAY_IN_SECONDS; |
|
208 | - $this->previous_range = array( |
|
209 | - 'period' => 'custom', |
|
210 | - 'before' => gmdate( 'Y-m-d', $week_starts + 6 * DAY_IN_SECONDS ), |
|
211 | - 'after' => gmdate( 'Y-m-d', $week_starts ), |
|
212 | - ); |
|
213 | - |
|
214 | - // Generate the report. |
|
215 | - return $date_range; |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Retrieves last x days date range. |
|
220 | - * |
|
221 | - * @return array The appropriate date range. |
|
222 | - */ |
|
223 | - public function get_x_days_date_range( $days = 7 ) { |
|
224 | - |
|
225 | - $days--; |
|
226 | - |
|
227 | - $date_range = array( |
|
228 | - 'before' => gmdate( 'Y-m-d' ), |
|
229 | - 'after' => gmdate( 'Y-m-d', strtotime( "-$days days" ) ), |
|
230 | - ); |
|
231 | - |
|
232 | - $days++; |
|
233 | - |
|
234 | - // Set the previous date range. |
|
235 | - $this->previous_range = array( |
|
236 | - 'period' => 'custom', |
|
237 | - 'before' => gmdate( 'Y-m-d', strtotime( $date_range['before'] ) - $days * DAY_IN_SECONDS ), |
|
238 | - 'after' => gmdate( 'Y-m-d', strtotime( $date_range['after'] ) - $days * DAY_IN_SECONDS ), |
|
239 | - ); |
|
240 | - |
|
241 | - // Generate the report. |
|
242 | - return $date_range; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * Retrieves this month date range. |
|
247 | - * |
|
248 | - * @return array The appropriate date range. |
|
249 | - */ |
|
250 | - public function get_month_date_range() { |
|
251 | - |
|
252 | - // Set the previous date range. |
|
253 | - $this->previous_range = array( |
|
254 | - 'period' => 'last_month', |
|
255 | - ); |
|
256 | - |
|
257 | - // Generate the report. |
|
258 | - return array( |
|
259 | - 'after' => gmdate( 'Y-m-01' ), |
|
260 | - 'before' => gmdate( 'Y-m-t' ), |
|
261 | - ); |
|
262 | - |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Retrieves last month's date range. |
|
267 | - * |
|
268 | - * @return array The appropriate date range. |
|
269 | - */ |
|
270 | - public function get_last_month_date_range() { |
|
271 | - |
|
272 | - // Set the previous date range. |
|
273 | - $this->previous_range = array( |
|
274 | - 'period' => 'custom', |
|
275 | - 'after' => gmdate( 'Y-m-01', strtotime( '-2 months' ) ), |
|
276 | - 'before' => gmdate( 'Y-m-t', strtotime( '-2 months' ) ), |
|
277 | - ); |
|
278 | - |
|
279 | - // Generate the report. |
|
280 | - return array( |
|
281 | - 'after' => gmdate( 'Y-m-01', strtotime( 'last month' ) ), |
|
282 | - 'before' => gmdate( 'Y-m-t', strtotime( 'last month' ) ), |
|
283 | - ); |
|
284 | - |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * Retrieves this quarter date range. |
|
289 | - * |
|
290 | - * @return array The available quarters. |
|
291 | - */ |
|
292 | - public function get_quarters() { |
|
293 | - |
|
294 | - $year = (int) gmdate( 'Y' ); |
|
295 | - $last_year = (int) $year - 1; |
|
296 | - return array( |
|
297 | - |
|
298 | - // Third quarter of previous year: July 1st to September 30th |
|
299 | - array( |
|
300 | - 'before' => "{$last_year}-09-30", |
|
301 | - 'after' => "{$last_year}-07-01", |
|
302 | - ), |
|
303 | - |
|
304 | - // Last quarter of previous year: October 1st to December 31st |
|
305 | - array( |
|
306 | - 'before' => "{$last_year}-12-31", |
|
307 | - 'after' => "{$last_year}-10-01", |
|
308 | - ), |
|
309 | - |
|
310 | - // First quarter: January 1st to March 31st |
|
311 | - array( |
|
312 | - 'before' => "{$year}-03-31", |
|
313 | - 'after' => "{$year}-01-01", |
|
314 | - ), |
|
315 | - |
|
316 | - // Second quarter: April 1st to June 30th |
|
317 | - array( |
|
318 | - 'before' => "{$year}-06-30", |
|
319 | - 'after' => "{$year}-04-01", |
|
320 | - ), |
|
321 | - |
|
322 | - // Third quarter: July 1st to September 30th |
|
323 | - array( |
|
324 | - 'before' => "{$year}-09-30", |
|
325 | - 'after' => "{$year}-07-01", |
|
326 | - ), |
|
327 | - |
|
328 | - // Fourth quarter: October 1st to December 31st |
|
329 | - array( |
|
330 | - 'before' => "{$year}-12-31", |
|
331 | - 'after' => "{$year}-10-01", |
|
332 | - ), |
|
333 | - ); |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * Retrieves the current quater. |
|
338 | - * |
|
339 | - * @return int The current quarter. |
|
340 | - */ |
|
341 | - public function get_quarter() { |
|
342 | - |
|
343 | - $month = (int) gmdate( 'n' ); |
|
344 | - $quarters = array( 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4 ); |
|
345 | - return $quarters[ $month - 1 ]; |
|
346 | - |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * Retrieves this quarter date range. |
|
351 | - * |
|
352 | - * @return array The appropriate date range. |
|
353 | - */ |
|
354 | - public function get_quarter_date_range() { |
|
355 | - |
|
356 | - // Set the previous date range. |
|
357 | - $this->previous_range = array( |
|
358 | - 'period' => 'last_quarter', |
|
359 | - ); |
|
360 | - |
|
361 | - // Generate the report. |
|
362 | - $quarter = $this->get_quarter(); |
|
363 | - $quarters = $this->get_quarters(); |
|
364 | - return $quarters[ $quarter + 1 ]; |
|
365 | - |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * Retrieves last quarter's date range. |
|
370 | - * |
|
371 | - * @return array The appropriate date range. |
|
372 | - */ |
|
373 | - public function get_last_quarter_date_range() { |
|
374 | - |
|
375 | - $quarters = $this->get_quarters(); |
|
376 | - $quarter = $this->get_quarter(); |
|
377 | - |
|
378 | - // Set the previous date range. |
|
379 | - $this->previous_range = array_merge( |
|
380 | - $quarters[ $quarter - 1 ], |
|
381 | - array( 'period' => 'custom' ) |
|
382 | - ); |
|
383 | - |
|
384 | - // Generate the report. |
|
385 | - return $quarters[ $quarter ]; |
|
386 | - |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Retrieves this year date range. |
|
391 | - * |
|
392 | - * @return array The appropriate date range. |
|
393 | - */ |
|
394 | - public function get_year_date_range() { |
|
395 | - |
|
396 | - // Set the previous date range. |
|
397 | - $this->previous_range = array( |
|
398 | - 'period' => 'last_year', |
|
399 | - ); |
|
400 | - |
|
401 | - // Generate the report. |
|
402 | - return array( |
|
403 | - 'after' => gmdate( 'Y-01-01' ), |
|
404 | - 'before' => gmdate( 'Y-12-31' ), |
|
405 | - ); |
|
406 | - |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Retrieves last year date range. |
|
411 | - * |
|
412 | - * @return array The appropriate date range. |
|
413 | - */ |
|
414 | - public function get_last_year_date_range() { |
|
415 | - |
|
416 | - // Set the previous date range. |
|
417 | - $this->previous_range = array( |
|
418 | - 'period' => 'custom', |
|
419 | - 'after' => gmdate( 'Y-01-01', strtotime( '-2 years' ) ), |
|
420 | - 'before' => gmdate( 'Y-12-31', strtotime( '-2 years' ) ), |
|
421 | - ); |
|
422 | - |
|
423 | - // Generate the report. |
|
424 | - return array( |
|
425 | - 'after' => gmdate( 'Y-01-01', strtotime( 'last year' ) ), |
|
426 | - 'before' => gmdate( 'Y-12-31', strtotime( 'last year' ) ), |
|
427 | - ); |
|
428 | - |
|
429 | - } |
|
430 | - |
|
431 | - /** |
|
432 | - * Prepare a the request date for SQL usage. |
|
433 | - * |
|
434 | - * @param WP_REST_Request $request Request object. |
|
435 | - * @param string $date_field The date field. |
|
436 | - * @return string The appropriate SQL. |
|
437 | - */ |
|
438 | - public function get_date_range_sql( $request, $date_field ) { |
|
439 | - global $wpdb; |
|
440 | - |
|
441 | - $sql = '1=1'; |
|
442 | - $range = $this->get_date_range( $request ); |
|
443 | - |
|
444 | - if ( ! empty( $range['after'] ) ) { |
|
445 | - $sql .= ' AND ' . $wpdb->prepare( |
|
446 | - "$date_field >= %s", |
|
447 | - $range['after'] |
|
448 | - ); |
|
449 | - } |
|
450 | - |
|
451 | - if ( ! empty( $range['before'] ) ) { |
|
452 | - $sql .= ' AND ' . $wpdb->prepare( |
|
453 | - "$date_field <= %s", |
|
454 | - $range['before'] |
|
455 | - ); |
|
456 | - } |
|
457 | - |
|
458 | - return $sql; |
|
459 | - |
|
460 | - } |
|
461 | - |
|
462 | - /** |
|
463 | - * Prepares a group by query. |
|
464 | - * |
|
465 | - * @param string $date_field The date field. |
|
466 | - * @return string The appropriate SQL. |
|
467 | - */ |
|
468 | - public function get_group_by_sql( $date_field ) { |
|
469 | - |
|
470 | - if ( 'day' === $this->groupby ) { |
|
471 | - return "YEAR($date_field), MONTH($date_field), DAY($date_field)"; |
|
472 | - } |
|
473 | - |
|
474 | - return "YEAR($date_field), MONTH($date_field)"; |
|
475 | - } |
|
476 | - |
|
477 | - /** |
|
478 | - * Get the query params for collections. |
|
479 | - * |
|
480 | - * @return array |
|
481 | - */ |
|
482 | - public function get_collection_params() { |
|
483 | - return array( |
|
484 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
485 | - 'period' => array( |
|
486 | - 'description' => __( 'Limit to results of a specific period.', 'invoicing' ), |
|
487 | - 'type' => 'string', |
|
488 | - 'enum' => array( 'custom', 'today', 'yesterday', 'week', 'last_week', '7_days', '30_days', '60_days', '90_days', '180_days', 'month', 'last_month', 'quarter', 'last_quarter', 'year', 'last_year', 'quarter', 'last_quarter' ), |
|
489 | - 'validate_callback' => 'rest_validate_request_arg', |
|
490 | - 'sanitize_callback' => 'sanitize_text_field', |
|
491 | - 'default' => '7_days', |
|
492 | - ), |
|
493 | - 'after' => array( |
|
494 | - /* translators: %s: date format */ |
|
495 | - 'description' => sprintf( __( 'Limit to results after a specific date, the date needs to be in the %s format.', 'invoicing' ), 'YYYY-MM-DD' ), |
|
496 | - 'type' => 'string', |
|
497 | - 'validate_callback' => 'rest_validate_request_arg', |
|
498 | - 'sanitize_callback' => 'sanitize_text_field', |
|
499 | - 'default' => gmdate( 'Y-m-d', strtotime( '-7 days' ) ), |
|
500 | - ), |
|
501 | - 'before' => array( |
|
502 | - /* translators: %s: date format */ |
|
503 | - 'description' => sprintf( __( 'Limit to results before a specific date, the date needs to be in the %s format.', 'invoicing' ), 'YYYY-MM-DD' ), |
|
504 | - 'type' => 'string', |
|
505 | - 'validate_callback' => 'rest_validate_request_arg', |
|
506 | - 'sanitize_callback' => 'sanitize_text_field', |
|
507 | - 'default' => gmdate( 'Y-m-d' ), |
|
508 | - ), |
|
509 | - ); |
|
510 | - } |
|
110 | + if ( ! empty( $request['before'] ) ) { |
|
111 | + $before = min( strtotime( $before ), strtotime( sanitize_text_field( $request['before'] ) ) ); |
|
112 | + } |
|
113 | + |
|
114 | + // Set the previous date range. |
|
115 | + $difference = $before - $after; |
|
116 | + $this->previous_range = array( |
|
117 | + 'period' => 'custom', |
|
118 | + 'before' => gmdate( 'Y-m-d', $before - $difference - DAY_IN_SECONDS ), |
|
119 | + 'after' => gmdate( 'Y-m-d', $after - $difference - DAY_IN_SECONDS ), |
|
120 | + ); |
|
121 | + |
|
122 | + // Generate the report. |
|
123 | + return array( |
|
124 | + 'before' => gmdate( 'Y-m-d', $before ), |
|
125 | + 'after' => gmdate( 'Y-m-d', $after ), |
|
126 | + ); |
|
127 | + |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Retrieves todays date range. |
|
132 | + * |
|
133 | + * @return array The appropriate date range. |
|
134 | + */ |
|
135 | + public function get_today_date_range() { |
|
136 | + |
|
137 | + // Set the previous date range. |
|
138 | + $this->previous_range = array( |
|
139 | + 'period' => 'yesterday', |
|
140 | + ); |
|
141 | + |
|
142 | + // Generate the report. |
|
143 | + return array( |
|
144 | + 'before' => gmdate( 'Y-m-d' ), |
|
145 | + 'after' => gmdate( 'Y-m-d' ), |
|
146 | + ); |
|
147 | + |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Retrieves yesterdays date range. |
|
152 | + * |
|
153 | + * @return array The appropriate date range. |
|
154 | + */ |
|
155 | + public function get_yesterday_date_range() { |
|
156 | + |
|
157 | + // Set the previous date range. |
|
158 | + $this->previous_range = array( |
|
159 | + 'period' => 'custom', |
|
160 | + 'before' => gmdate( 'Y-m-d', strtotime( '-2 days' ) ), |
|
161 | + 'after' => gmdate( 'Y-m-d', strtotime( '-2 days' ) ), |
|
162 | + ); |
|
163 | + |
|
164 | + // Generate the report. |
|
165 | + return array( |
|
166 | + 'before' => gmdate( 'Y-m-d', strtotime( '-1 day' ) ), |
|
167 | + 'after' => gmdate( 'Y-m-d', strtotime( '-1 day' ) ), |
|
168 | + ); |
|
169 | + |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Retrieves this week's date range. |
|
174 | + * |
|
175 | + * @return array The appropriate date range. |
|
176 | + */ |
|
177 | + public function get_week_date_range() { |
|
178 | + |
|
179 | + // Set the previous date range. |
|
180 | + $this->previous_range = array( |
|
181 | + 'period' => 'last_week', |
|
182 | + ); |
|
183 | + |
|
184 | + // Generate the report. |
|
185 | + $week_starts = absint( get_option( 'start_of_week' ) ); |
|
186 | + return array( |
|
187 | + 'before' => gmdate( 'Y-m-d' ), |
|
188 | + 'after' => gmdate( 'Y-m-d', strtotime( 'next Sunday -' . ( 7 - $week_starts ) . ' days' ) ), |
|
189 | + ); |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Retrieves last week's date range. |
|
194 | + * |
|
195 | + * @return array The appropriate date range. |
|
196 | + */ |
|
197 | + public function get_last_week_date_range() { |
|
198 | + |
|
199 | + $week_starts = absint( get_option( 'start_of_week' ) ); |
|
200 | + $week_starts = strtotime( 'last Sunday -' . ( 7 - $week_starts ) . ' days' ); |
|
201 | + $date_range = array( |
|
202 | + 'before' => gmdate( 'Y-m-d', $week_starts + 6 * DAY_IN_SECONDS ), |
|
203 | + 'after' => gmdate( 'Y-m-d', $week_starts ), |
|
204 | + ); |
|
205 | + |
|
206 | + // Set the previous date range. |
|
207 | + $week_starts = $week_starts - 7 * DAY_IN_SECONDS; |
|
208 | + $this->previous_range = array( |
|
209 | + 'period' => 'custom', |
|
210 | + 'before' => gmdate( 'Y-m-d', $week_starts + 6 * DAY_IN_SECONDS ), |
|
211 | + 'after' => gmdate( 'Y-m-d', $week_starts ), |
|
212 | + ); |
|
213 | + |
|
214 | + // Generate the report. |
|
215 | + return $date_range; |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Retrieves last x days date range. |
|
220 | + * |
|
221 | + * @return array The appropriate date range. |
|
222 | + */ |
|
223 | + public function get_x_days_date_range( $days = 7 ) { |
|
224 | + |
|
225 | + $days--; |
|
226 | + |
|
227 | + $date_range = array( |
|
228 | + 'before' => gmdate( 'Y-m-d' ), |
|
229 | + 'after' => gmdate( 'Y-m-d', strtotime( "-$days days" ) ), |
|
230 | + ); |
|
231 | + |
|
232 | + $days++; |
|
233 | + |
|
234 | + // Set the previous date range. |
|
235 | + $this->previous_range = array( |
|
236 | + 'period' => 'custom', |
|
237 | + 'before' => gmdate( 'Y-m-d', strtotime( $date_range['before'] ) - $days * DAY_IN_SECONDS ), |
|
238 | + 'after' => gmdate( 'Y-m-d', strtotime( $date_range['after'] ) - $days * DAY_IN_SECONDS ), |
|
239 | + ); |
|
240 | + |
|
241 | + // Generate the report. |
|
242 | + return $date_range; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * Retrieves this month date range. |
|
247 | + * |
|
248 | + * @return array The appropriate date range. |
|
249 | + */ |
|
250 | + public function get_month_date_range() { |
|
251 | + |
|
252 | + // Set the previous date range. |
|
253 | + $this->previous_range = array( |
|
254 | + 'period' => 'last_month', |
|
255 | + ); |
|
256 | + |
|
257 | + // Generate the report. |
|
258 | + return array( |
|
259 | + 'after' => gmdate( 'Y-m-01' ), |
|
260 | + 'before' => gmdate( 'Y-m-t' ), |
|
261 | + ); |
|
262 | + |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Retrieves last month's date range. |
|
267 | + * |
|
268 | + * @return array The appropriate date range. |
|
269 | + */ |
|
270 | + public function get_last_month_date_range() { |
|
271 | + |
|
272 | + // Set the previous date range. |
|
273 | + $this->previous_range = array( |
|
274 | + 'period' => 'custom', |
|
275 | + 'after' => gmdate( 'Y-m-01', strtotime( '-2 months' ) ), |
|
276 | + 'before' => gmdate( 'Y-m-t', strtotime( '-2 months' ) ), |
|
277 | + ); |
|
278 | + |
|
279 | + // Generate the report. |
|
280 | + return array( |
|
281 | + 'after' => gmdate( 'Y-m-01', strtotime( 'last month' ) ), |
|
282 | + 'before' => gmdate( 'Y-m-t', strtotime( 'last month' ) ), |
|
283 | + ); |
|
284 | + |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * Retrieves this quarter date range. |
|
289 | + * |
|
290 | + * @return array The available quarters. |
|
291 | + */ |
|
292 | + public function get_quarters() { |
|
293 | + |
|
294 | + $year = (int) gmdate( 'Y' ); |
|
295 | + $last_year = (int) $year - 1; |
|
296 | + return array( |
|
297 | + |
|
298 | + // Third quarter of previous year: July 1st to September 30th |
|
299 | + array( |
|
300 | + 'before' => "{$last_year}-09-30", |
|
301 | + 'after' => "{$last_year}-07-01", |
|
302 | + ), |
|
303 | + |
|
304 | + // Last quarter of previous year: October 1st to December 31st |
|
305 | + array( |
|
306 | + 'before' => "{$last_year}-12-31", |
|
307 | + 'after' => "{$last_year}-10-01", |
|
308 | + ), |
|
309 | + |
|
310 | + // First quarter: January 1st to March 31st |
|
311 | + array( |
|
312 | + 'before' => "{$year}-03-31", |
|
313 | + 'after' => "{$year}-01-01", |
|
314 | + ), |
|
315 | + |
|
316 | + // Second quarter: April 1st to June 30th |
|
317 | + array( |
|
318 | + 'before' => "{$year}-06-30", |
|
319 | + 'after' => "{$year}-04-01", |
|
320 | + ), |
|
321 | + |
|
322 | + // Third quarter: July 1st to September 30th |
|
323 | + array( |
|
324 | + 'before' => "{$year}-09-30", |
|
325 | + 'after' => "{$year}-07-01", |
|
326 | + ), |
|
327 | + |
|
328 | + // Fourth quarter: October 1st to December 31st |
|
329 | + array( |
|
330 | + 'before' => "{$year}-12-31", |
|
331 | + 'after' => "{$year}-10-01", |
|
332 | + ), |
|
333 | + ); |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * Retrieves the current quater. |
|
338 | + * |
|
339 | + * @return int The current quarter. |
|
340 | + */ |
|
341 | + public function get_quarter() { |
|
342 | + |
|
343 | + $month = (int) gmdate( 'n' ); |
|
344 | + $quarters = array( 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4 ); |
|
345 | + return $quarters[ $month - 1 ]; |
|
346 | + |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * Retrieves this quarter date range. |
|
351 | + * |
|
352 | + * @return array The appropriate date range. |
|
353 | + */ |
|
354 | + public function get_quarter_date_range() { |
|
355 | + |
|
356 | + // Set the previous date range. |
|
357 | + $this->previous_range = array( |
|
358 | + 'period' => 'last_quarter', |
|
359 | + ); |
|
360 | + |
|
361 | + // Generate the report. |
|
362 | + $quarter = $this->get_quarter(); |
|
363 | + $quarters = $this->get_quarters(); |
|
364 | + return $quarters[ $quarter + 1 ]; |
|
365 | + |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Retrieves last quarter's date range. |
|
370 | + * |
|
371 | + * @return array The appropriate date range. |
|
372 | + */ |
|
373 | + public function get_last_quarter_date_range() { |
|
374 | + |
|
375 | + $quarters = $this->get_quarters(); |
|
376 | + $quarter = $this->get_quarter(); |
|
377 | + |
|
378 | + // Set the previous date range. |
|
379 | + $this->previous_range = array_merge( |
|
380 | + $quarters[ $quarter - 1 ], |
|
381 | + array( 'period' => 'custom' ) |
|
382 | + ); |
|
383 | + |
|
384 | + // Generate the report. |
|
385 | + return $quarters[ $quarter ]; |
|
386 | + |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Retrieves this year date range. |
|
391 | + * |
|
392 | + * @return array The appropriate date range. |
|
393 | + */ |
|
394 | + public function get_year_date_range() { |
|
395 | + |
|
396 | + // Set the previous date range. |
|
397 | + $this->previous_range = array( |
|
398 | + 'period' => 'last_year', |
|
399 | + ); |
|
400 | + |
|
401 | + // Generate the report. |
|
402 | + return array( |
|
403 | + 'after' => gmdate( 'Y-01-01' ), |
|
404 | + 'before' => gmdate( 'Y-12-31' ), |
|
405 | + ); |
|
406 | + |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * Retrieves last year date range. |
|
411 | + * |
|
412 | + * @return array The appropriate date range. |
|
413 | + */ |
|
414 | + public function get_last_year_date_range() { |
|
415 | + |
|
416 | + // Set the previous date range. |
|
417 | + $this->previous_range = array( |
|
418 | + 'period' => 'custom', |
|
419 | + 'after' => gmdate( 'Y-01-01', strtotime( '-2 years' ) ), |
|
420 | + 'before' => gmdate( 'Y-12-31', strtotime( '-2 years' ) ), |
|
421 | + ); |
|
422 | + |
|
423 | + // Generate the report. |
|
424 | + return array( |
|
425 | + 'after' => gmdate( 'Y-01-01', strtotime( 'last year' ) ), |
|
426 | + 'before' => gmdate( 'Y-12-31', strtotime( 'last year' ) ), |
|
427 | + ); |
|
428 | + |
|
429 | + } |
|
430 | + |
|
431 | + /** |
|
432 | + * Prepare a the request date for SQL usage. |
|
433 | + * |
|
434 | + * @param WP_REST_Request $request Request object. |
|
435 | + * @param string $date_field The date field. |
|
436 | + * @return string The appropriate SQL. |
|
437 | + */ |
|
438 | + public function get_date_range_sql( $request, $date_field ) { |
|
439 | + global $wpdb; |
|
440 | + |
|
441 | + $sql = '1=1'; |
|
442 | + $range = $this->get_date_range( $request ); |
|
443 | + |
|
444 | + if ( ! empty( $range['after'] ) ) { |
|
445 | + $sql .= ' AND ' . $wpdb->prepare( |
|
446 | + "$date_field >= %s", |
|
447 | + $range['after'] |
|
448 | + ); |
|
449 | + } |
|
450 | + |
|
451 | + if ( ! empty( $range['before'] ) ) { |
|
452 | + $sql .= ' AND ' . $wpdb->prepare( |
|
453 | + "$date_field <= %s", |
|
454 | + $range['before'] |
|
455 | + ); |
|
456 | + } |
|
457 | + |
|
458 | + return $sql; |
|
459 | + |
|
460 | + } |
|
461 | + |
|
462 | + /** |
|
463 | + * Prepares a group by query. |
|
464 | + * |
|
465 | + * @param string $date_field The date field. |
|
466 | + * @return string The appropriate SQL. |
|
467 | + */ |
|
468 | + public function get_group_by_sql( $date_field ) { |
|
469 | + |
|
470 | + if ( 'day' === $this->groupby ) { |
|
471 | + return "YEAR($date_field), MONTH($date_field), DAY($date_field)"; |
|
472 | + } |
|
473 | + |
|
474 | + return "YEAR($date_field), MONTH($date_field)"; |
|
475 | + } |
|
476 | + |
|
477 | + /** |
|
478 | + * Get the query params for collections. |
|
479 | + * |
|
480 | + * @return array |
|
481 | + */ |
|
482 | + public function get_collection_params() { |
|
483 | + return array( |
|
484 | + 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
485 | + 'period' => array( |
|
486 | + 'description' => __( 'Limit to results of a specific period.', 'invoicing' ), |
|
487 | + 'type' => 'string', |
|
488 | + 'enum' => array( 'custom', 'today', 'yesterday', 'week', 'last_week', '7_days', '30_days', '60_days', '90_days', '180_days', 'month', 'last_month', 'quarter', 'last_quarter', 'year', 'last_year', 'quarter', 'last_quarter' ), |
|
489 | + 'validate_callback' => 'rest_validate_request_arg', |
|
490 | + 'sanitize_callback' => 'sanitize_text_field', |
|
491 | + 'default' => '7_days', |
|
492 | + ), |
|
493 | + 'after' => array( |
|
494 | + /* translators: %s: date format */ |
|
495 | + 'description' => sprintf( __( 'Limit to results after a specific date, the date needs to be in the %s format.', 'invoicing' ), 'YYYY-MM-DD' ), |
|
496 | + 'type' => 'string', |
|
497 | + 'validate_callback' => 'rest_validate_request_arg', |
|
498 | + 'sanitize_callback' => 'sanitize_text_field', |
|
499 | + 'default' => gmdate( 'Y-m-d', strtotime( '-7 days' ) ), |
|
500 | + ), |
|
501 | + 'before' => array( |
|
502 | + /* translators: %s: date format */ |
|
503 | + 'description' => sprintf( __( 'Limit to results before a specific date, the date needs to be in the %s format.', 'invoicing' ), 'YYYY-MM-DD' ), |
|
504 | + 'type' => 'string', |
|
505 | + 'validate_callback' => 'rest_validate_request_arg', |
|
506 | + 'sanitize_callback' => 'sanitize_text_field', |
|
507 | + 'default' => gmdate( 'Y-m-d' ), |
|
508 | + ), |
|
509 | + ); |
|
510 | + } |
|
511 | 511 | } |