PluginProbe
Tableberg – Simple Gutenberg Table Block / 0.5.3
Tableberg – Simple Gutenberg Table Block v0.5.3
1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 trunk 0.0.2 0.2.1 0.3.2 0.3.3 0.4.1 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 All 42 releases
tableberg / includes / Admin / Tableberg_Admin.php

Tableberg_Admin.php in Tableberg – Simple Gutenberg Table Block 0.5.3, at includes/Admin/Tableberg_Admin.php

296 lines 9.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The admin-specific functionality of the plugin.
5 *
6 * @package tableberg
7 */
8
9 namespace Tableberg\Admin;
10
11 use Tableberg;
12 use Tableberg\Version_Control;
13
14 /**
15 * Manage Tableberg Admin
16 */
17 class Tableberg_Admin
18 {
19 /**
20 * The ID of this plugin.
21 *
22 * @access private
23 * @var string $plugin_name The ID of this plugin.
24 */
25 private $plugin_name;
26
27 /**
28 * The version of this plugin.
29 *
30 * @access private
31 * @var string $version The current version of this plugin.
32 */
33 private $version;
34
35 /**
36 * The PATH of this plugin.
37 *
38 * @access private
39 * @var string $plugin_path The PATH of this plugin.
40 */
41 private $plugin_path;
42
43 /**
44 * The URL of this plugin.
45 *
46 * @access private
47 * @var string $plugin_url The URL of this plugin.
48 */
49 private $plugin_url;
50
51 /**
52 * Initialize the class and set its properties.
53 */
54 public function __construct()
55 {
56
57 $this->plugin_name = 'tableberg';
58 $this->version = TABLEBERG_VERSION;
59 $this->plugin_path = TABLEBERG_DIR_PATH;
60 $this->plugin_url = TABLEBERG_URL;
61 $this->add_tableberg_admin_hook();
62
63 // initialize version sync manager.
64 Tableberg\Version_Sync_Manager::init();
65
66 // initialize version control manager.
67 Version_Control::init();
68
69 add_action('admin_menu', array($this, 'register_admin_menus'));
70 add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_script'));
71 add_action('admin_notices', array($this, 'tableberg_review_notice'));
72 add_action('wp_ajax_TablebergReviewNoticeHide', array($this, 'tableberg_hide_review_notify'));
73 add_filter('tableberg/filter/admin_settings_menu_data', array($this, 'add_settings_menu_data'), 1, 1);
74 }
75
76 /**
77 * Add hook
78 */
79 public function add_tableberg_admin_hook()
80 {
81 add_action('wp_ajax_toggle_control', array($this, 'update_toggle_control'));
82 add_action('wp_ajax_block_properties', array($this, 'update_block_properties'));
83 }
84
85 /**
86 * Block properties control
87 */
88 private function update_block_properties()
89 {
90 check_ajax_referer('block_properties');
91
92 if (isset($_POST['value']) && isset($_POST['property_name'])) {
93 $value = sanitize_text_field(wp_unslash($_POST['value']));
94 $property_name = sanitize_text_field(wp_unslash($_POST['property_name']));
95 $saved_properties = get_option('tableberg_block_properties', false);
96 if ($saved_properties) {
97 foreach ($saved_properties as $key => $property) {
98 if ($property['name'] === $property_name) {
99 $saved_properties[$key]['value'] = (int) $value;
100 }
101 }
102 }
103
104 update_option('tableberg_block_properties', $saved_properties);
105 }
106
107 die();
108 }
109
110 /**
111 * Toggle control
112 */
113 private function update_toggle_control()
114 {
115 check_ajax_referer('toggle_control');
116
117 if (isset($_POST['enable']) && isset($_POST['toggle_name'])) {
118 $enable = sanitize_text_field(wp_unslash($_POST['enable']));
119 $toggle_name = sanitize_text_field(wp_unslash($_POST['toggle_name']));
120 update_option($toggle_name, $enable);
121 }
122 die();
123 }
124
125 /**
126 * Add data for admin settings menu frontend.
127 *
128 * @param array $data frontend data.
129 *
130 * @return array filtered frontend data
131 */
132 public function add_settings_menu_data($data)
133 {
134 $data['assets'] = array(
135 'logo' => trailingslashit($this->plugin_url) . 'includes/Admin/images/logos/menu-icon-colored.svg',
136 'logoTransparent' => trailingslashit($this->plugin_url) . 'includes/Admin/images/logos/menu-icon-colored-transparent.svg',
137 );
138
139 $data['individual_control'] = array(
140 'data' => get_option('tableberg_individual_control', false),
141 'ajax' => array(
142 'toggleControl' => array(
143 'url' => admin_url('admin-ajax.php'),
144 'action' => 'toggle_control',
145 'nonce' => wp_create_nonce('toggle_control'),
146 ),
147 ),
148 );
149 $data['global_control'] = array(
150 'data' => get_option('tableberg_global_control', false),
151 'ajax' => array(
152 'toggleControl' => array(
153 'url' => admin_url('admin-ajax.php'),
154 'action' => 'toggle_control',
155 'nonce' => wp_create_nonce('toggle_control'),
156 ),
157 ),
158 );
159 $data['block_properties'] = array(
160 'data' => get_option('tableberg_block_properties', false),
161 'ajax' => array(
162 'blockProperties' => array(
163 'url' => admin_url('admin-ajax.php'),
164 'action' => 'block_properties',
165 'nonce' => wp_create_nonce('block_properties'),
166 ),
167 ),
168 );
169
170 global $tp_fs;
171 if (isset($tp_fs)) {
172 $data['misc'] = [
173 'pro_status' => $tp_fs->is__premium_only()
174 && $tp_fs->can_use_premium_code()
175 ];
176 } else {
177 $data['misc'] = [
178 'pro_status' => false
179 ];
180 }
181
182 $data = array_merge($data, Tableberg\Utils\Utils::welcome_page());
183 return $data;
184 }
185
186 /**
187 * Enqueue admin scripts.
188 */
189 public function enqueue_admin_script()
190 {
191 $tableberg_assets = new Tableberg\Assets();
192 $tableberg_assets->register_admin_assets();
193 }
194
195 /**
196 * Set template for main setting page
197 *
198 * @return void
199 */
200 public function main_menu_template_cb()
201 {
202 ?>
203 <div id="tableberg-admin-menu"></div>
204 <?php
205 }
206
207 /**
208 * Register Setting Pages for the admin area.
209 */
210 public function register_admin_menus()
211 {
212
213 // assign global variables.
214 global $menu_page;
215 global $menu_page_slug;
216
217 $menu_page_slug = 'tableberg-settings';
218 $menu_page = add_menu_page(
219 'Tableberg Settings',
220 'Tableberg',
221 'manage_options',
222 $menu_page_slug,
223 array($this, 'main_menu_template_cb'),
224 plugin_dir_url(__FILE__) . 'images/logos/menu-icon.svg'
225 );
226 }
227
228 /**
229 * Generating the review notice.
230 *
231 * @since 2.1.6
232 */
233 public static function tableberg_review_notice()
234 {
235 $install_date = get_option('tableberg_installDate');
236 $display_date = date('Y-m-d h:i:s');
237 $datetime1 = new \DateTime($install_date);
238 $datetime2 = new \DateTime($display_date);
239 $diff_interval = round(($datetime2->format('U') - $datetime1->format('U')) / (60 * 60 * 24));
240 if ($diff_interval >= 21 && get_option('tableberg_review_notify') == 'no') {
241 ?>
242 <div class="tableberg-review-notice notice notice-info">
243 <p style="font-size: 14px;">
244 <?php
245 _e(
246 'Hey,<br> I noticed that you have been using <strong>Tableberg Plugin</strong> for a while now - that’s awesome! Could you please do me a BIG favor and <b>give it a 5-star rating on WordPress</b>? Just to help us spread the word and boost our motivation. <br>~ Imtiaz Rayhan<br>~ Lead Developer, Tableberg.',
247 'tableberg'
248 );
249 ?>
250 </p>
251 <ul>
252 <li>
253 <a style="margin-right: 5px; margin-bottom: 5px;" class="button-primary" href="https://wordpress.org/support/plugin/tableberg/reviews/?filter=5#new-post" target="_blank">Sure, you deserve it.</a>
254 <a style="margin-right: 5px;" class="Tableberg_HideReview_Notice button" href="javascript:void(0);">I already did.</a>
255 <a class="Tableberg_HideReview_Notice button" href="javascript:void(0);">No, not good enough.</a>
256 </li>
257 </ul>
258 </div>
259 <script>
260 jQuery(document).ready(function($) {
261 jQuery('.Tableberg_HideReview_Notice').click(function() {
262 var data = {
263 'action': 'TablebergReviewNoticeHide'
264 };
265 jQuery.ajax({
266 url: "<?php echo admin_url('admin-ajax.php'); ?>",
267 type: "post",
268 data: data,
269 dataType: "json",
270 async: !0,
271 success: function(notice_hide) {
272 if (notice_hide == "success") {
273 jQuery('.tableberg-review-notice').slideUp('fast');
274 }
275 }
276 });
277 });
278 });
279 </script>
280 <?php
281 }
282 }
283
284 /**
285 * Hides the review notice.
286 *
287 * @since 2.1.6
288 */
289 public function tableberg_hide_review_notify()
290 {
291 update_option('tableberg_review_notify', 'yes');
292 echo json_encode(array('success'));
293 exit;
294 }
295 }
296