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
tableberg / includes / Admin / Tableberg_Admin.php

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

231 lines 9.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Tableberg\Admin;
4
5 use Tableberg;
6
7 class Tableberg_Admin {
8 private $plugin_name;
9 private $plugin_url;
10
11 public function __construct() {
12
13 $this->plugin_name = 'tableberg';
14 $this->plugin_url = TABLEBERG_URL;
15
16 add_action('wp_ajax_tableberg_toggle_control', [$this, 'update_toggle_control']);
17 add_action('wp_ajax_tableberg_block_properties', [$this, 'update_block_properties']);
18
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);
24 }
25
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 ) {
33 $value = sanitize_text_field(wp_unslash($_POST['value']));
34 $property_name = sanitize_text_field(wp_unslash($_POST['property_name']));
35 $saved_properties = get_option('tableberg_block_properties', false);
36 if ($saved_properties) {
37 foreach ($saved_properties as $key => $property) {
38 if ($property['name'] === $property_name) {
39 $saved_properties[$key]['value'] = (int) $value;
40 }
41 }
42 }
43
44 update_option('tableberg_block_properties', $saved_properties);
45 }
46
47 die();
48 }
49
50 private function update_toggle_control() {
51
52 if (
53 check_ajax_referer('toggle_control') &&
54 isset($_POST['enable']) &&
55 isset($_POST['toggle_name']) &&
56 current_user_can('manage_options')
57 ) {
58 $enable = sanitize_text_field(wp_unslash($_POST['enable']));
59 $toggle_name = sanitize_text_field(wp_unslash($_POST['toggle_name']));
60 update_option($toggle_name, $enable);
61 }
62 die();
63 }
64
65 public function add_settings_menu_data($data) {
66 $data['assets'] = [
67 'logo' => trailingslashit($this->plugin_url) . 'includes/Admin/images/logos/menu-icon-colored.svg',
68 'logoTransparent' => trailingslashit($this->plugin_url) . 'includes/Admin/images/logos/menu-icon-colored-transparent.svg',
69 ];
70
71 $data['individual_control'] = [
72 'data' => get_option('tableberg_individual_control', false),
73 'ajax' => [
74 'toggleControl' => [
75 'url' => admin_url('admin-ajax.php'),
76 'action' => 'tableberg_toggle_control',
77 'nonce' => wp_create_nonce('toggle_control'),
78 ],
79 ],
80 ];
81 $data['global_control'] = [
82 'data' => get_option('tableberg_global_control', false),
83 'ajax' => [
84 'toggleControl' => [
85 'url' => admin_url('admin-ajax.php'),
86 'action' => 'tableberg_toggle_control',
87 'nonce' => wp_create_nonce('toggle_control'),
88 ],
89 ],
90 ];
91 $data['block_properties'] = [
92 'data' => get_option('tableberg_block_properties', false),
93 'ajax' => [
94 'blockProperties' => [
95 'url' => admin_url('admin-ajax.php'),
96 'action' => 'tableberg_block_properties',
97 'nonce' => wp_create_nonce('block_properties'),
98 ],
99 ],
100 ];
101
102 $has_pro_addon = defined('TABLEBERG_PRO_VERSION');
103 global $tp_fs;
104 if (isset($tp_fs)) {
105 $data['misc'] = [
106 'pro_status' => $has_pro_addon
107 || ($tp_fs->is__premium_only()
108 && $tp_fs->can_use_premium_code()),
109 ];
110 } else {
111 $data['misc'] = [
112 'pro_status' => $has_pro_addon,
113 ];
114 }
115
116 $data = array_merge($data, $this->welcome_page());
117 return $data;
118 }
119
120 public function enqueue_admin_script() {
121 $tableberg_assets = new Tableberg\Assets();
122 $tableberg_assets->register_admin_assets();
123 }
124
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 ?>
152 <div id="tableberg-admin-menu"></div>
153 <?php
154 }
155
156 public function register_admin_menus() {
157 global $menu_page;
158 global $menu_page_slug;
159
160 $menu_page_slug = 'tableberg-settings';
161 $menu_page = add_menu_page(
162 __('Tableberg Settings', 'tableberg'),
163 __('Tableberg', 'tableberg'),
164 'manage_options',
165 $menu_page_slug,
166 [$this, 'main_menu_template_cb'],
167 plugin_dir_url(__FILE__) . 'images/logos/menu-icon.svg'
168 );
169 }
170
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">
181 <button type="button" class="notice-dismiss Tableberg_HideReview_Notice" style="position: absolute; top: 2px; right: 2px;">
182 <span class="screen-reader-text"><?php esc_html_e('Dismiss this notice.', 'tableberg'); ?></span>
183 </button>
184 <p style="font-size: 14px; line-height: 2;padding-right:2rem">
185 <?php
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 ?>
191 </p>
192 <ul style="list-style-type: none; padding: 0;">
193 <li>
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>
196 </li>
197 </ul>
198 </div>
199 <script>
200 jQuery(document).ready(function($) {
201 $('.Tableberg_HideReview_Notice').click(function() {
202 var data = {
203 'action': 'TablebergReviewNoticeHide'
204 };
205 $.ajax({
206 url: "<?php echo esc_url(admin_url('admin-ajax.php')); ?>",
207 type: "post",
208 data: data,
209 dataType: "json",
210 async: true,
211 success: function(notice_hide) {
212 if (notice_hide == "success") {
213 $('.tableberg-review-notice').slideUp('fast');
214 }
215 }
216 });
217 });
218 });
219 </script>
220 <?php
221 }
222 }
223
224
225 public function tableberg_hide_review_notify() {
226 update_option('tableberg_review_notify', 'yes');
227 echo wp_json_encode(['success']);
228 exit;
229 }
230 }
231