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