PluginProbe
Tableberg – Simple Gutenberg Table Block / 1.1.5
Tableberg – Simple Gutenberg Table Block v1.1.5
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
← All changes | includes/Admin/Tableberg_Admin.php +109 -178 0.5.61.1.5 View file →
@@ -1,96 +1,36 @@
1 1 <?php
2 2
3 -/**
4 - * The admin-specific functionality of the plugin.
5 - *
6 - * @package tableberg
7 - */
8 -
9 3 namespace Tableberg\Admin;
10 4
11 5 use Tableberg;
12 -use Tableberg\Version_Control;
13 6
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 - */
7 +class Tableberg_Admin {
25 8 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 9 private $plugin_url;
50 10
51 - /**
52 - * Initialize the class and set its properties.
53 - */
54 - public function __construct()
55 - {
11 + public function __construct() {
56 12
57 13 $this->plugin_name = 'tableberg';
58 - $this->version = TABLEBERG_VERSION;
59 - $this->plugin_path = TABLEBERG_DIR_PATH;
60 14 $this->plugin_url = TABLEBERG_URL;
61 - $this->add_tableberg_admin_hook();
62 15
63 - // initialize version sync manager.
64 - Tableberg\Version_Sync_Manager::init();
16 + add_action('wp_ajax_tableberg_toggle_control', [$this, 'update_toggle_control']);
17 + add_action('wp_ajax_tableberg_block_properties', [$this, 'update_block_properties']);
65 18
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);
19 + add_action('admin_menu', [$this, 'register_admin_menus']);
20 + add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_script']);
21 + add_action('admin_notices', [$this, 'tableberg_review_notice']);
22 + add_action('wp_ajax_TablebergReviewNoticeHide', [$this, 'tableberg_hide_review_notify']);
23 + add_filter('tableberg/filter/admin_settings_menu_data', [$this, 'add_settings_menu_data'], 1, 1);
74 24 }
75 25
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'])) {
26 + private function update_block_properties() {
27 + if (
28 + check_ajax_referer('block_properties') &&
29 + isset($_POST['value']) &&
30 + isset($_POST['property_name']) &&
31 + current_user_can('manage_options')
32 + ) {
93 33 $value = sanitize_text_field(wp_unslash($_POST['value']));
94 34 $property_name = sanitize_text_field(wp_unslash($_POST['property_name']));
95 35 $saved_properties = get_option('tableberg_block_properties', false);
96 36 if ($saved_properties) {
@@ -106,16 +46,16 @@
106 46
107 47 die();
108 48 }
109 49
110 - /**
111 - * Toggle control
112 - */
113 - private function update_toggle_control()
114 - {
115 - check_ajax_referer('toggle_control');
50 + private function update_toggle_control() {
116 51
117 - if (isset($_POST['enable']) && isset($_POST['toggle_name'])) {
52 + if (
53 + check_ajax_referer('toggle_control') &&
54 + isset($_POST['enable']) &&
55 + isset($_POST['toggle_name']) &&
56 + current_user_can('manage_options')
57 + ) {
118 58 $enable = sanitize_text_field(wp_unslash($_POST['enable']));
119 59 $toggle_name = sanitize_text_field(wp_unslash($_POST['toggle_name']));
120 60 update_option($toggle_name, $enable);
121 61 }
@@ -121,142 +61,139 @@
121 61 }
122 62 die();
123 63 }
124 64
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(
65 + public function add_settings_menu_data($data) {
66 + $data['assets'] = [
135 67 'logo' => trailingslashit($this->plugin_url) . 'includes/Admin/images/logos/menu-icon-colored.svg',
136 68 'logoTransparent' => trailingslashit($this->plugin_url) . 'includes/Admin/images/logos/menu-icon-colored-transparent.svg',
137 - );
69 + ];
138 70
139 - $data['individual_control'] = array(
71 + $data['individual_control'] = [
140 72 'data' => get_option('tableberg_individual_control', false),
141 - 'ajax' => array(
142 - 'toggleControl' => array(
73 + 'ajax' => [
74 + 'toggleControl' => [
143 75 'url' => admin_url('admin-ajax.php'),
144 - 'action' => 'toggle_control',
76 + 'action' => 'tableberg_toggle_control',
145 77 'nonce' => wp_create_nonce('toggle_control'),
146 - ),
147 - ),
148 - );
149 - $data['global_control'] = array(
78 + ],
79 + ],
80 + ];
81 + $data['global_control'] = [
150 82 'data' => get_option('tableberg_global_control', false),
151 - 'ajax' => array(
152 - 'toggleControl' => array(
83 + 'ajax' => [
84 + 'toggleControl' => [
153 85 'url' => admin_url('admin-ajax.php'),
154 - 'action' => 'toggle_control',
86 + 'action' => 'tableberg_toggle_control',
155 87 'nonce' => wp_create_nonce('toggle_control'),
156 - ),
157 - ),
158 - );
159 - $data['block_properties'] = array(
88 + ],
89 + ],
90 + ];
91 + $data['block_properties'] = [
160 92 'data' => get_option('tableberg_block_properties', false),
161 - 'ajax' => array(
162 - 'blockProperties' => array(
93 + 'ajax' => [
94 + 'blockProperties' => [
163 95 'url' => admin_url('admin-ajax.php'),
164 - 'action' => 'block_properties',
96 + 'action' => 'tableberg_block_properties',
165 97 'nonce' => wp_create_nonce('block_properties'),
166 - ),
167 - ),
168 - );
98 + ],
99 + ],
100 + ];
169 101
102 + $has_pro_addon = defined('TABLEBERG_PRO_VERSION');
170 103 global $tp_fs;
171 104 if (isset($tp_fs)) {
172 105 $data['misc'] = [
173 - 'pro_status' => $tp_fs->is__premium_only()
174 - && $tp_fs->can_use_premium_code()
106 + 'pro_status' => $has_pro_addon
107 + || ($tp_fs->is__premium_only()
108 + && $tp_fs->can_use_premium_code()),
175 109 ];
176 110 } else {
177 111 $data['misc'] = [
178 - 'pro_status' => false
112 + 'pro_status' => $has_pro_addon,
179 113 ];
180 114 }
181 115
182 - $data = array_merge($data, Tableberg\Utils\Utils::welcome_page());
116 + $data = array_merge($data, $this->welcome_page());
183 117 return $data;
184 118 }
185 119
186 - /**
187 - * Enqueue admin scripts.
188 - */
189 - public function enqueue_admin_script()
190 - {
120 + public function enqueue_admin_script() {
191 121 $tableberg_assets = new Tableberg\Assets();
192 122 $tableberg_assets->register_admin_assets();
193 123 }
194 124
195 - /**
196 - * Set template for main setting page
197 - *
198 - * @return void
199 - */
200 - public function main_menu_template_cb()
201 - {
202 -?>
125 + public static function welcome_page() {
126 + return [
127 + 'welcome' => [
128 + 'title' => 'Welcome to Tableberg!',
129 + 'content' => 'Elevate Your Content with Seamless Tables - The Ultimate WordPress Block Editor Plugin for Effortless Table Creation!',
130 + ],
131 + 'documentation' => [
132 + 'title' => 'Documentation',
133 + 'content' => 'Elevate your space with Tableberg: a sleek, modern table block for style and functionality. Crafted for timeless elegance and versatility.',
134 + ],
135 + 'support' => [
136 + 'title' => 'Support',
137 + 'content' => "Visit our Tableberg Support Page for quick solutions and assistance. We're here to ensure your Tableberg experience is seamless and satisfying.",
138 + ],
139 + 'community' => [
140 + 'title' => 'Join Community',
141 + 'content' => 'Join the vibrant Tableberg community. Connect, share, and discover endless possibilities together. Elevate your experience with like-minded enthusiasts now!',
142 + ],
143 + 'upgrade' => [
144 + 'title' => 'Upgrade to Tableberg PRO!',
145 + 'content' => 'Elevate Your Content with Seamless Tables - The Ultimate WordPress Block Editor Plugin for Effortless Table Creation!',
146 + ],
147 + ];
148 + }
149 +
150 + public function main_menu_template_cb() {
151 + ?>
203 152 <div id="tableberg-admin-menu"></div>
204 153 <?php
205 154 }
206 155
207 - /**
208 - * Register Setting Pages for the admin area.
209 - */
210 - public function register_admin_menus()
211 - {
212 -
213 - // assign global variables.
156 + public function register_admin_menus() {
214 157 global $menu_page;
215 158 global $menu_page_slug;
216 159
217 160 $menu_page_slug = 'tableberg-settings';
218 161 $menu_page = add_menu_page(
219 - 'Tableberg Settings',
220 - 'Tableberg',
162 + __('Tableberg Settings', 'tableberg'),
163 + __('Tableberg', 'tableberg'),
221 164 'manage_options',
222 165 $menu_page_slug,
223 - array($this, 'main_menu_template_cb'),
166 + [$this, 'main_menu_template_cb'],
224 167 plugin_dir_url(__FILE__) . 'images/logos/menu-icon.svg'
225 168 );
226 169 }
227 170
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 -
241 - if ($diff_interval >= 21 && get_option('tableberg_review_notify') == 'no') {
242 - ?>
243 - <div class="tableberg-review-notice notice notice-info" style="display: inline-block; position: relative; padding:0.5rem 1.5rem">
171 + public static function tableberg_review_notice() {
172 + $install_date = get_option('tableberg_installDate');
173 + $display_date = date('Y-m-d h:i:s');
174 + $datetime1 = new \DateTime($install_date);
175 + $datetime2 = new \DateTime($display_date);
176 + $diff_interval = round(($datetime2->format('U') - $datetime1->format('U')) / (60 * 60 * 24));
177 +
178 + if ($diff_interval >= 21 && get_option('tableberg_review_notify') == 'no') {
179 + ?>
180 + <div class="tableberg-review-notice notice notice-info" style="position: relative; padding:0.5rem 1.5rem">
244 181 <button type="button" class="notice-dismiss Tableberg_HideReview_Notice" style="position: absolute; top: 2px; right: 2px;">
245 - <span class="screen-reader-text">Dismiss this notice.</span>
182 + <span class="screen-reader-text"><?php esc_html_e('Dismiss this notice.', 'tableberg'); ?></span>
246 183 </button>
247 184 <p style="font-size: 14px; line-height: 2;padding-right:2rem">
248 185 <?php
249 - _e(
250 - 'Hello! Seems like you\'ve been using <strong>Tableberg</strong> for a while on your website. That\'s awesome!<br>If you can spare a few moments to rate it on wordpress.org, it would help us a lot (and boost my motivation).<br>Imtiaz Rayhan, developer of Tableberg',
251 - 'tableberg'
252 - );
253 - ?>
186 + echo wp_kses_post(__(
187 + 'Hello! Seems like you\'ve been using <strong>Tableberg</strong> for a while on your website. That\'s awesome!<br>If you can spare a few moments to rate it on wordpress.org, it would help us a lot (and boost my motivation).<br>Imtiaz Rayhan, developer of Tableberg',
188 + 'tableberg'
189 + ));
190 + ?>
254 191 </p>
255 192 <ul style="list-style-type: none; padding: 0;">
256 193 <li>
257 - <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">Ok, I will gladly help!</a>
258 - <a class="Tableberg_HideReview_Notice button" href="javascript:void(0);">No, thanks</a>
194 + <a style="margin-right: 5px; margin-bottom: 5px;" class="button-primary" href="https://wordpress.org/support/plugin/tableberg/reviews/" target="_blank"><?php esc_html_e('Ok, I will gladly help!', 'tableberg'); ?></a>
195 + <a class="Tableberg_HideReview_Notice button" href="javascript:void(0);"><?php esc_html_e('No, thanks', 'tableberg'); ?></a>
259 196 </li>
260 197 </ul>
261 198 </div>
262 199 <script>
@@ -265,9 +202,9 @@
265 202 var data = {
266 203 'action': 'TablebergReviewNoticeHide'
267 204 };
268 205 $.ajax({
269 - url: "<?php echo admin_url('admin-ajax.php'); ?>",
206 + url: "<?php echo esc_url(admin_url('admin-ajax.php')); ?>",
270 207 type: "post",
271 208 data: data,
272 209 dataType: "json",
273 210 async: true,
@@ -280,20 +217,14 @@
280 217 });
281 218 });
282 219 </script>
283 220 <?php
284 - }
285 - }
286 -
221 + }
222 + }
287 223
288 - /**
289 - * Hides the review notice.
290 - *
291 - * @since 2.1.6
292 - */
293 - public function tableberg_hide_review_notify()
294 - {
224 +
225 + public function tableberg_hide_review_notify() {
295 226 update_option('tableberg_review_notify', 'yes');
296 - echo json_encode(array('success'));
227 + echo wp_json_encode(['success']);
297 228 exit;
298 229 }
299 230 }