admin
10 months ago
core
10 months ago
class-activator.php
10 months ago
class-assets.php
11 months ago
class-builder-page.php
1 year ago
class-deactivator.php
3 years ago
class-debug-info.php
2 years ago
class-feed-ajax.php
1 year ago
class-feed-block.php
1 year ago
class-feed-deserializer.php
11 months ago
class-feed-old.php
4 years ago
class-feed-page.php
11 months ago
class-feed-serializer.php
2 years ago
class-feed-shortcode.php
2 years ago
class-feed-widget.php
4 years ago
class-plugin-overview-ajax.php
1 year ago
class-plugin-overview.php
11 months ago
class-plugin-settings.php
10 months ago
class-plugin-support.php
1 year ago
class-plugin.php
11 months ago
class-post-types.php
3 years ago
class-reviews-cron.php
1 year ago
class-settings-save.php
1 year ago
class-view.php
10 months ago
index.php
4 years ago
page-setting-advance.php
1 year ago
page-setting-fig.php
1 year ago
page-setting-support.php
4 years ago
class-plugin-settings.php
179 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WP_Rplg_Google_Reviews\Includes; |
| 4 | |
| 5 | class Plugin_Settings { |
| 6 | |
| 7 | private $builder_page; |
| 8 | private $debug_info; |
| 9 | |
| 10 | public function __construct($builder_page, $debug_info) { |
| 11 | $this->builder_page = $builder_page; |
| 12 | $this->debug_info = $debug_info; |
| 13 | } |
| 14 | |
| 15 | public function register() { |
| 16 | $render_func; |
| 17 | $feed_ids = get_option('grw_feed_ids'); |
| 18 | if (empty($feed_ids)) { |
| 19 | $render_func = array($this, 'connect'); |
| 20 | } else { |
| 21 | $render_func = array($this, 'render'); |
| 22 | } |
| 23 | |
| 24 | add_action('grw_admin_page_grw-settings', array($this, 'init')); |
| 25 | add_action('grw_admin_page_grw-settings', $render_func); |
| 26 | } |
| 27 | |
| 28 | public function init() { |
| 29 | |
| 30 | } |
| 31 | |
| 32 | public function connect() { |
| 33 | $this->builder_page->render(null); |
| 34 | } |
| 35 | |
| 36 | public function render() { |
| 37 | |
| 38 | $tab = isset($_GET['grw_tab']) && strlen($_GET['grw_tab']) > 0 ? sanitize_text_field(wp_unslash($_GET['grw_tab'])) : 'active'; |
| 39 | |
| 40 | $grw_enabled = get_option('grw_active') == '1'; |
| 41 | $async_css = get_option('grw_async_css'); |
| 42 | $grw_demand_assets = get_option('grw_demand_assets'); |
| 43 | $grw_freq_revs_upd = get_option('grw_freq_revs_upd'); |
| 44 | $gpa_old = get_option('grw_gpa_old'); |
| 45 | $grw_google_api_key = get_option('grw_google_api_key'); |
| 46 | $grw_activation_time = get_option('grw_activation_time'); |
| 47 | ?> |
| 48 | |
| 49 | <div class="grw-page-title"> |
| 50 | Settings |
| 51 | </div> |
| 52 | |
| 53 | <?php do_action('grw_admin_notices'); ?> |
| 54 | |
| 55 | <div class="grw-settings-workspace"> |
| 56 | |
| 57 | <div data-nav-tabs=""> |
| 58 | |
| 59 | <div class="nav-tab-wrapper"> |
| 60 | <a href="#grw-general" class="nav-tab<?php if ($tab == 'active') { ?> nav-tab-active<?php } ?>">General</a> |
| 61 | <a href="#grw-google" class="nav-tab<?php if ($tab == 'google') { ?> nav-tab-active<?php } ?>">Google</a> |
| 62 | <a href="#grw-advance" class="nav-tab<?php if ($tab == 'advance') { ?> nav-tab-active<?php } ?>">Advance</a> |
| 63 | </div> |
| 64 | |
| 65 | <div id="grw-general" class="tab-content" style="display:<?php echo $tab == 'active' ? 'block' : 'none'?>;"> |
| 66 | <h3>General Settings</h3> |
| 67 | <form method="post" action="<?php echo esc_url(admin_url('admin-post.php?action=grw_settings_save&grw_tab=active&active=' . (string)((int)($grw_enabled != true)))); ?>"> |
| 68 | <div class="grw-field"> |
| 69 | <div class="grw-field-label"> |
| 70 | <label>Google Reviews plugin is currently <b><?php echo $grw_enabled ? 'enabled' : 'disabled' ?></b></label> |
| 71 | </div> |
| 72 | <div class="wp-review-field-option"> |
| 73 | <?php wp_nonce_field('grw-wpnonce_active', 'grw-form_nonce_active'); ?> |
| 74 | <input type="submit" name="active" class="button" value="<?php echo $grw_enabled ? 'Disable' : 'Enable'; ?>" /> |
| 75 | </div> |
| 76 | </div> |
| 77 | <div class="grw-field"> |
| 78 | <div class="grw-field-label"> |
| 79 | <label>Async CSS assets</label> |
| 80 | </div> |
| 81 | <div class="wp-review-field-option"> |
| 82 | <label> |
| 83 | <input type="hidden" name="grw_async_css" value="false"> |
| 84 | <input type="checkbox" id="grw_async_css" name="grw_async_css" value="true" <?php checked('true', $async_css); ?>> |
| 85 | Asynchronous CSS loads in the background |
| 86 | </label> |
| 87 | </div> |
| 88 | </div> |
| 89 | <div class="grw-field"> |
| 90 | <div class="grw-field-label"> |
| 91 | <label>Load assets on demand</label> |
| 92 | </div> |
| 93 | <div class="wp-review-field-option"> |
| 94 | <label> |
| 95 | <input type="hidden" name="grw_demand_assets" value="false"> |
| 96 | <input type="checkbox" id="grw_demand_assets" name="grw_demand_assets" value="true" <?php checked('true', $grw_demand_assets); ?>> |
| 97 | Load static assets (JS/CSS) only on pages where reviews are showing |
| 98 | </label> |
| 99 | <div style="padding-top:15px"> |
| 100 | <input type="submit" value="Save" name="save" class="button" /> |
| 101 | </div> |
| 102 | </div> |
| 103 | </div> |
| 104 | </form> |
| 105 | </div> |
| 106 | |
| 107 | <div id="grw-google" class="tab-content" style="display:<?php echo $tab == 'google' ? 'block' : 'none'?>;"> |
| 108 | <h3>Google</h3> |
| 109 | <form method="post" action="<?php echo esc_url(admin_url('admin-post.php?action=grw_settings_save&grw_tab=google')); ?>"> |
| 110 | <?php wp_nonce_field('grw-wpnonce_save', 'grw-form_nonce_save'); ?> |
| 111 | <div class="grw-field"> |
| 112 | <div class="grw-field-label"> |
| 113 | <label>Frequency of review updates</label> |
| 114 | </div> |
| 115 | <div class="wp-review-field-option"> |
| 116 | <select name="grw_freq_revs_upd"> |
| 117 | <option value="daily" <?php selected('daily', $grw_freq_revs_upd); ?>>Daily</option> |
| 118 | <option value="weekly" <?php selected('weekly', $grw_freq_revs_upd); ?>>Once weekly</option> |
| 119 | <option value="fortnightly " <?php selected('fortnightly', $grw_freq_revs_upd); ?>>Every two weeks </option> |
| 120 | <option value="monthly" <?php selected('monthly', $grw_freq_revs_upd); ?>>Once monthly</option> |
| 121 | </select> |
| 122 | </div> |
| 123 | </div> |
| 124 | <div class="grw-field"> |
| 125 | <div class="grw-field-label"> |
| 126 | <label>Use old Places API</label> |
| 127 | </div> |
| 128 | <div class="wp-review-field-option"> |
| 129 | <label> |
| 130 | <input type="hidden" name="grw_gpa_old" value="false"> |
| 131 | <input type="checkbox" id="grw_gpa_old" name="grw_gpa_old" value="true" <?php checked('true', $gpa_old); ?>> |
| 132 | Applies to API keys created before March 1, 2025,<br>provided that the Places API (New) has not been enabled in Google Console. |
| 133 | </label> |
| 134 | </div> |
| 135 | </div> |
| 136 | <div class="grw-field"> |
| 137 | <div class="grw-field-label"> |
| 138 | <label>Google Places API key</label> |
| 139 | </div> |
| 140 | <div class="wp-review-field-option"> |
| 141 | <input type="text" id="grw_google_api_key" name="grw_google_api_key" class="regular-text" value="<?php echo esc_attr($grw_google_api_key); ?>"> |
| 142 | <?php if (!$grw_google_api_key && time() - $grw_activation_time > 60 * 60 * 48) { ?> |
| 143 | <div class="grw-warn">Your Google API key is not set for this reason, reviews are not automatically updated daily.<br>Please create your own Google API key and save here.</div><?php |
| 144 | } elseif ($grw_google_api_key) { |
| 145 | $response = wp_remote_get('http://ip6.me/api/'); |
| 146 | if (is_array($response) && !is_wp_error($response)) { |
| 147 | $body = wp_remote_retrieve_body($response); |
| 148 | if (!empty($body)) { |
| 149 | $parts = explode(',', $body); |
| 150 | if (count($parts) > 1) { |
| 151 | ?><p>If you wish to restrict your API key, please use <b>Application restrictions</b> - <b>IP addresses</b> and add the IP address: <b><u><?php echo $parts[1]; ?></u></b></p><?php |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | } ?> |
| 156 | <p>Google API key is required to automatically update and fetch new reviews.<br>With your own API key, there's no limit to collecting reviews, you can connect more than 10 and collect them daily.</p> |
| 157 | <p>After you created your own API key, it's required to add your bank card to confirm usage of this Key.<br>Please do not worry <b>Google gives 1000 free API requests monthly</b> and<br>it's enough for automatically updated up to 2-3 connected your Google places.</p> |
| 158 | <p>Here is extrimy complete guide on <a href="<?php echo admin_url('admin.php?page=grw-support&grw_tab=fig#fig_api_key'); ?>" target="_blank">how to create your own API key</a>.</p> |
| 159 | <div style="padding-top:15px"> |
| 160 | <input type="submit" value="Save" name="save" class="button" /> |
| 161 | </div> |
| 162 | </div> |
| 163 | </div> |
| 164 | </form> |
| 165 | </div> |
| 166 | |
| 167 | <div id="grw-advance" class="tab-content" style="display:<?php echo $tab == 'advance' ? 'block' : 'none'?>;"> |
| 168 | <h3>Advance</h3> |
| 169 | <?php include_once(dirname(GRW_PLUGIN_FILE) . '/includes/page-setting-advance.php'); ?> |
| 170 | </div> |
| 171 | |
| 172 | </div> |
| 173 | |
| 174 | </div> |
| 175 | <?php |
| 176 | } |
| 177 | |
| 178 | } |
| 179 |