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 +354 -274 3.0.42.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,317 +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' ) );
50 + add_action("admin_enqueue_scripts", [$this, "admin_style_script"]);
51 + add_action("wp_ajax_wow_item_save", [$this, "item_save"]);
51 52
52 - }
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 + }
53 59
54 - public function wow_message_callback() {
55 - update_option( 'wow_' . $this->plugin['prefix'] . '_message', 'read' );
56 - wp_die();
57 - }
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>";
58 83
59 - /**
60 - * @param string|array $arg text which need show in the tooltip
61 - *
62 - * @return string tooltip for the element
63 - */
64 - static function tooltip( $arg ) {
65 - $tooltip = '';
66 - foreach ( $arg as $key => $value ) {
67 - if ( $key == 'title' ) {
68 - $tooltip .= $value . '<p/>';
69 - } elseif ( $key == 'ul' ) {
70 - $tooltip .= '<ul>';
71 - $arr = $value;
72 - foreach ( $arr as $val ) {
73 - $tooltip .= '<li>' . $val . '</li>';
74 - }
75 - $tooltip .= '</ul>';
76 - } else {
77 - $tooltip .= $value;
78 - }
79 - }
80 - echo "<span class='wow-help dashicons dashicons-editor-help' title='" . wp_kses_post( $tooltip ) . "'></span>";
81 - }
84 + return $tooltip;
85 + }
82 86
83 - /**
84 - * @param array $arg parameters for creating field in the backend
85 - *
86 - * @return string field for displaying
87 - */
88 - static function option( $arg ) {
89 - $id = isset( $arg['id'] ) ? $arg['id'] : null;
90 - $name = isset( $arg['name'] ) ? $arg['name'] : '';
91 - $type = isset( $arg['type'] ) ? $arg['type'] : '';
92 - $func = ! empty( $arg['func'] ) ? ' onchange="' . $arg['func'] . '"' : '';
93 - $options = isset( $arg['option'] ) ? $arg['option'] : '';
94 - $val = $arg['val'];
95 - $separator = isset( $arg['sep'] ) ? $arg['sep'] : '';
96 - $extra_class = '';
97 - if($type == 'text' || $type == 'number' || $type == 'time') {
98 - $extra_class = 'input ';
99 - }
100 - $class = isset( $arg['class'] ) ? ' class="' .$extra_class . $arg['class'] . '"' : ' class="' .$extra_class . '"';
101 - $field = '';
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 = "";
102 103
103 - switch ( $type ) {
104 - case 'radio':
105 - include( 'fields/radio.php' );
106 - break;
107 - case 'checkbox':
108 - include( 'fields/checkbox.php' );
109 - break;
110 - case 'text':
111 - case 'number':
112 - case 'hidden':
113 - case 'time':
114 - include( 'fields/input.php' );
115 - break;
116 - case 'select':
117 - include( 'fields/select.php' );
118 - break;
119 - case 'color':
120 - include( 'fields/color.php' );
121 - break;
122 - case 'editor':
123 - include( 'fields/editor.php' );
124 - break;
125 - }
126 - }
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 + }
127 165
128 - /**
129 - * @param string $tooltip tooltip for element
130 - *
131 - * @return string
132 - */
133 - public function pro( $tooltip = null ) {
134 - $link = admin_url() . 'admin.php?page=' . $this->plugin['slug'] . '&tab=extension';
135 - $title = esc_attr__( 'More features in the PRO version', 'bubble-menu' );
136 - $classes = 'wow-help dashicons dashicons-lock';
137 - $tooltip = ! empty( $tooltip ) ? $title . '<br/>' . $tooltip : $title;
138 - echo '<a href="' . esc_url( $link ) . '" class="' . esc_attr( $classes ) . '" title="' . wp_kses_post( $tooltip ) . '"></a>';
139 - }
166 + return $field;
167 + }
140 168
141 - /**
142 - * Add the plugin page in admin menu
143 - *
144 - * @since 1.0
145 - */
146 - public function add_admin_page() {
147 - $parent = 'wow-company';
148 - $title = $this->plugin['name'] . ' version ' . $this->plugin['version'];
149 - $menu_title = $this->plugin['menu'];
150 - $capability = 'manage_options';
151 - $slug = $this->plugin['slug'];
152 - $function = array( $this, 'plugin_page' );
153 - add_submenu_page( $parent, $title, $menu_title, $capability, $slug, $function );
154 - }
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>';
155 181
156 - /**
157 - * Include main plugin page with Style and Script
158 - *
159 - * @since 1.0
160 - */
161 - public function plugin_page() {
162 - global $wow_plugin_page;
163 - $wow_plugin_page = $this->plugin['slug'];
164 - require_once 'page-main.php';
165 - }
182 + return $pro;
183 + }
166 184
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 + }
167 200
168 - /**
169 - * Include Styles and Scripts on the plugin admin page
170 - *
171 - * @since 1.0
172 - */
173 - public function admin_scripts( $hook ) {
174 - $page = 'wow-plugins_page_' . $this->plugin['slug'];
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 + }
175 212
176 - if ( $page != $hook ) {
177 - return false;
178 - }
179 - $slug = $this->plugin['slug'];
180 - $version = $this->plugin['version'];
181 - $url_assets = plugin_dir_url(__FILE__).'assets/';
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"];
182 221
183 - $pre_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
222 + if ($page != $hook) {
223 + return false;
224 + }
184 225
185 - // include the main style
186 - wp_enqueue_style( $slug . '-admin', $url_assets . 'css/style.css', false, $version );
226 + $slug = $this->plugin["slug"];
227 + $version = $this->plugin["version"];
228 + $url_assets = $this->plugin["url"] . "assets/";
187 229
188 - // include fontAwesome icon
189 - $url_fontawesome = $this->plugin['url'] . 'vendors/fontawesome/css/fontawesome-all.min.css';
190 - wp_enqueue_style( $slug . '-fontawesome', $url_fontawesome, null, '5.15.3' );
230 + $pre_suffix = defined("SCRIPT_DEBUG") && SCRIPT_DEBUG ? "" : ".min";
191 231
192 - // include fonticonpicker styles & scripts
193 - $fonticonpicker_js = $url_assets . 'fonticonpicker/fonticonpicker.min.js';
194 - wp_enqueue_script( $slug . '-fonticonpicker', $fonticonpicker_js, array( 'jquery' ) );
232 + // include the main style
233 + wp_enqueue_style($slug . "-admin", $url_assets . "css/admin-style" . $pre_suffix . ".css", false, $version);
195 234
196 - $fonticonpicker_css = $url_assets . 'fonticonpicker/css/fonticonpicker.min.css';
197 - wp_enqueue_style( $slug . '-fonticonpicker', $fonticonpicker_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");
198 238
199 - $fonticonpicker_dark_css = $url_assets . 'fonticonpicker/fonticonpicker.darkgrey.min.css';
200 - wp_enqueue_style( $slug . '-fonticonpicker-darkgrey', $fonticonpicker_dark_css );
239 + // include fonticonpicker styles & scripts
240 + $fonticonpicker_js = $url_assets . "vendors/fonticonpicker/fonticonpicker.min.js";
241 + wp_enqueue_script($slug . "-fonticonpicker", $fonticonpicker_js, ["jquery"]);
201 242
202 - // include the color picker
203 - wp_enqueue_style( 'wp-color-picker' );
204 - wp_enqueue_script( 'wp-color-picker' );
243 + $fonticonpicker_css = $url_assets . "vendors/fonticonpicker/css/fonticonpicker.min.css";
244 + wp_enqueue_style($slug . "-fonticonpicker", $fonticonpicker_css);
205 245
206 - $url_alpha = $url_assets . 'js/wp-color-picker-alpha.min.js';
207 - wp_enqueue_script( 'wp-color-picker-alpha', $url_alpha, array( 'wp-color-picker' ) );
246 + $fonticonpicker_dark_css = $url_assets . "vendors/fonticonpicker/fonticonpicker.darkgrey.min.css";
247 + wp_enqueue_style($slug . "-fonticonpicker-darkgrey", $fonticonpicker_dark_css);
208 248
209 - // include tooltip script
210 - wp_enqueue_script( 'jquery-ui-tooltip' );
249 + // include the color picker
250 + wp_enqueue_style("wp-color-picker");
251 + wp_enqueue_script("wp-color-picker");
211 252
212 - // include sortable
213 - wp_enqueue_script( 'jquery-ui-sortable' );
253 + // include tooltip script
254 + wp_enqueue_script("jquery-ui-tooltip");
214 255
256 + // include sortable
257 + wp_enqueue_script("jquery-ui-sortable");
215 258
216 - // include the plugin admin script
217 - $url_script = $url_assets . 'js/script' . $pre_suffix . '.js';
218 - wp_enqueue_script( $slug . '-admin', $url_script, array( 'jquery' ), $version, true );
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"]);
219 262
220 - }
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 + }
221 267
222 - /**
223 - * Add the link to the plugin page on Plugins page
224 - *
225 - * @param $actions
226 - * @param $plugin_file - the plugin main file
227 - *
228 - * @return mixed
229 - */
230 - public function action_links( $actions, $plugin_file ) {
231 - if ( false === strpos( $plugin_file, plugin_basename( $this->plugin['file'] ) ) ) {
232 - return $actions;
233 - }
234 - $settings_link
235 - = '<a href="admin.php?page=' . esc_attr( $this->plugin['slug'] ) . '">' . esc_attr__( 'Settings',
236 - 'bubble-menu' ) . '</a>';
237 - array_unshift( $actions, $settings_link );
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);
238 283
239 - return $actions;
240 - }
284 + return $actions;
285 + }
241 286
242 - /**
243 - * Add custom text in the footer on the wow plugin page
244 - *
245 - * @param $footer_text - text in the footer
246 - *
247 - * @return string - end text in the footer
248 - * @since 1.0
249 - */
250 - public function rate_us( $footer_text ) {
251 - global $wow_plugin_page;
252 - if ( $wow_plugin_page == $this->plugin['slug'] ) {
253 - $rate_text = sprintf( __( 'Thank you for using <a href="%1$s" target="_blank">' . esc_attr( $this->plugin['name'] )
254 - . '</a>! Please <a href="%2$s" target="_blank">rate us on '
255 - . esc_attr( $this->rating['website'] ) . '</a>', 'bubble-menu' ), $this->url['home'],
256 - $this->rating['url'] );
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"]);
257 300
258 - return str_replace( '</span>', '', $footer_text ) . ' | ' . $rate_text . '</span>';
259 - } else {
260 - return $footer_text;
261 - }
262 - }
301 + return str_replace("</span>", "", $footer_text) . " | " . $rate_text . "</span>";
302 + } else {
303 + return $footer_text;
304 + }
305 + }
263 306
264 - function item_save() {
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 + }
265 320
266 - $response = 'No';
267 - if ( isset( $_POST[ $this->plugin['slug'] . '_nonce' ] ) ) {
268 - if ( ! empty( $_POST )
269 - && wp_verify_nonce( $_POST[ $this->plugin['slug'] . '_nonce' ], $this->plugin['slug'] . '_action' )
270 - && current_user_can( 'manage_options' )
271 - ) {
272 - $response = self:: save_data();
273 - }
274 - }
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 + }
275 353
276 - wp_send_json( $response );
354 + return $response;
355 + }
277 356
278 - wp_die();
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 + }
279 365
280 - }
366 + wp_send_json($response);
281 367
282 - /**
283 - * Save and Update the Item into the plugin Database
284 - *
285 - * @return array response from DB
286 - *
287 - * @since 1.0
288 - */
289 - public function save_data() {
290 - global $wpdb;
291 - $add = ( isset( $_REQUEST['add'] ) ) ? absint( $_REQUEST['add'] ) : '';
292 - $table = $wpdb->prefix . 'wow_' . $this->plugin['prefix'];
293 - $id = absint( $_POST['tool_id'] );
294 - $title = sanitize_text_field( $_POST['title'] );
295 - $param = map_deep( $_POST['param'], array( $this, 'sanitize_param' ) );
296 - $param['popupcontent'] = wp_kses_post( $_POST['param']['popupcontent'] );
297 - $param = serialize( $param );
368 + wp_die();
369 + }
298 370
299 - $response = array(
300 - 'status' => 'NO',
301 - 'message' => esc_attr__( 'Something went wrong. Contact the plugin developer', 'bubble-menu' ),
302 - );
303 - if ( 1 === $add ) {
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 + }
304 390
305 - $insert = $wpdb->query(
306 - $wpdb->prepare( " INSERT INTO {$table} ( id, title, param ) VALUES ( %d, %s, %s )",
307 - $id,
308 - $title,
309 - $param
310 - ) );
311 - if ( $insert ) {
312 - $response = array(
313 - 'status' => 'OK',
314 - 'message' => esc_attr__( 'Item Added', 'bubble-menu' ),
315 - );
316 - }
391 + return;
392 + }
317 393
318 - } elseif ( 2 === $add ) {
319 - $update =
320 - $wpdb->query(
321 - $wpdb->prepare( " UPDATE {$table} SET title = %s, param = %s WHERE id= %d;",
322 - $title,
323 - $param,
324 - $id
325 - ) );
394 + /*
395 + * Notice for updating the plugin
396 + */
326 397
327 - if ( ! empty( $update ) ) {
328 - $response = array(
329 - 'status' => 'OK',
330 - 'message' => esc_attr__( 'Item Updated', 'bubble-menu' ),
331 - );
332 - }
333 - }
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 + }
334 412
335 - return $response;
336 - }
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 + }
337 417
338 - public function sanitize_param( $value ) {
339 - return wp_unslash( sanitize_text_field( $value ) );
340 - }
341 -
342 -
418 + function wow_notice_action_callback()
419 + {
420 + update_option("wow_" . $this->plugin["prefix"] . "_notice_action", "read");
421 + wp_die();
422 + }
343 423 }