PluginProbe
Powerkit – Supercharge your WordPress Site / 2.4.4
Powerkit – Supercharge your WordPress Site v2.4.4
3.1.1 3.1.0 3.0.9 3.0.8 trunk 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 All 87 releases
powerkit / modules / share-buttons / admin / class-powerkit-share-buttons-admin.php

class-powerkit-share-buttons-admin.php in Powerkit – Supercharge your WordPress Site 2.4.4, at modules/share-buttons/admin/class-powerkit-share-buttons-admin.php

644 lines 29.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The admin-specific functionality of the module.
4 *
5 * @link https://codesupply.co
6 * @since 1.0.0
7 *
8 * @package Powerkit
9 * @subpackage Modules/Admin
10 */
11
12 /**
13 * The admin-specific functionality of the module.
14 */
15 class Powerkit_Share_Buttons_Admin extends Powerkit_Module_Admin {
16
17 /**
18 * Initialize
19 */
20 public function initialize() {
21 add_action( 'init', array( $this, 'register_options_default' ) );
22 add_action( 'admin_menu', array( $this, 'register_options_page' ) );
23 add_filter( 'powerkit_ajax_reset_cache', array( $this, 'register_reset_cache' ) );
24 }
25
26
27 /**
28 * Register Reset Cache
29 *
30 * @since 1.0.0
31 * @param array $list Change list reset cache.
32 * @access private
33 */
34 public function register_reset_cache( $list ) {
35 $slug = powerkit_get_page_slug( $this->slug );
36
37 $list[ $slug ] = array(
38 'powerkit_share_buttons_transient',
39 );
40
41 return $list;
42 }
43
44 /**
45 * Register options default
46 *
47 * @since 1.0.0
48 */
49 public function register_options_default() {
50
51 // Save options default [locations].
52 $locations = apply_filters( 'powerkit_share_buttons_locations', array() );
53
54 if ( $locations ) {
55 foreach ( $locations as $key => $item ) {
56 $location = $item['location'];
57
58 add_filter(
59 "default_option_powerkit_share_buttons_{$location}_display", function ( $default ) use ( $item ) {
60 return isset( $item['display'] ) ? $item['display'] : $default;
61 }
62 );
63 add_filter(
64 "default_option_powerkit_share_buttons_{$location}_multiple_list", function ( $default ) use ( $item ) {
65 return isset( $item['shares'] ) ? (array) $item['shares'] : $default;
66 }
67 );
68 add_filter(
69 "default_option_powerkit_share_buttons_{$location}_order_multiple_list", function ( $default ) use ( $item ) {
70 return isset( $item['shares'] ) ? (array) $item['shares'] : $default;
71 }
72 );
73 add_filter(
74 "default_option_powerkit_share_buttons_{$location}_display_labels", function ( $default ) use ( $item ) {
75 return isset( $item['meta']['labels'] ) ? $item['meta']['labels'] : true;
76 }
77 );
78 add_filter(
79 "default_option_powerkit_share_buttons_{$location}_display_total_share_count", function ( $default ) use ( $item ) {
80 return isset( $item['display_total'] ) ? $item['display_total'] : true;
81 }
82 );
83 add_filter(
84 "default_option_powerkit_share_buttons_{$location}_display_count", function ( $default ) use ( $item ) {
85 return isset( $item['display_count'] ) ? $item['display_count'] : true;
86 }
87 );
88 add_filter(
89 "default_option_powerkit_share_buttons_{$location}_title_location", function ( $default ) use ( $item ) {
90 return isset( $item['title_location'] ) ? $item['title_location'] : $default;
91 }
92 );
93 add_filter(
94 "default_option_powerkit_share_buttons_{$location}_label_location", function ( $default ) use ( $item ) {
95 return isset( $item['label_location'] ) ? $item['label_location'] : $default;
96 }
97 );
98 add_filter(
99 "default_option_powerkit_share_buttons_{$location}_count_location", function ( $default ) use ( $item ) {
100 return isset( $item['count_location'] ) ? $item['count_location'] : $default;
101 }
102 );
103 add_filter(
104 "default_option_powerkit_share_buttons_{$location}_layout", function ( $default ) use ( $item ) {
105 return isset( $item['layout'] ) ? $item['layout'] : $default;
106 }
107 );
108 add_filter(
109 "default_option_powerkit_share_buttons_{$location}_scheme", function ( $default ) use ( $item ) {
110 return isset( $item['scheme'] ) ? $item['scheme'] : $default;
111 }
112 );
113 }
114 }
115 }
116
117 /**
118 * Register admin page
119 *
120 * @since 1.0.0
121 */
122 public function register_options_page() {
123 add_options_page( esc_html__( 'Share Buttons', 'powerkit' ), esc_html__( 'Share Buttons', 'powerkit' ), 'manage_options', powerkit_get_page_slug( $this->slug ), array( $this, 'build_options_page' ) );
124 }
125
126
127 /**
128 * Build admin page
129 *
130 * @since 1.0.0
131 */
132 public function build_options_page() {
133
134 if ( ! current_user_can( 'manage_options' ) ) {
135 wp_die( esc_html__( 'You do not have sufficient rights to view this page.', 'powerkit' ) );
136 }
137
138 $this->save_options_page();
139 ?>
140
141 <div class="wrap pk-share-buttons-wrap">
142 <h1><?php esc_html_e( 'Share Buttons', 'powerkit' ); ?></h1>
143
144 <div class="pk-share-buttons-settings">
145 <?php $locations = apply_filters( 'powerkit_share_buttons_locations', array() ); ?>
146
147 <?php if ( $locations ) : ?>
148 <form class="pk-share-buttons-basic" method="post">
149 <div class="pk-share-buttons-tabs">
150 <?php
151 $locations = array_values( $locations );
152
153 $tab = isset( $_GET['tab'] ) ? esc_attr( $_GET['tab'] ) : $locations[0]['location']; // Input var ok; sanitization ok.
154 ?>
155
156 <nav class="nav-tab-wrapper woo-nav-tab-wrapper">
157 <?php
158 foreach ( $locations as $item ) {
159 $class = ( $item['location'] === $tab ) ? 'nav-tab-active' : ''; // Input var ok.
160
161 printf(
162 '<a class="nav-tab %4$s" href="%1$s&tab=%2$s">%3$s</a>',
163 esc_url( powerkit_get_page_url( $this->slug ) ), esc_attr( $item['location'] ), esc_html( $item['name'] ), esc_attr( $class )
164 );
165 }
166 ?>
167
168 <a class="nav-tab nav-tab-advanced <?php echo esc_attr( 'advanced-settings' === $tab ? 'nav-tab-active' : '' ); ?>"
169 href="<?php echo esc_url( powerkit_get_page_url( $this->slug ) ); ?>&tab=<?php echo esc_attr( 'advanced-settings' ); ?>">
170 <?php esc_html_e( 'Advanced Settings', 'powerkit' ); ?>
171 </a>
172 </nav>
173
174 <?php
175 foreach ( $locations as $item ) {
176 if ( $item['location'] === $tab ) { // Input var ok.
177 $location = $item['location'];
178 ?>
179 <div id="tab-<?php echo esc_attr( $location ); ?>" class="tab-wrap">
180 <table class="form-table">
181 <tbody>
182 <!-- Display Share Buttons -->
183 <tr class="visible">
184 <th scope="row"><label for="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display"><?php esc_html_e( 'Display Share Buttons', 'powerkit' ); ?></label></th>
185 <td><input class="powerkit_share_buttons_display" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display" type="checkbox" value="true" <?php checked( (bool) get_option( "powerkit_share_buttons_{$location}_display", false ) ); ?>></td>
186 </tr>
187
188 <!-- Share Buttons -->
189 <tr>
190 <th scope="row"><?php esc_html_e( 'Share Buttons', 'powerkit' ); ?></label></th>
191 <td>
192 <div class="pk-share-buttons-source">
193 <?php
194 $accounts = powerkit_share_buttons_get_accounts();
195
196 if ( $accounts ) {
197 foreach ( $accounts as $key => $account ) {
198
199 // Check support accounts for extra locations.
200 if ( 'highlight-text' === $location || 'blockquote' === $location ) {
201 $list = powerkit_share_buttons_support_text_accounts();
202
203 if ( ! in_array( $key, $list, true ) ) {
204 continue;
205 }
206 }
207
208 $powerkit_share_buttons_multiple_list = get_option( "powerkit_share_buttons_{$location}_multiple_list", array() );
209
210 $checked = in_array( $key, $powerkit_share_buttons_multiple_list, true ) ? 'checked' : '';
211 ?>
212 <p class="share-item">
213 <label for="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_multiple_list_<?php echo esc_attr( $key ); ?>"><input class="powerkit_share_buttons_multiple_list" data-item="<?php echo esc_attr( $key ); ?>" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_multiple_list_<?php echo esc_attr( $key ); ?>" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_multiple_list[]" type="checkbox" value="<?php echo esc_attr( $key ); ?>" <?php echo esc_attr( $checked ); ?>> <?php echo esc_attr( $account['name'] ); ?></label>
214
215 <?php if ( in_array( $key, array( 'whatsapp', 'fb-messenger' ), true ) ) : ?>
216 <code class="description"><?php esc_html_e( '[mobile only]', 'powerkit' ); ?></code>
217 <?php endif; ?>
218 </p>
219 <?php
220 }
221 }
222 ?>
223 </div>
224 </td>
225 </tr>
226
227 <!-- Order -->
228 <tr>
229 <th scope="row"><label for="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_order_multiple_list"><?php esc_html_e( 'Order', 'powerkit' ); ?></label></th>
230 <td>
231 <ul class="social-sortable">
232 <?php
233 $accounts_save = get_option( "powerkit_share_buttons_{$location}_order_multiple_list", array() );
234
235 $accounts = powerkit_share_buttons_get_accounts();
236
237 // Sort.
238 if ( $accounts_save && $accounts ) {
239 $accounts_save = array_flip( $accounts_save );
240 $accounts = array_merge( $accounts_save, $accounts );
241 }
242
243 // Output.
244 if ( $accounts ) {
245 foreach ( $accounts as $key => $account ) {
246
247 // Check support accounts for extra locations.
248 if ( 'highlight-text' === $location || 'blockquote' === $location ) {
249 $list = powerkit_share_buttons_support_text_accounts();
250
251 if ( ! in_array( $key, $list, true ) ) {
252 continue;
253 }
254 }
255 ?>
256 <li class="ui-state-default <?php echo esc_attr( $key ); ?>">
257 <span class="dashicons dashicons-leftright"></span>
258 <input type="text" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_order_multiple_list[]" value="<?php echo esc_attr( $key ); ?>"><?php echo esc_attr( $account['name'] ); ?>
259 </li>
260 <?php
261 }
262 }
263 ?>
264 </ul>
265 </td>
266 </tr>
267
268 <!-- Display Labels -->
269 <?php if ( isset( $item['meta']['labels'] ) ? $item['meta']['labels'] : true ) : ?>
270 <tr>
271 <th scope="row"><label for="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display_labels"><?php esc_html_e( 'Display Labels', 'powerkit' ); ?></label></th>
272 <td><input id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display_labels" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display_labels" type="checkbox" value="true" <?php checked( (bool) get_option( "powerkit_share_buttons_{$location}_display_labels", true ) ); ?>></td>
273 </tr>
274 <?php endif; ?>
275
276 <!-- Display Total Share Count -->
277 <?php if ( isset( $item['fields']['display_total'] ) && $item['fields']['display_total'] ) : ?>
278 <tr>
279 <th scope="row"><label for="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display_total_share_count"><?php esc_html_e( 'Display Total Share Count', 'powerkit' ); ?></label></th>
280 <td><input id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display_total_share_count" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display_total_share_count" type="checkbox" value="true" <?php checked( (bool) get_option( "powerkit_share_buttons_{$location}_display_total_share_count", false ) ); ?>></td>
281 </tr>
282 <?php endif; ?>
283
284 <!-- Display Counts -->
285 <?php if ( isset( $item['fields']['display_count'] ) && $item['fields']['display_count'] ) : ?>
286 <tr>
287 <th scope="row"><label for="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display_count"><?php esc_html_e( 'Display Counts', 'powerkit' ); ?></label></th>
288 <td><input id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display_count" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display_count" type="checkbox" value="true" <?php checked( (bool) get_option( "powerkit_share_buttons_{$location}_display_count", false ) ); ?>></td>
289 </tr>
290 <?php endif; ?>
291
292 <!-- Title Location -->
293 <?php
294 if ( isset( $item['meta']['titles'] ) ? $item['meta']['titles'] : false ) {
295
296 $title_location = isset( $item['fields']['title_locations'] ) ? (array) $item['fields']['title_locations'] : array( 'inside', 'outside' );
297
298 if ( in_array( 'inside', $title_location, true ) && in_array( 'outside', $title_location, true ) ) {
299 ?>
300 <tr>
301 <th scope="row"><?php esc_html_e( 'Title Location', 'powerkit' ); ?></th>
302 <td>
303 <label>
304 <input type="radio" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_title_location" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_title_location" value="inside" <?php checked( get_option( "powerkit_share_buttons_{$location}_title_location", 'inside' ), 'inside' ); ?>>
305 <?php esc_html_e( 'Inside', 'powerkit' ); ?>&nbsp;
306 </label>
307 <label>
308 <input type="radio" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_title_location" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_title_location" value="outside" <?php checked( get_option( "powerkit_share_buttons_{$location}_title_location", 'inside' ), 'outside' ); ?>>
309 <?php esc_html_e( 'Outside', 'powerkit' ); ?>&nbsp;
310 </label>
311 </td>
312 </tr>
313 <?php
314 }
315 }
316 ?>
317
318 <!-- Label Location -->
319 <?php
320 if ( isset( $item['meta']['labels'] ) ? $item['meta']['labels'] : true ) {
321
322 $label_location = isset( $item['fields']['label_locations'] ) ? (array) $item['fields']['label_locations'] : array( 'inside', 'outside' );
323
324 if ( in_array( 'inside', $label_location, true ) && in_array( 'outside', $label_location, true ) ) {
325 ?>
326 <tr>
327 <th scope="row"><?php esc_html_e( 'Label Location', 'powerkit' ); ?></th>
328 <td>
329 <label>
330 <input type="radio" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_label_location" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_label_location" value="inside" <?php checked( get_option( "powerkit_share_buttons_{$location}_label_location", 'inside' ), 'inside' ); ?>>
331 <?php esc_html_e( 'Inside', 'powerkit' ); ?>&nbsp;
332 </label>
333 <label>
334 <input type="radio" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_label_location" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_label_location" value="outside" <?php checked( get_option( "powerkit_share_buttons_{$location}_label_location", 'inside' ), 'outside' ); ?>>
335 <?php esc_html_e( 'Outside', 'powerkit' ); ?>&nbsp;
336 </label>
337 </td>
338 </tr>
339 <?php
340 }
341 }
342 ?>
343
344 <!-- Count Location -->
345 <?php
346 $count_location = isset( $item['fields']['count_locations'] ) ? (array) $item['fields']['count_locations'] : array( 'inside', 'outside' );
347
348 if ( in_array( 'inside', $count_location, true ) && in_array( 'outside', $count_location, true ) ) {
349 ?>
350 <tr>
351 <th scope="row"><?php esc_html_e( 'Count Location', 'powerkit' ); ?></th>
352 <td>
353 <label>
354 <input type="radio" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_count_location" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_count_location" value="inside" <?php checked( get_option( "powerkit_share_buttons_{$location}_count_location", 'inside' ), 'inside' ); ?>>
355 <?php esc_html_e( 'Inside', 'powerkit' ); ?>&nbsp;
356 </label>
357 <label>
358 <input type="radio" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_count_location" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_count_location" value="outside" <?php checked( get_option( "powerkit_share_buttons_{$location}_count_location", 'inside' ), 'outside' ); ?>>
359 <?php esc_html_e( 'Outside', 'powerkit' ); ?>&nbsp;
360 </label>
361 </td>
362 </tr>
363 <?php } ?>
364
365 <!-- Layout -->
366 <?php
367 $layouts = powerkit_share_buttons_format_layouts( $item, $location );
368
369 if ( count( (array) $layouts ) > 1 ) {
370 ?>
371 <tr>
372 <th scope="row"><label for="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_layout"><?php esc_html_e( 'Layout', 'powerkit' ); ?></label></th>
373 <td>
374 <select class="regular-text" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_layout" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_layout">
375 <?php
376 if ( $layouts ) {
377 foreach ( $layouts as $key => $i ) {
378 ?>
379 <option value="<?php echo esc_attr( $key ); ?>" <?php selected( get_option( "powerkit_share_buttons_{$location}_layout" ), $key ); ?>><?php echo esc_attr( $i['name'] ); ?></option>
380 <?php
381 }
382 }
383 ?>
384 </select>
385 </td>
386 </tr>
387 <?php } ?>
388
389 <!-- Color Scheme -->
390 <?php
391 $schemes = powerkit_share_buttons_format_color_schemes( $item );
392
393 if ( count( (array) $schemes ) > 1 ) {
394 ?>
395 <tr>
396 <th scope="row"><label for="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_scheme"><?php esc_html_e( 'Color Scheme', 'powerkit' ); ?></label></th>
397 <td>
398 <select class="regular-text" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_scheme" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_scheme">
399 <?php
400 if ( $schemes ) {
401 foreach ( $schemes as $key => $i ) {
402 ?>
403 <option value="<?php echo esc_attr( $key ); ?>" <?php selected( get_option( "powerkit_share_buttons_{$location}_scheme" ), $key ); ?>><?php echo esc_attr( $i['name'] ); ?></option>
404 <?php
405 }
406 }
407 ?>
408 </select>
409 </td>
410 </tr>
411 <?php } ?>
412 </tbody>
413 </table>
414
415 <input type="hidden" name="<?php echo esc_attr( "powerkit_share_buttons_action_{$location}" ); ?>" value="true">
416 </div>
417 <?php
418 }
419 }
420 ?>
421
422 <?php if ( 'advanced-settings' === $tab ) { ?>
423 <div id="tab-advanced-settings" class="tab-wrap">
424 <input type="hidden" name="advanced_settings" value="1">
425 <!-- Share Labels -->
426 <h3><?php esc_html_e( 'Share Labels', 'powerkit' ); ?></h3>
427 <table class="form-table">
428 <tbody>
429 <?php
430 $accounts = apply_filters( 'powerkit_share_buttons_accounts', array(), null, null );
431
432 foreach ( $accounts as $key => $account ) {
433 ?>
434 <tr class="visible simple">
435 <th scope="row">
436 <label for="powerkit_share_buttons_label_<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $account['name'] ); ?></label>
437 </th>
438 <td>
439 <input class="regular-text" id="powerkit_share_buttons_label_<?php echo esc_attr( $key ); ?>" name="powerkit_share_buttons_label_<?php echo esc_attr( $key ); ?>" type="text" value="<?php echo esc_attr( get_option( "powerkit_share_buttons_label_{$key}", $account['label'] ) ); ?>">
440 </td>
441 </tr>
442 <?php
443 }
444 ?>
445 </tbody>
446 </table>
447
448 <hr>
449
450 <!-- Recover social counts -->
451 <h3><?php esc_html_e( 'Recover social counts', 'powerkit' ); ?></h3>
452 <p class="description"><?php esc_html_e( 'If enabled, the total share count will be displayed for both http and https versions of a page', 'powerkit' ); ?></p>
453 <table class="form-table">
454 <tbody>
455 <tr class="visible">
456 <th scope="row">
457 <label for="powerkit_share_buttons_recover"><?php esc_html_e( 'Enable recover counts', 'powerkit' ); ?></label>
458 </th>
459 <td><input class="powerkit_share_buttons_recover" id="powerkit_share_buttons_recover" name="powerkit_share_buttons_recover" type="checkbox" value="true" <?php checked( (bool) get_option( 'powerkit_share_buttons_recover', false ) ); ?>></td>
460 </tr>
461 </tbody>
462 </table>
463
464 <hr>
465
466 <!-- Bitly Link Shortening -->
467 <h3><?php esc_html_e( 'Bitly Link Shortening', 'powerkit' ); ?></h3>
468 <p class="description"><?php esc_html_e( 'If you like to have all of your links automatically shortened, enter your Access Token from bitly.com', 'powerkit' ); ?></p>
469
470 <div class="form-field">
471 <h4><?php esc_html_e( 'Instructions', 'powerkit' ); ?></h4>
472 <ol>
473 <li><?php esc_html_e( 'Log in to your', 'powerkit' ); ?> <?php echo sprintf( '<a href="%1$s" target="_blank">%2$s</a>', esc_url( 'https://bitly.com/' ), esc_html__( 'Bitly account', 'powerkit' ) ); ?></li>
474 <li><?php esc_html_e( 'Go to Settings → Advanced Settings → FOR DEVELOPERS OAuth → Generic Access Token', 'powerkit' ); ?></li>
475 <li><?php esc_html_e( 'Generate your Token', 'powerkit' ); ?></li>
476 <li><?php esc_html_e( 'Copy your "Token"', 'powerkit' ); ?></li>
477 </ol>
478 </div>
479 <table class="form-table">
480 <tbody>
481 <tr class="visible">
482 <th scope="row">
483 <label for="powerkit_share_buttons_bitly_api_token"><?php esc_html_e( 'Bitly API Token', 'powerkit' ); ?></label>
484 </th>
485 <td><input id="powerkit_share_buttons_bitly_api_token" class="regular-text" name="powerkit_share_buttons_bitly_api_token" type="text" value="<?php echo esc_attr( get_option( 'powerkit_share_buttons_bitly_api_token' ) ); ?>"></td>
486 </tr>
487 </tbody>
488 </table>
489 </div>
490 <?php } ?>
491 </div>
492
493 <?php wp_nonce_field(); ?>
494
495 <p class="submit">
496 <input class="button button-primary" name="save_settings" type="submit" value="<?php esc_html_e( 'Save changes', 'powerkit' ); ?>" />
497 </p>
498 </form>
499 <?php else : ?>
500 <p class="submit">
501 <?php esc_html_e( 'No available locations found.', 'powerkit' ); ?>
502 </p>
503 <?php endif; ?>
504 </div>
505 </div>
506 <?php
507 }
508
509 /**
510 * Settings save
511 *
512 * @since 1.0.0
513 */
514 protected function save_options_page() {
515 if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'] ) ) { // Input var ok; sanitization ok.
516 return;
517 }
518
519 if ( isset( $_POST['save_settings'] ) ) { // Input var ok.
520
521 // Save social buttons [locations].
522 $locations = apply_filters( 'powerkit_share_buttons_locations', array() );
523
524 if ( $locations ) {
525 foreach ( $locations as $key => $item ) {
526 $location = $item['location'];
527
528 if ( ! isset( $_POST[ "powerkit_share_buttons_action_{$location}" ] ) ) { // Input var ok.
529 continue;
530 }
531
532 if ( isset( $_POST[ "powerkit_share_buttons_{$location}_display" ] ) ) { // Input var ok.
533 update_option( "powerkit_share_buttons_{$location}_display", true );
534 } else {
535 update_option( "powerkit_share_buttons_{$location}_display", false );
536 }
537
538 if ( isset( $_POST[ "powerkit_share_buttons_{$location}_multiple_list" ] ) ) { // Input var ok.
539 update_option( "powerkit_share_buttons_{$location}_multiple_list", $_POST[ "powerkit_share_buttons_{$location}_multiple_list" ] ); // Input var ok; sanitization ok.
540 } else {
541 update_option( "powerkit_share_buttons_{$location}_multiple_list", array() );
542 }
543
544 if ( isset( $_POST[ "powerkit_share_buttons_{$location}_order_multiple_list" ] ) ) { // Input var ok.
545 update_option( "powerkit_share_buttons_{$location}_order_multiple_list", (array) $_POST[ "powerkit_share_buttons_{$location}_order_multiple_list" ] ); // Input var ok; sanitization ok.
546 } else {
547 update_option( "powerkit_share_buttons_{$location}_order_multiple_list", array() );
548 }
549
550 if ( isset( $_POST[ "powerkit_share_buttons_{$location}_title_location" ] ) ) { // Input var ok.
551 update_option( "powerkit_share_buttons_{$location}_title_location", sanitize_text_field( wp_unslash( $_POST[ "powerkit_share_buttons_{$location}_title_location" ] ) ) ); // Input var ok.
552 }
553
554 if ( isset( $_POST[ "powerkit_share_buttons_{$location}_label_location" ] ) ) { // Input var ok.
555 update_option( "powerkit_share_buttons_{$location}_label_location", sanitize_text_field( wp_unslash( $_POST[ "powerkit_share_buttons_{$location}_label_location" ] ) ) ); // Input var ok.
556 }
557
558 if ( isset( $_POST[ "powerkit_share_buttons_{$location}_count_location" ] ) ) { // Input var ok.
559 update_option( "powerkit_share_buttons_{$location}_count_location", sanitize_text_field( wp_unslash( $_POST[ "powerkit_share_buttons_{$location}_count_location" ] ) ) ); // Input var ok.
560 }
561
562 if ( isset( $_POST[ "powerkit_share_buttons_{$location}_layout" ] ) ) { // Input var ok.
563 update_option( "powerkit_share_buttons_{$location}_layout", sanitize_text_field( wp_unslash( $_POST[ "powerkit_share_buttons_{$location}_layout" ] ) ) ); // Input var ok.
564 }
565
566 if ( isset( $_POST[ "powerkit_share_buttons_{$location}_scheme" ] ) ) { // Input var ok.
567 update_option( "powerkit_share_buttons_{$location}_scheme", sanitize_text_field( wp_unslash( $_POST[ "powerkit_share_buttons_{$location}_scheme" ] ) ) ); // Input var ok.
568 }
569
570 if ( isset( $item['meta']['labels'] ) ? $item['meta']['labels'] : true ) {
571 if ( isset( $_POST[ "powerkit_share_buttons_{$location}_display_labels" ] ) ) { // Input var ok.
572 update_option( "powerkit_share_buttons_{$location}_display_labels", true );
573 } else {
574 update_option( "powerkit_share_buttons_{$location}_display_labels", false );
575 }
576 }
577
578 if ( isset( $item['fields']['display_total'] ) && $item['fields']['display_total'] ) {
579 if ( isset( $_POST[ "powerkit_share_buttons_{$location}_display_total_share_count" ] ) ) { // Input var ok.
580 update_option( "powerkit_share_buttons_{$location}_display_total_share_count", true );
581 } else {
582 update_option( "powerkit_share_buttons_{$location}_display_total_share_count", false );
583 }
584 }
585
586 if ( isset( $item['fields']['display_count'] ) && $item['fields']['display_count'] ) {
587 if ( isset( $_POST[ "powerkit_share_buttons_{$location}_display_count" ] ) ) { // Input var ok.
588 update_option( "powerkit_share_buttons_{$location}_display_count", true );
589 } else {
590 update_option( "powerkit_share_buttons_{$location}_display_count", false );
591 }
592 }
593 }
594 }
595
596 // Advanced Settings.
597 if ( isset( $_POST['advanced_settings'] ) ) { // Input var ok.
598 $accounts = apply_filters( 'powerkit_share_buttons_accounts', array(), null, null );
599 foreach ( $accounts as $key => $account ) {
600 if ( isset( $_POST[ "powerkit_share_buttons_label_{$key}" ] ) ) { // Input var ok.
601 update_option( "powerkit_share_buttons_label_{$key}", sanitize_text_field( wp_unslash( $_POST[ "powerkit_share_buttons_label_{$key}" ] ) ) ); // Input var ok.
602 }
603 }
604
605 if ( isset( $_POST['powerkit_share_buttons_recover'] ) ) { // Input var ok.
606 update_option( 'powerkit_share_buttons_recover', true );
607 } else {
608 update_option( 'powerkit_share_buttons_recover', false );
609 }
610 if ( isset( $_POST['powerkit_share_buttons_bitly_api_token'] ) ) { // Input var ok.
611 update_option( 'powerkit_share_buttons_bitly_api_token', sanitize_text_field( wp_unslash( $_POST['powerkit_share_buttons_bitly_api_token'] ) ) ); // Input var ok.
612 }
613 }
614
615 // Reset cache.
616 Powerkit_Connect::reset_cache(
617 array(
618 'powerkit_share_buttons_count',
619 'powerkit_share_buttons_transient',
620 )
621 );
622
623 printf( '<div id="message" class="updated fade"><p><strong>%s</strong></p></div>', esc_html__( 'Settings saved.', 'powerkit' ) );
624 }
625 }
626
627 /**
628 * Register the stylesheets and JavaScript for the admin area.
629 *
630 * @param string $page Current page.
631 */
632 public function admin_enqueue_scripts( $page ) {
633 if ( 'settings_page_' . powerkit_get_page_slug( $this->slug ) === $page ) {
634 wp_enqueue_script( 'jquery-ui-sortable' );
635
636 // Styles.
637 wp_enqueue_style( 'powerkit-share-buttons', powerkit_style( plugin_dir_url( __FILE__ ) . 'css/admin-powerkit-share-buttons.css' ), array(), powerkit_get_setting( 'version' ), 'all' );
638
639 // Scripts.
640 wp_enqueue_script( 'powerkit-share-buttons', plugin_dir_url( __FILE__ ) . 'js/admin-powerkit-share-buttons.js', array( 'jquery' ), powerkit_get_setting( 'version' ), false );
641 }
642 }
643 }
644