PluginProbe
Bubble Menu – Floating Button Menu with Sticky Navigation / 2.2
Bubble Menu – Floating Button Menu with Sticky Navigation v2.2
trunk 1.3 2.0 2.2 2.2.1 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.1 4.1.1
← All changes | admin/class-admin.php +357 -274 3.0.52.2 View file →
@@ -4,9 +4,9 @@
4 4 * Admin Class
5 5 *
6 6 * @package Wow_Plugin
7 7 * @subpackage Admin
8 - * @author Wow-Company <yoda@wow-company.com>
8 + * @author Dmytro Lobov <i@wpbiker.com>
9 9 * @copyright 2019 Wow-Company
10 10 * @license GNU Public License
11 11 * @version 1.0
12 12 */
@@ -12,11 +12,10 @@
12 12 */
13 13
14 14 namespace bubble_menu_lite;
15 15
16 -
17 -if ( ! defined( 'ABSPATH' ) ) {
18 - exit;
16 +if (!defined("ABSPATH")) {
17 + exit();
19 18 }
20 19
21 20 /**
22 21 * Class Wow_Plugin_Admin
@@ -27,314 +26,398 @@
27 26 * @property array url - home, pro and other URL for plugin
28 27 * @property array rating - website and link for rating
29 28 *
30 29 */
31 -class Wow_Plugin_Admin {
30 +class Wow_Plugin_Admin
31 +{
32 + /**
33 + * Setup to admin panel of the plugin
34 + *
35 + * @param array $info general information about the plugin
36 + *
37 + * @since 1.0
38 + */
39 + public function __construct($info)
40 + {
41 + $this->plugin = $info["plugin"];
42 + $this->url = $info["url"];
43 + $this->rating = $info["rating"];
32 44
33 - /**
34 - * Setup to admin panel of the plugin
35 - *
36 - * @param array $info general information about the plugin
37 - *
38 - * @since 1.0
39 - */
40 - public function __construct( $info ) {
41 - $this->plugin = $info['plugin'];
42 - $this->url = $info['url'];
43 - $this->rating = $info['rating'];
45 + add_filter("plugin_action_links", [$this, "action_links"], 10, 2);
46 + add_action("admin_menu", [$this, "add_admin_page"]);
47 + add_filter("admin_footer_text", [$this, "rate_us"]);
48 + // add_action( 'plugins_loaded', array( $this, 'plugin_check' ) );
44 49
45 - add_filter( 'plugin_action_links', array( $this, 'action_links' ), 10, 2 );
46 - add_action( 'admin_menu', array( $this, 'add_admin_page' ) );
47 - add_filter( 'admin_footer_text', array( $this, 'rate_us' ) );
48 - add_action( 'wp_ajax_' . $this->plugin['prefix'] . '_item_save', array( $this, 'item_save' ) );
49 - add_action( 'wp_ajax_float_menu_message', array( $this, 'wow_message_callback' ) );
50 - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
51 - }
50 + add_action("admin_enqueue_scripts", [$this, "admin_style_script"]);
51 + add_action("wp_ajax_wow_item_save", [$this, "item_save"]);
52 52
53 - public function wow_message_callback() {
54 - update_option( 'wow_' . $this->plugin['prefix'] . '_message', 'read' );
55 - wp_die();
56 - }
53 + if (get_option("wow_" . $this->plugin["prefix"] . "_notice_action") != "read") {
54 + add_action("admin_notices", [$this, "general_admin_notice"]);
55 + add_action("admin_enqueue_scripts", [$this, "admin_notice_assets"]);
56 + add_action("wp_ajax_bubble_menu_notice_action", [$this, "wow_notice_action_callback"]);
57 + }
58 + }
57 59
58 - /**
59 - * @param string|array $arg text which need show in the tooltip
60 - *
61 - * @return string tooltip for the element
62 - */
63 - static function tooltip( $arg ) {
64 - $tooltip = '';
65 - foreach ( $arg as $key => $value ) {
66 - if ( $key == 'title' ) {
67 - $tooltip .= $value . '<p/>';
68 - } elseif ( $key == 'ul' ) {
69 - $tooltip .= '<ul>';
70 - $arr = $value;
71 - foreach ( $arr as $val ) {
72 - $tooltip .= '<li>' . $val . '</li>';
73 - }
74 - $tooltip .= '</ul>';
75 - } else {
76 - $tooltip .= $value;
77 - }
78 - }
79 - echo "<span class='wow-help dashicons dashicons-editor-help' title='" . wp_kses_post( $tooltip ) . "'></span>";
80 - }
60 + /**
61 + * @param string|array $arg text which need show in the tooltip
62 + *
63 + * @return string tooltip for the element
64 + */
65 + static function tooltip($arg)
66 + {
67 + $tooltip = "";
68 + foreach ($arg as $key => $value) {
69 + if ($key == "title") {
70 + $tooltip .= $value . "<p/>";
71 + } elseif ($key == "ul") {
72 + $tooltip .= "<ul>";
73 + $arr = $value;
74 + foreach ($arr as $val) {
75 + $tooltip .= "<li>" . $val . "</li>";
76 + }
77 + $tooltip .= "</ul>";
78 + } else {
79 + $tooltip .= $value;
80 + }
81 + }
82 + $tooltip = "<span class='wow-help dashicons dashicons-editor-help' title='" . $tooltip . "'></span>";
81 83
82 - /**
83 - * @param array $arg parameters for creating field in the backend
84 - *
85 - * @return string field for displaying
86 - */
87 - static function option( $arg ) {
88 - $id = isset( $arg['id'] ) ? $arg['id'] : null;
89 - $name = isset( $arg['name'] ) ? $arg['name'] : '';
90 - $type = isset( $arg['type'] ) ? $arg['type'] : '';
91 - $func = ! empty( $arg['func'] ) ? ' onchange="' . $arg['func'] . '"' : '';
92 - $options = isset( $arg['option'] ) ? $arg['option'] : '';
93 - $val = $arg['val'];
94 - $separator = isset( $arg['sep'] ) ? $arg['sep'] : '';
95 - $extra_class = '';
96 - if ( $type == 'text' || $type == 'number' || $type == 'time' ) {
97 - $extra_class = 'input ';
98 - }
99 - $class = isset( $arg['class'] ) ? ' class="' . $extra_class . $arg['class'] . '"' : ' class="' . $extra_class . '"';
100 - $field = '';
84 + return $tooltip;
85 + }
101 86
102 - switch ( $type ) {
103 - case 'radio':
104 - include( 'fields/radio.php' );
105 - break;
106 - case 'checkbox':
107 - include( 'fields/checkbox.php' );
108 - break;
109 - case 'text':
110 - case 'number':
111 - case 'hidden':
112 - case 'time':
113 - include( 'fields/input.php' );
114 - break;
115 - case 'select':
116 - include( 'fields/select.php' );
117 - break;
118 - case 'color':
119 - include( 'fields/color.php' );
120 - break;
121 - case 'editor':
122 - include( 'fields/editor.php' );
123 - break;
124 - }
125 - }
87 + /**
88 + * @param array $arg parameters for creating field in the backend
89 + *
90 + * @return string field for displaying
91 + */
92 + static function option($arg)
93 + {
94 + $id = isset($arg["id"]) ? $arg["id"] : null;
95 + $name = isset($arg["name"]) ? $arg["name"] : "";
96 + $type = isset($arg["type"]) ? $arg["type"] : "";
97 + $func = !empty($arg["func"]) ? ' onchange="' . $arg["func"] . '"' : "";
98 + $options = isset($arg["option"]) ? $arg["option"] : "";
99 + $val = $arg["val"];
100 + $separator = isset($arg["sep"]) ? "<" . esc_attr($arg["sep"]) . "/>" : "";
101 + $class = isset($arg["class"]) ? ' class="' . $arg["class"] . '"' : "";
102 + $field = "";
126 103
127 - /**
128 - * @param string $tooltip tooltip for element
129 - *
130 - * @return string
131 - */
132 - public function pro( $tooltip = null ) {
133 - $link = admin_url() . 'admin.php?page=' . $this->plugin['slug'] . '&tab=extension';
134 - $title = esc_attr__( 'More features in the PRO version', 'bubble-menu' );
135 - $classes = 'wow-help dashicons dashicons-lock';
136 - $tooltip = ! empty( $tooltip ) ? $title . '<br/>' . $tooltip : $title;
137 - echo '<a href="' . esc_url( $link ) . '" class="' . esc_attr( $classes ) . '" title="' . wp_kses_post( $tooltip ) . '"></a>';
138 - }
104 + if ($type == "radio") {
105 + // create radio fields
106 + $option = "";
107 + foreach ($options as $key => $value) {
108 + $select = $key == $val ? ' checked="checked"' : "";
109 + $option .= '<input name="' . esc_attr($name) . '" type="radio" value="' . esc_attr($key) . '" id="' . esc_attr($id) . "_" . esc_attr($key) . '" ' . $select . $func . $class . '><label for="' . esc_attr($id) . "_" . esc_attr($key) . '"> ' . esc_attr($value) . "</label>" . $separator;
110 + }
111 + $field = $option;
112 + } elseif ($type == "checkbox") {
113 + // create checkbox field
114 + $select = !empty($val) ? ' checked="checked"' : "";
115 + $id = $id === null ? "" : ' id="' . esc_attr($id) . '"';
116 + $field = '<input type="checkbox" ' . $id . $select . $func . $class . ">" . $separator;
117 + $field .= '<input type="hidden" name="' . esc_attr($name) . '" value="">';
118 + } elseif ($type == "text" || $type == "number" || $type == "hidden") {
119 + // create text field
120 + $option = "";
121 + if (is_array($options)) {
122 + foreach ($options as $key => $value) {
123 + $option .= " " . $key . '="' . $value . '"';
124 + }
125 + }
126 + $id = $id === null ? "" : ' id="' . $id . '"';
127 + $field = '<input name="' . esc_attr($name) . '" type="' . esc_attr($type) . '" value="' . esc_attr($val) . '"' . $id . $func . $option . $class . ">" . $separator;
128 + } elseif ($type == "color") {
129 + // create color field
130 + $id = $id === null ? "" : ' id="' . $id . '"';
131 + $field = '<input name="' . esc_attr($name) . '" type="text" value="' . esc_attr($val) . '" class="wp-color-picker-field" data-alpha="true"' . $id . ">" . $separator;
132 + }
133 + // create select field
134 + elseif ($type == "select") {
135 + $disabled = isset($arg["disabled"]) ? " disabled" : "";
136 + $readonly = isset($arg["readonly"]) ? " readonly" : "";
137 + $option = "";
138 + foreach ($options as $key => $value) {
139 + if (strrpos($key, "_start") != false) {
140 + $option .= '<optgroup label="' . esc_attr($value) . '">';
141 + } elseif (strrpos($key, "_end") != false) {
142 + $option .= "</optgroup>";
143 + } else {
144 + $select = $key == $val ? 'selected="selected"' : "";
145 + $option .= '<option value="' . esc_attr($key) . '" ' . $select . ">" . esc_attr($value) . "</option>";
146 + }
147 + }
148 + $id = $id === null ? "" : ' id="' . $id . '"';
149 + $field = '<select name="' . esc_attr($name) . '"' . $func . $class . $disabled . $readonly . $id . ">";
150 + $field .= $option;
151 + $field .= "</select>" . $separator;
152 + } elseif ($type == "editor") {
153 + // create editor field
154 + $settings = [
155 + "wpautop" => 0,
156 + "textarea_name" => "" . $name . "",
157 + "textarea_rows" => 15,
158 + ];
159 + $field = wp_editor($val, $id, $settings);
160 + } elseif ($type == "textarea") {
161 + // create textarea field
162 + $id = $id === null ? "" : ' id="' . $id . '"';
163 + $field = '<textarea name="' . esc_attr($name) . '"' . $id . ">" . $val . "</textarea>" . $separator;
164 + }
139 165
140 - /**
141 - * Add the plugin page in admin menu
142 - *
143 - * @since 1.0
144 - */
145 - public function add_admin_page() {
146 - $parent = 'wow-company';
147 - $title = $this->plugin['name'] . ' version ' . $this->plugin['version'];
148 - $menu_title = $this->plugin['menu'];
149 - $capability = 'manage_options';
150 - $slug = $this->plugin['slug'];
151 - $function = array( $this, 'plugin_page' );
152 - add_submenu_page( $parent, $title, $menu_title, $capability, $slug, $function );
153 - }
166 + return $field;
167 + }
154 168
155 - /**
156 - * Include main plugin page with Style and Script
157 - *
158 - * @since 1.0
159 - */
160 - public function plugin_page() {
161 - global $wow_plugin_page;
162 - $wow_plugin_page = $this->plugin['slug'];
163 - require_once 'page-main.php';
164 - }
169 + /**
170 + * @param string $tooltip tooltip for element
171 + *
172 + * @return string
173 + */
174 + public function pro($tooltip = null)
175 + {
176 + $link = admin_url() . "admin.php?page=" . $this->plugin["slug"] . "&tab=extension";
177 + $title = esc_attr__("More features in the PRO version", $this->plugin["text"]);
178 + $classes = "wow-help dashicons dashicons-lock";
179 + $tooltip = !empty($tooltip) ? $title . "<br/>" . $tooltip : $title;
180 + $pro = '<a href="' . $link . '" class="' . $classes . '" title="' . $tooltip . '"></a>';
165 181
182 + return $pro;
183 + }
166 184
167 - /**
168 - * Include Styles and Scripts on the plugin admin page
169 - *
170 - * @since 1.0
171 - */
172 - public function admin_scripts( $hook ) {
173 - $page = 'wow-plugins_page_' . $this->plugin['slug'];
185 + /**
186 + * Add the plugin page in admin menu
187 + *
188 + * @since 1.0
189 + */
190 + public function add_admin_page()
191 + {
192 + $parent = "wow-company";
193 + $title = $this->plugin["name"] . " version " . $this->plugin["version"];
194 + $menu_title = $this->plugin["menu"];
195 + $capability = "manage_options";
196 + $slug = $this->plugin["slug"];
197 + $function = [$this, "plugin_page"];
198 + add_submenu_page($parent, $title, $menu_title, $capability, $slug, $function);
199 + }
174 200
175 - if ( $page != $hook ) {
176 - return false;
177 - }
178 - $slug = $this->plugin['slug'];
179 - $version = $this->plugin['version'];
180 - $url_assets = plugin_dir_url( __FILE__ ) . 'assets/';
201 + /**
202 + * Include main plugin page with Style and Script
203 + *
204 + * @since 1.0
205 + */
206 + public function plugin_page()
207 + {
208 + global $wow_plugin_page;
209 + $wow_plugin_page = $this->plugin["slug"];
210 + require_once "partials/main.php";
211 + }
181 212
182 - $pre_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
213 + /**
214 + * Include Styles and Scripts on the plugin admin page
215 + *
216 + * @since 1.0
217 + */
218 + public function admin_style_script($hook)
219 + {
220 + $page = "wow-plugins_page_" . $this->plugin["slug"];
183 221
184 - // include the main style
185 - wp_enqueue_style( $slug . '-admin', $url_assets . 'css/style.css', false, $version );
222 + if ($page != $hook) {
223 + return false;
224 + }
186 225
187 - // include fontAwesome icon
188 - $url_fontawesome = $this->plugin['url'] . 'vendors/fontawesome/css/fontawesome-all.min.css';
189 - wp_enqueue_style( $slug . '-fontawesome', $url_fontawesome, null, '5.15.3' );
226 + $slug = $this->plugin["slug"];
227 + $version = $this->plugin["version"];
228 + $url_assets = $this->plugin["url"] . "assets/";
190 229
191 - // include fonticonpicker styles & scripts
192 - $fonticonpicker_js = $url_assets . 'fonticonpicker/fonticonpicker.min.js';
193 - wp_enqueue_script( $slug . '-fonticonpicker', $fonticonpicker_js, array( 'jquery' ) );
230 + $pre_suffix = defined("SCRIPT_DEBUG") && SCRIPT_DEBUG ? "" : ".min";
194 231
195 - $fonticonpicker_css = $url_assets . 'fonticonpicker/css/fonticonpicker.min.css';
196 - wp_enqueue_style( $slug . '-fonticonpicker', $fonticonpicker_css );
232 + // include the main style
233 + wp_enqueue_style($slug . "-admin", $url_assets . "css/admin-style" . $pre_suffix . ".css", false, $version);
197 234
198 - $fonticonpicker_dark_css = $url_assets . 'fonticonpicker/fonticonpicker.darkgrey.min.css';
199 - wp_enqueue_style( $slug . '-fonticonpicker-darkgrey', $fonticonpicker_dark_css );
235 + // include fontAwesome icon
236 + $url_fontawesome = $url_assets . "vendors/fontawesome/css/fontawesome-all" . $pre_suffix . ".css";
237 + wp_enqueue_style($slug . "-fontawesome", $url_fontawesome, null, "5.14");
200 238
201 - // include the color picker
202 - wp_enqueue_style( 'wp-color-picker' );
203 - wp_enqueue_script( 'wp-color-picker' );
239 + // include fonticonpicker styles & scripts
240 + $fonticonpicker_js = $url_assets . "vendors/fonticonpicker/fonticonpicker.min.js";
241 + wp_enqueue_script($slug . "-fonticonpicker", $fonticonpicker_js, ["jquery"]);
204 242
205 - $url_alpha = $url_assets . 'js/wp-color-picker-alpha.min.js';
206 - wp_enqueue_script( 'wp-color-picker-alpha', $url_alpha, array( 'wp-color-picker' ) );
243 + $fonticonpicker_css = $url_assets . "vendors/fonticonpicker/css/fonticonpicker.min.css";
244 + wp_enqueue_style($slug . "-fonticonpicker", $fonticonpicker_css);
207 245
208 - // include tooltip script
209 - wp_enqueue_script( 'jquery-ui-tooltip' );
246 + $fonticonpicker_dark_css = $url_assets . "vendors/fonticonpicker/fonticonpicker.darkgrey.min.css";
247 + wp_enqueue_style($slug . "-fonticonpicker-darkgrey", $fonticonpicker_dark_css);
210 248
211 - // include sortable
212 - wp_enqueue_script( 'jquery-ui-sortable' );
249 + // include the color picker
250 + wp_enqueue_style("wp-color-picker");
251 + wp_enqueue_script("wp-color-picker");
213 252
253 + // include tooltip script
254 + wp_enqueue_script("jquery-ui-tooltip");
214 255
215 - // include the plugin admin script
216 - $url_script = $url_assets . 'js/script' . $pre_suffix . '.js';
217 - wp_enqueue_script( $slug . '-admin', $url_script, array( 'jquery' ), $version, true );
218 - }
256 + // include sortable
257 + wp_enqueue_script("jquery-ui-sortable");
219 258
220 - /**
221 - * Add the link to the plugin page on Plugins page
222 - *
223 - * @param $actions
224 - * @param $plugin_file - the plugin main file
225 - *
226 - * @return mixed
227 - */
228 - public function action_links( $actions, $plugin_file ) {
229 - if ( false === strpos( $plugin_file, plugin_basename( $this->plugin['file'] ) ) ) {
230 - return $actions;
231 - }
232 - $settings_link
233 - = '<a href="admin.php?page=' . esc_attr( $this->plugin['slug'] ) . '">' . esc_attr__( 'Settings',
234 - 'bubble-menu' ) . '</a>';
235 - array_unshift( $actions, $settings_link );
259 + // include an alpha rgba color picker
260 + $url_alpha = $url_assets . "js/wp-color-picker-alpha" . $pre_suffix . ".js";
261 + wp_enqueue_script("wp-color-picker-alpha", $url_alpha, ["wp-color-picker"]);
236 262
237 - return $actions;
238 - }
263 + // include the plugin admin script
264 + $url_script = $url_assets . "js/admin-script.js";
265 + wp_enqueue_script($slug . "-admin", $url_script, ["jquery"], $version, true);
266 + }
239 267
240 - /**
241 - * Add custom text in the footer on the wow plugin page
242 - *
243 - * @param $footer_text - text in the footer
244 - *
245 - * @return string - end text in the footer
246 - * @since 1.0
247 - */
248 - public function rate_us( $footer_text ) {
249 - global $wow_plugin_page;
250 - if ( $wow_plugin_page == $this->plugin['slug'] ) {
251 - $rate_text = sprintf( __( 'Thank you for using <a href="%1$s" target="_blank">' . esc_attr( $this->plugin['name'] )
252 - . '</a>! Please <a href="%2$s" target="_blank">rate us on '
253 - . esc_attr( $this->rating['website'] ) . '</a>', 'bubble-menu' ),
254 - $this->url['home'],
255 - $this->rating['url'] );
268 + /**
269 + * Add the link to the plugin page on Plugins page
270 + *
271 + * @param $actions
272 + * @param $plugin_file - the plugin main file
273 + *
274 + * @return mixed
275 + */
276 + public function action_links($actions, $plugin_file)
277 + {
278 + if (false === strpos($plugin_file, plugin_basename($this->plugin["file"]))) {
279 + return $actions;
280 + }
281 + $settings_link = '<a href="admin.php?page=' . $this->plugin["slug"] . '">' . esc_attr__("Settings", $this->plugin["text"]) . "</a>";
282 + array_unshift($actions, $settings_link);
256 283
257 - return str_replace( '</span>', '', $footer_text ) . ' | ' . $rate_text . '</span>';
258 - } else {
259 - return $footer_text;
260 - }
261 - }
284 + return $actions;
285 + }
262 286
263 - function item_save() {
264 - $response = 'No';
265 - if ( isset( $_POST[ $this->plugin['slug'] . '_nonce' ] ) ) {
266 - if ( ! empty( $_POST )
267 - && wp_verify_nonce( $_POST[ $this->plugin['slug'] . '_nonce' ], $this->plugin['slug'] . '_action' )
268 - && current_user_can( 'manage_options' )
269 - ) {
270 - $response = self:: save_data();
271 - }
272 - }
287 + /**
288 + * Add custom text in the footer on the wow plugin page
289 + *
290 + * @param $footer_text - text in the footer
291 + *
292 + * @return string - end text in the footer
293 + * @since 1.0
294 + */
295 + public function rate_us($footer_text)
296 + {
297 + global $wow_plugin_page;
298 + if ($wow_plugin_page == $this->plugin["slug"]) {
299 + $rate_text = sprintf(__('Thank you for using <a href="%1$s" target="_blank">' . $this->plugin["name"] . '</a>! Please <a href="%2$s" target="_blank">rate us on ' . $this->rating["website"] . "</a>", $this->plugin["text"]), $this->url["home"], $this->rating["url"]);
273 300
274 - wp_send_json( $response );
301 + return str_replace("</span>", "", $footer_text) . " | " . $rate_text . "</span>";
302 + } else {
303 + return $footer_text;
304 + }
305 + }
275 306
276 - wp_die();
277 - }
307 + /*
308 + * Check the post parameter from wow plugin
309 + *
310 + * @since 1.0
311 + */
312 + public function plugin_check()
313 + {
314 + if (isset($_POST[$this->plugin["slug"] . "_nonce"])) {
315 + if (!empty($_POST) && wp_verify_nonce($_POST[$this->plugin["slug"] . "_nonce"], $this->plugin["slug"] . "_action") && current_user_can("manage_options")) {
316 + self::save_data();
317 + }
318 + }
319 + }
278 320
279 - /**
280 - * Save and Update the Item into the plugin Database
281 - *
282 - * @return array response from DB
283 - *
284 - * @since 1.0
285 - */
286 - public function save_data() {
287 - global $wpdb;
288 - $add = ( isset( $_REQUEST['add'] ) ) ? absint( $_REQUEST['add'] ) : '';
289 - $table = $wpdb->prefix . 'wow_' . $this->plugin['prefix'];
290 - $id = absint( $_POST['tool_id'] );
291 - $title = sanitize_text_field( $_POST['title'] );
292 - $param = map_deep( $_POST['param'], array( $this, 'sanitize_param' ) );
293 - $param['popupcontent'] = wp_kses_post( $_POST['param']['popupcontent'] );
294 - $param['item_link'] = map_deep( $_POST['param']['item_link'], 'sanitize_url' );
295 - $param = serialize( $param );
321 + /**
322 + * Save and Update the Item into the plugin Database
323 + *
324 + * @return array response from DB
325 + *
326 + * @since 1.0
327 + */
328 + public function save_data()
329 + {
330 + $save_class = __NAMESPACE__ . "\\Wow_DB_Update";
331 + $objItem = new $save_class($this->plugin["dir"], $this->plugin["slug"]);
332 + $add = isset($_REQUEST["add"]) ? absint($_REQUEST["add"]) : "";
333 + $table = isset($_REQUEST["data"]) ? sanitize_text_field($_REQUEST["data"]) : "";
334 + $tool_id = absint($_POST["tool_id"]);
335 + $info = [];
336 + $info["id"] = $tool_id;
337 + $info["title"] = sanitize_text_field($_POST["title"]);
338 + $info["param"] = $_POST["param"];
339 + $response = "";
340 + if ("1" == $add) {
341 + $objItem->create_item($table, $info);
342 + $response = [
343 + "status" => "OK",
344 + "message" => esc_attr__("Item Added", $this->plugin["text"]),
345 + ];
346 + } elseif ("2" == $add) {
347 + $objItem->update_item($table, $info);
348 + $response = [
349 + "status" => "OK",
350 + "message" => esc_attr__("Item Updated", $this->plugin["text"]),
351 + ];
352 + }
296 353
354 + return $response;
355 + }
297 356
298 - $response = array(
299 - 'status' => 'NO',
300 - 'message' => esc_attr__( 'Something went wrong. Contact the plugin developer', 'bubble-menu' ),
301 - );
302 - if ( 1 === $add ) {
303 - $insert = $wpdb->query(
304 - $wpdb->prepare( " INSERT INTO {$table} ( id, title, param ) VALUES ( %d, %s, %s )",
305 - $id,
306 - $title,
307 - $param
308 - ) );
309 - if ( $insert ) {
310 - $response = array(
311 - 'status' => 'OK',
312 - 'message' => esc_attr__( 'Item Added', 'bubble-menu' ),
313 - );
314 - }
315 - } elseif ( 2 === $add ) {
316 - $update =
317 - $wpdb->query(
318 - $wpdb->prepare( " UPDATE {$table} SET title = %s, param = %s WHERE id= %d;",
319 - $title,
320 - $param,
321 - $id
322 - ) );
357 + function item_save()
358 + {
359 + $response = "No";
360 + if (isset($_POST[$this->plugin["slug"] . "_nonce"])) {
361 + if (!empty($_POST) && wp_verify_nonce($_POST[$this->plugin["slug"] . "_nonce"], $this->plugin["slug"] . "_action") && current_user_can("manage_options")) {
362 + $response = self::save_data();
363 + }
364 + }
323 365
324 - if ( ! empty( $update ) ) {
325 - $response = array(
326 - 'status' => 'OK',
327 - 'message' => esc_attr__( 'Item Updated', 'bubble-menu' ),
328 - );
329 - }
330 - }
366 + wp_send_json($response);
331 367
332 - return $response;
333 - }
368 + wp_die();
369 + }
334 370
335 - public function sanitize_param( $value ) {
336 - return wp_unslash( sanitize_text_field( $value ) );
337 - }
371 + /**
372 + * Delete the files from plugin folder in 'uploads'
373 + *
374 + * @param integer $id id of the item
375 + *
376 + * @since 1.0
377 + */
378 + public function delete_file($id = null)
379 + {
380 + $upload = wp_upload_dir();
381 + $basedir = $upload["basedir"] . "/" . $this->plugin["slug"] . "/";
382 + $file_style = $basedir . "style-" . $id . ".css";
383 + $file_script = $basedir . "script-" . $id . ".js";
384 + if (file_exists($file_style)) {
385 + wp_delete_file($file_style);
386 + }
387 + if (file_exists($file_script)) {
388 + wp_delete_file($file_script);
389 + }
338 390
391 + return;
392 + }
339 393
394 + /*
395 + * Notice for updating the plugin
396 + */
397 +
398 + function general_admin_notice()
399 + {
400 + echo '<div class="notice notice-warning wow-plugin-notice is-dismissible">
401 + <p><b>' .
402 + $this->plugin["name"] .
403 + '</b>! In connection with the upgrade of Font Awesome to version 5, we ask you to edit and update all previously created menus. <a href="' .
404 + admin_url() .
405 + "admin.php?page=" .
406 + $this->plugin["slug"] .
407 + '">Go to the ' .
408 + $this->plugin["name"] .
409 + ' page</a></p>
410 + </div>';
411 + }
412 +
413 + function admin_notice_assets()
414 + {
415 + wp_enqueue_script("wow-notice-update", $this->plugin["url"] . "assets/js/notice-update.min.js", ["jquery"], "1.0", true);
416 + }
417 +
418 + function wow_notice_action_callback()
419 + {
420 + update_option("wow_" . $this->plugin["prefix"] . "_notice_action", "read");
421 + wp_die();
422 + }
340 423 }