PluginProbe ʕ •ᴥ•ʔ
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More / 2.10.0
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More v2.10.0
2.11.0 2.10.0 2.9.0 2.8.0 2.7.0 2.6.7 2.6.8 2.6.5 2.6.4 2.6.3 2.6.2 2.6.0 2.5.5 2.5.4 2.5.3 2.5.2 trunk 1.0 1.0.1 1.0.2 1.0.3 1.1 1.1.1 1.1.2 1.2.0 2.0 2.1.0 2.1.1 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1
reviews-feed / class / Common / Services / SettingsManagerService.php
reviews-feed / class / Common / Services Last commit date
Upgrade 3 weeks ago CLIService.php 3 weeks ago FeedCacheUpdateService.php 3 weeks ago MigrationReactivationNotice.php 3 weeks ago SBR_Upgrader.php 3 weeks ago SettingsManagerService.php 3 weeks ago ShortcodeService.php 3 weeks ago SiteUrlWatcher.php 3 weeks ago UsageTrackingService.php 3 weeks ago
SettingsManagerService.php
89 lines
1 <?php
2
3 /**
4 * Settings Manager Service
5 */
6
7 namespace SmashBalloon\Reviews\Common\Services;
8
9 if (! defined('ABSPATH')) {
10 exit;
11 }
12
13 use SmashBalloon\Reviews\Common\Builder\SBR_Feed_Saver_Manager;
14 use SmashBalloon\Reviews\Common\Utils\AjaxUtil;
15 use Smashballoon\Stubs\Services\ServiceProvider;
16
17 class SettingsManagerService extends ServiceProvider
18 {
19 private $settings_options = 'sbr_settings';
20
21 public function register(): void
22 {
23 add_action('wp_ajax_sbr_update_settings', [$this, 'ajax_update_settings']);
24 }
25
26 public function ajax_update_settings(): void
27 {
28 check_ajax_referer('sbr-admin', 'nonce');
29
30 if (!sbr_current_user_can('manage_reviews_feed_options')) {
31 wp_send_json_error();
32 }
33
34 unset($_POST['nonce'], $_POST['action']);
35
36 $settings = json_decode(stripslashes($_POST['settings']), true);
37
38 $update_array = $this->sanitize_settings($settings) ;
39
40 foreach ($settings['translations'] as $key => $value) {
41 $update_array['translations'][$key] = sanitize_text_field($value);
42 }
43
44
45 if ($this->update_settings($update_array)) {
46 wp_send_json_success();
47 } else {
48 wp_send_json_error();
49 }
50 }
51
52 public function update_settings($settings): bool
53 {
54 $current_settings = $this->get_settings();
55 $updated_settings = array_merge($current_settings, $settings);
56
57 return update_option($this->settings_options, $updated_settings);
58 }
59
60 public function get_settings(): array
61 {
62 $settings = get_option($this->settings_options, []);
63 // Return type is `array` — coerce corrupted non-array state to [] to
64 // avoid a TypeError and let SMASH-1281's recovery flow re-register.
65 return is_array($settings) ? $settings : [];
66 }
67
68 public function sanitize_settings($data)
69 {
70 $sanitized_and_sorted = [];
71
72 foreach ($data as $key => $value) {
73 $data_type = SBR_Feed_Saver_Manager::get_data_type($key);
74 $sanitized_values = array();
75 if (is_array($value)) {
76 $sanitized_values[] = $value;
77 } elseif (is_object($value)) {
78 $sanitized_values[] = $value;
79 } else {
80 $type = SBR_Feed_Saver_Manager::is_boolean($value) ? 'boolean' : $data_type['sanitization'];
81 $sanitized_values = SBR_Feed_Saver_Manager::sanitize($type, $value);
82 }
83
84 $sanitized_and_sorted[$key] = $sanitized_values;
85 }
86 return $sanitized_and_sorted;
87 }
88 }
89