PluginProbe
Tableberg – Simple Gutenberg Table Block / 1.1.0
Tableberg – Simple Gutenberg Table Block v1.1.0
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.0, at includes/Admin/Tableberg_Admin.php

230 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_url;
9
10 public function __construct() {
11
12 $this->plugin_name = 'tableberg';
13 $this->plugin_url = TABLEBERG_URL;
14
15 add_action('wp_ajax_tableberg_toggle_control', [$this, 'update_toggle_control']);
16 add_action('wp_ajax_tableberg_block_properties', [$this, 'update_block_properties']);
17
18 add_action('admin_menu', [$this, 'register_admin_menus']);
19 add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_script']);
20 add_action('admin_notices', [$this, 'tableberg_review_notice']);
21 add_action('wp_ajax_TablebergReviewNoticeHide', [$this, 'tableberg_hide_review_notify']);
22 add_filter('tableberg/filter/admin_settings_menu_data', [$this, 'add_settings_menu_data'], 1, 1);
23 }
24
25 private function update_block_properties() {
26 if (
27 check_ajax_referer('block_properties') &&
28 isset($_POST['value']) &&
29 isset($_POST['property_name']) &&
30 current_user_can('manage_options')
31 ) {
32 $value = sanitize_text_field(wp_unslash($_POST['value']));
33 $property_name = sanitize_text_field(wp_unslash($_POST['property_name']));
34 $saved_properties = get_option('tableberg_block_properties', false);
35 if ($saved_properties) {
36 foreach ($saved_properties as $key => $property) {
37 if ($property['name'] === $property_name) {
38 $saved_properties[$key]['value'] = (int) $value;
39 }
40 }
41 }
42
43 update_option('tableberg_block_properties', $saved_properties);
44 }
45
46 die();
47 }
48
49 private function update_toggle_control() {
50
51 if (
52 check_ajax_referer('toggle_control') &&
53 isset($_POST['enable']) &&
54 isset($_POST['toggle_name']) &&
55 current_user_can('manage_options')
56 ) {
57 $enable = sanitize_text_field(wp_unslash($_POST['enable']));
58 $toggle_name = sanitize_text_field(wp_unslash($_POST['toggle_name']));
59 update_option($toggle_name, $enable);
60 }
61 die();
62 }
63
64 public function add_settings_menu_data($data) {
65 $data['assets'] = [
66 'logo' => trailingslashit($this->plugin_url) . 'includes/Admin/images/logos/menu-icon-colored.svg',
67 'logoTransparent' => trailingslashit($this->plugin_url) . 'includes/Admin/images/logos/menu-icon-colored-transparent.svg',
68 ];
69
70 $data['individual_control'] = [
71 'data' => get_option('tableberg_individual_control', false),
72 'ajax' => [
73 'toggleControl' => [
74 'url' => admin_url('admin-ajax.php'),
75 'action' => 'tableberg_toggle_control',
76 'nonce' => wp_create_nonce('toggle_control'),
77 ],
78 ],
79 ];
80 $data['global_control'] = [
81 'data' => get_option('tableberg_global_control', false),
82 'ajax' => [
83 'toggleControl' => [
84 'url' => admin_url('admin-ajax.php'),
85 'action' => 'tableberg_toggle_control',
86 'nonce' => wp_create_nonce('toggle_control'),
87 ],
88 ],
89 ];
90 $data['block_properties'] = [
91 'data' => get_option('tableberg_block_properties', false),
92 'ajax' => [
93 'blockProperties' => [
94 'url' => admin_url('admin-ajax.php'),
95 'action' => 'tableberg_block_properties',
96 'nonce' => wp_create_nonce('block_properties'),
97 ],
98 ],
99 ];
100
101 $has_pro_addon = defined('TABLEBERG_PRO_VERSION');
102 global $tp_fs;
103 if (isset($tp_fs)) {
104 $data['misc'] = [
105 'pro_status' => $has_pro_addon
106 || ($tp_fs->is__premium_only()
107 && $tp_fs->can_use_premium_code()),
108 ];
109 } else {
110 $data['misc'] = [
111 'pro_status' => $has_pro_addon,
112 ];
113 }
114
115 $data = array_merge($data, $this->welcome_page());
116 return $data;
117 }
118
119 public function enqueue_admin_script() {
120 $tableberg_assets = new Tableberg\Assets();
121 $tableberg_assets->register_admin_assets();
122 }
123
124 public static function welcome_page() {
125 return [
126 'welcome' => [
127 'title' => 'Welcome to Tableberg!',
128 'content' => 'Elevate Your Content with Seamless Tables - The Ultimate WordPress Block Editor Plugin for Effortless Table Creation!',
129 ],
130 'documentation' => [
131 'title' => 'Documentation',
132 'content' => 'Elevate your space with Tableberg: a sleek, modern table block for style and functionality. Crafted for timeless elegance and versatility.',
133 ],
134 'support' => [
135 'title' => 'Support',
136 'content' => "Visit our Tableberg Support Page for quick solutions and assistance. We're here to ensure your Tableberg experience is seamless and satisfying.",
137 ],
138 'community' => [
139 'title' => 'Join Community',
140 'content' => 'Join the vibrant Tableberg community. Connect, share, and discover endless possibilities together. Elevate your experience with like-minded enthusiasts now!',
141 ],
142 'upgrade' => [
143 'title' => 'Upgrade to Tableberg PRO!',
144 'content' => 'Elevate Your Content with Seamless Tables - The Ultimate WordPress Block Editor Plugin for Effortless Table Creation!',
145 ],
146 ];
147 }
148
149 public function main_menu_template_cb() {
150 ?>
151 <div id="tableberg-admin-menu"></div>
152 <?php
153 }
154
155 public function register_admin_menus() {
156 global $menu_page;
157 global $menu_page_slug;
158
159 $menu_page_slug = 'tableberg-settings';
160 $menu_page = add_menu_page(
161 __('Tableberg Settings', 'tableberg'),
162 __('Tableberg', 'tableberg'),
163 'manage_options',
164 $menu_page_slug,
165 [$this, 'main_menu_template_cb'],
166 plugin_dir_url(__FILE__) . 'images/logos/menu-icon.svg'
167 );
168 }
169
170 public static function tableberg_review_notice() {
171 $install_date = get_option('tableberg_installDate');
172 $display_date = date('Y-m-d h:i:s');
173 $datetime1 = new \DateTime($install_date);
174 $datetime2 = new \DateTime($display_date);
175 $diff_interval = round(($datetime2->format('U') - $datetime1->format('U')) / (60 * 60 * 24));
176
177 if ($diff_interval >= 21 && get_option('tableberg_review_notify') == 'no') {
178 ?>
179 <div class="tableberg-review-notice notice notice-info" style="position: relative; padding:0.5rem 1.5rem">
180 <button type="button" class="notice-dismiss Tableberg_HideReview_Notice" style="position: absolute; top: 2px; right: 2px;">
181 <span class="screen-reader-text"><?php esc_html_e('Dismiss this notice.', 'tableberg'); ?></span>
182 </button>
183 <p style="font-size: 14px; line-height: 2;padding-right:2rem">
184 <?php
185 echo wp_kses_post(__(
186 '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',
187 'tableberg'
188 ));
189 ?>
190 </p>
191 <ul style="list-style-type: none; padding: 0;">
192 <li>
193 <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>
194 <a class="Tableberg_HideReview_Notice button" href="javascript:void(0);"><?php esc_html_e('No, thanks', 'tableberg'); ?></a>
195 </li>
196 </ul>
197 </div>
198 <script>
199 jQuery(document).ready(function($) {
200 $('.Tableberg_HideReview_Notice').click(function() {
201 var data = {
202 'action': 'TablebergReviewNoticeHide'
203 };
204 $.ajax({
205 url: "<?php echo esc_url(admin_url('admin-ajax.php')); ?>",
206 type: "post",
207 data: data,
208 dataType: "json",
209 async: true,
210 success: function(notice_hide) {
211 if (notice_hide == "success") {
212 $('.tableberg-review-notice').slideUp('fast');
213 }
214 }
215 });
216 });
217 });
218 </script>
219 <?php
220 }
221 }
222
223
224 public function tableberg_hide_review_notify() {
225 update_option('tableberg_review_notify', 'yes');
226 echo wp_json_encode(['success']);
227 exit;
228 }
229 }
230