| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | +namespace MaxButtons; | |
| 2 | 3 | defined('ABSPATH') or die('No direct access permitted'); |
| 3 | 4 | |
| 4 | 5 | define('MAXBUTTONS_VERSION_KEY', 'maxbuttons_version'); |
| 5 | 6 | |
| @@ -6,60 +7,61 @@ | ||
| 6 | 7 | class maxButtonsPlugin |
| 7 | 8 | { |
| 8 | 9 | |
| 9 | 10 | protected $installed_version = 0; |
| 10 | - protected $plugin_name; | |
| 11 | + protected $plugin_name; | |
| 11 | 12 | protected $plugin_url; |
| 12 | 13 | protected $plugin_path; |
| 13 | 14 | protected $debug_mode = false; |
| 14 | 15 | protected $footer = array(); |
| 15 | 16 | |
| 16 | - protected static $notices = array(); | |
| 17 | - | |
| 18 | - protected $mainClasses = array(); | |
| 19 | - | |
| 17 | + protected static $notices = array(); | |
| 18 | + | |
| 19 | + protected $mainClasses = array(); | |
| 20 | + | |
| 20 | 21 | protected static $instance; |
| 21 | - | |
| 22 | - /* Class constructor | |
| 22 | + | |
| 23 | + /* Class constructor | |
| 23 | 24 | Add hooks and actions used by this plugin. Sets plugin environment information |
| 24 | 25 | */ |
| 25 | 26 | function __construct() |
| 26 | 27 | { |
| 27 | - maxUtils::timeInit(); // benchmark timer init. | |
| 28 | + maxUtils::timeInit(); // benchmark timer init. | |
| 28 | 29 | |
| 29 | 30 | $this->plugin_url = self::get_plugin_url(); //plugins_url() . '/' . $this->plugin_name; |
| 30 | - $this->plugin_path = self::get_plugin_path(); //plugin_dir_path($rootfile); | |
| 31 | + $this->plugin_path = self::get_plugin_path(); //plugin_dir_path($rootfile); | |
| 31 | 32 | $this->plugin_name = trim(basename($this->plugin_path), '/'); |
| 32 | - | |
| 33 | - $this->installed_version = get_option(MAXBUTTONS_VERSION_KEY); | |
| 34 | - | |
| 33 | + | |
| 34 | + $this->installed_version = get_option(MAXBUTTONS_VERSION_KEY); | |
| 35 | + | |
| 35 | 36 | if ( defined('MAXBUTTONS_DEBUG') && MAXBUTTONS_DEBUG) |
| 36 | 37 | $this->debug_mode = true; |
| 37 | - | |
| 38 | + | |
| 38 | 39 | add_action('plugins_loaded', array($this, 'load_textdomain')); |
| 39 | 40 | |
| 40 | 41 | add_filter('widget_text', 'do_shortcode'); |
| 41 | - add_shortcode('maxbutton', array($this, 'shortcode')); | |
| 42 | + add_shortcode('maxbutton', array($this, 'shortcode')); | |
| 42 | 43 | |
| 43 | - add_action("mb-footer", array($this, 'do_footer'),10,3); | |
| 44 | - add_action("wp_footer", array($this, "footer")); | |
| 45 | - | |
| 44 | + add_action("mb-footer", array($this, 'do_footer'),10,3); | |
| 45 | + add_action("wp_footer", array($this, "footer")); | |
| 46 | + | |
| 46 | 47 | // Media buttons |
| 47 | 48 | add_action('media_buttons', array($this,'media_button')); |
| 48 | 49 | |
| 49 | 50 | add_filter('plugin_action_links', array($this, "plugin_action_links"), 10, 2); |
| 50 | 51 | add_filter('plugin_row_meta', array($this, 'plugin_row_meta'), 10, 2); |
| 51 | - | |
| 52 | + | |
| 52 | 53 | if( is_admin()) |
| 53 | - { | |
| 54 | + { | |
| 54 | 55 | add_action('admin_enqueue_scripts', array($this,'add_admin_styles')); |
| 55 | - add_action('admin_enqueue_scripts', array($this,'add_admin_scripts')); | |
| 56 | - | |
| 56 | + add_action('admin_enqueue_scripts', array($this,'add_admin_scripts')); | |
| 57 | + add_action('admin_enqueue_scripts', array(maxUtils::namespaceit('maxUtils'), 'fixFAConflict'),999); | |
| 58 | + | |
| 57 | 59 | add_action('admin_init', array($this,'register_settings' )); |
| 58 | - | |
| 60 | + | |
| 59 | 61 | add_action('admin_init', array($this, 'do_review_notice')); // Ask for review |
| 60 | - add_action('admin_init', array('maxInstall','check_database')); | |
| 61 | - | |
| 62 | + add_action('admin_init', array(maxUtils::namespaceit('maxInstall'),'check_database')); | |
| 63 | + | |
| 62 | 64 | add_action('admin_menu', array($this, 'admin_menu')); |
| 63 | 65 | add_action('admin_footer', array($this, "footer")); |
| 64 | 66 | add_filter("admin_footer_text",array($this, "admin_footer_text")); |
| 65 | 67 | |
| @@ -66,153 +68,160 @@ | ||
| 66 | 68 | // errors in user space. No internal error but user output friendly issues |
| 67 | 69 | add_action("mb/editor/display_notices", array($this,"display_notices"), 99); |
| 68 | 70 | add_action("mb/collection/display_notices", array($this,"display_notices"), 99); |
| 69 | 71 | add_action('mb/header/display_notices', array($this, 'display_notices'), 99); |
| 70 | - | |
| 71 | - add_action("wp_ajax_getAjaxButtons", array('maxButtonsAdmin', 'getAjaxButtons')); | |
| 72 | - add_action("wp_ajax_set_review_notice_status", array($this, "setReviewNoticeStatus")); | |
| 73 | 72 | |
| 73 | + add_action("wp_ajax_getAjaxButtons", array(maxUtils::namespaceit('maxButtonsAdmin'), 'getAjaxButtons')); | |
| 74 | + add_action("wp_ajax_set_review_notice_status", array($this, "setReviewNoticeStatus")); | |
| 75 | + | |
| 74 | 76 | // Collection AJAX |
| 75 | - add_action("wp_ajax_collection-edit", array("maxCollections", "ajax_save")); | |
| 76 | - add_action('wp_ajax_mbpro_collection_block', array("maxCollections", "ajax_action")); // all block level ajax stuff - for logged in users - backend | |
| 77 | - add_action('wp_ajax_mb_button_action', array('maxButtons', "ajax_action")); | |
| 77 | + add_action("wp_ajax_collection-edit", array(maxUtils::namespaceit("maxCollections"), "ajax_save")); | |
| 78 | + add_action('wp_ajax_mbpro_collection_block', array(maxUtils::namespaceit("maxCollections"), "ajax_action")); // all block level ajax stuff - for logged in users - backend | |
| 79 | + add_action('wp_ajax_mb_button_action', array(maxUtils::namespaceit('maxButtons'), "ajax_action")); | |
| 80 | + | |
| 81 | + add_action('wp_ajax_maxajax', array(maxUtils::namespaceit('maxUtils'), 'ajax_action')); | |
| 78 | 82 | } |
| 79 | 83 | // FRONT AJAX |
| 80 | - add_action('wp_ajax_mbpro_collection_block_front', array("maxCollections", "ajax_action_front")); // front end for all users | |
| 81 | - add_action('wp_ajax_nopriv_mbpro_collection_block_front', array("maxCollections", "ajax_action_front")); | |
| 82 | - | |
| 84 | + add_action('wp_ajax_mbpro_collection_block_front', array(maxUtils::namespaceit("maxCollections"), "ajax_action_front")); // front end for all users | |
| 85 | + add_action('wp_ajax_nopriv_mbpro_collection_block_front', array(maxUtils::namespaceit("maxCollections"), "ajax_action_front")); | |
| 86 | + | |
| 83 | 87 | // front scripts |
| 84 | 88 | add_action('wp_enqueue_scripts', array($this, 'front_scripts')); |
| 85 | - | |
| 89 | + add_action('wp_enqueue_scripts', array(maxUtils::namespaceit('maxUtils'), 'fixFAConflict'),999); | |
| 90 | + | |
| 86 | 91 | $this->setMainClasses(); // struct for override functionality |
| 87 | - | |
| 88 | - // The second the blocks are being loaded, check dbase integrity | |
| 89 | - add_action("mb_blockclassesloaded", array($this, "check_database")); | |
| 90 | - | |
| 92 | + | |
| 93 | + // The second the blocks are being loaded, check dbase integrity | |
| 94 | + add_action("mb_blockclassesloaded", array($this, "check_database")); | |
| 95 | + | |
| 91 | 96 | // setup page hooks and shortcode |
| 92 | 97 | add_shortcode('maxcollection', array($this, 'collection_shortcode')); |
| 93 | - if (! is_admin()) | |
| 98 | + if (! is_admin()) | |
| 94 | 99 | $hook_bool = maxCollections::setupHooks(); // setup the hooks to insert collections |
| 95 | 100 | |
| 96 | 101 | self::$instance = $this; |
| 97 | - maxIntegrations::init(); // fire the integrations. | |
| 102 | + maxIntegrations::init(); // fire the integrations. | |
| 98 | 103 | } |
| 99 | - | |
| 104 | + | |
| 100 | 105 | public static function getInstance() |
| 101 | 106 | { |
| 102 | 107 | return self::$instance; |
| 103 | 108 | } |
| 104 | - | |
| 109 | + | |
| 105 | 110 | public function setMainClasses() |
| 106 | 111 | { |
| 107 | 112 | $classes = array( |
| 108 | 113 | "button" => "maxButton", |
| 109 | 114 | "buttons" => "maxButtons", |
| 110 | - "block" => "maxBlock", | |
| 111 | - "admin" => "maxButtonsAdmin", | |
| 112 | - "install" => "maxInstall", | |
| 115 | + "block" => "maxBlock", | |
| 116 | + "admin" => "maxButtonsAdmin", | |
| 117 | + "install" => "maxInstall", | |
| 113 | 118 | "groups" => "maxGroups", |
| 114 | - "collections" => "maxCollections", | |
| 119 | + "collections" => "maxCollections", | |
| 115 | 120 | "collection" => "maxCollection", |
| 116 | 121 | "pack" => "maxPack", |
| 117 | 122 | |
| 118 | - ); | |
| 119 | - | |
| 120 | - $this->mainClasses = $classes; | |
| 123 | + ); | |
| 124 | + | |
| 125 | + $this->mainClasses = $classes; | |
| 121 | 126 | } |
| 122 | - | |
| 127 | + | |
| 123 | 128 | // from block loader action. Checks if all parts of the table are there, or panic if not. |
| 124 | 129 | public function check_database($blocks) |
| 125 | 130 | { |
| 126 | 131 | maxUtils::addTime("Check database"); |
| 127 | - | |
| 128 | - $sql = "SELECT id,name,status,cache, created "; | |
| 129 | - foreach ($blocks as $block => $class) | |
| 132 | + | |
| 133 | + $sql = "SELECT id,name,status,cache, created "; | |
| 134 | + foreach ($blocks as $block => $class) | |
| 130 | 135 | { |
| 131 | - $sql .= ", $block"; | |
| 132 | - } | |
| 133 | - $sql .= " from " . maxUtils::get_table_name() . " limit 1"; | |
| 134 | - | |
| 135 | - global $wpdb; | |
| 136 | + $sql .= ", $block"; | |
| 137 | + } | |
| 138 | + $sql .= " from " . maxUtils::get_table_name() . " limit 1"; | |
| 139 | + | |
| 140 | + global $wpdb; | |
| 136 | 141 | $wpdb->hide_errors(); |
| 137 | - $result = $wpdb->get_results($sql); | |
| 138 | - | |
| 139 | - | |
| 140 | - // check this query for errors. If there is an error, one or more database fields are missing. Fix that. | |
| 141 | - if (isset($wpdb->last_error) && $wpdb->last_error != '') | |
| 142 | + $result = $wpdb->get_results($sql); | |
| 143 | + | |
| 144 | + | |
| 145 | + // check this query for errors. If there is an error, one or more database fields are missing. Fix that. | |
| 146 | + if (isset($wpdb->last_error) && $wpdb->last_error != '') | |
| 142 | 147 | { |
| 143 | - | |
| 144 | - $install = $this->getClass("install"); | |
| 148 | + | |
| 149 | + $install = $this->getClass("install"); | |
| 145 | 150 | $install::create_database_table(); |
| 146 | 151 | $install::migrate(); |
| 147 | 152 | } |
| 148 | - | |
| 149 | - | |
| 153 | + | |
| 154 | + | |
| 150 | 155 | maxUtils::addTime("End check database"); |
| 151 | 156 | } |
| 152 | - | |
| 157 | + | |
| 153 | 158 | public function getClass($class) |
| 154 | 159 | { |
| 155 | 160 | |
| 156 | - if (isset($this->mainClasses[$class])) | |
| 161 | + if (isset($this->mainClasses[$class])) | |
| 157 | 162 | { |
| 158 | - $load_class = $this->mainClasses[$class]; | |
| 163 | + $load_class = maxUtils::namespaceit($this->mainClasses[$class]); | |
| 159 | 164 | if (method_exists($load_class,'getInstance')) |
| 160 | 165 | { |
| 161 | - return $load_class::getInstance(); | |
| 166 | + return $load_class::getInstance(); | |
| 162 | 167 | } |
| 163 | 168 | return new $load_class; |
| 164 | 169 | } |
| 165 | 170 | } |
| 166 | - | |
| 171 | + | |
| 167 | 172 | /* Load the plugin textdomain */ |
| 168 | 173 | public function load_textdomain() |
| 169 | 174 | { |
| 170 | - // see: http://geertdedeckere.be/article/loading-wordpress-language-files-the-right-way | |
| 175 | + // see: http://geertdedeckere.be/article/loading-wordpress-language-files-the-right-way | |
| 171 | 176 | $domain = 'maxbuttons'; |
| 172 | 177 | // The "plugin_locale" filter is also used in load_plugin_textdomain() |
| 173 | 178 | $locale = apply_filters('plugin_locale', get_locale(), $domain); |
| 174 | 179 | |
| 175 | - load_textdomain($domain, WP_LANG_DIR.'/maxbuttons/'.$domain.'-'.$locale.'.mo'); | |
| 180 | + load_textdomain($domain, WP_LANG_DIR.'/maxbuttons/'.$domain.'-'.$locale.'.mo'); | |
| 176 | 181 | $res = load_plugin_textdomain('maxbuttons', false, $this->plugin_name . '/languages/'); |
| 177 | - | |
| 182 | + | |
| 178 | 183 | } |
| 179 | - | |
| 180 | - | |
| 184 | + | |
| 185 | + | |
| 186 | + /** WP Settings framework. Registers settings used on maxbuttons-settings.php page */ | |
| 181 | 187 | public function register_settings() |
| 182 | 188 | { |
| 183 | 189 | register_setting( 'maxbuttons_settings', 'maxbuttons_user_level' ); |
| 184 | 190 | register_setting( 'maxbuttons_settings', 'maxbuttons_noshowtinymce' ); |
| 185 | - register_setting( 'maxbuttons_settings', 'maxbuttons_minify' ); | |
| 186 | - register_setting( 'maxbuttons_settings', 'maxbuttons_hidedescription' ); | |
| 191 | + register_setting( 'maxbuttons_settings', 'maxbuttons_minify' ); | |
| 192 | + register_setting( 'maxbuttons_settings', 'maxbuttons_hidedescription' ); | |
| 193 | + register_setting( 'maxbuttons_settings', 'maxbuttons_forcefa') ; | |
| 194 | + register_setting( 'maxbuttons_settings', 'maxbuttons_borderbox'); | |
| 195 | + register_setting( 'maxbuttons_settings', 'maxbuttons_protocol'); | |
| 187 | 196 | } |
| 188 | - | |
| 189 | - protected function checkbox_option($options) | |
| 197 | + | |
| 198 | + protected function checkbox_option($options) | |
| 190 | 199 | { |
| 191 | - if (! isset($options["maxbuttons_minify"])) | |
| 192 | - $options["maxbuttons_minify"] = 0; | |
| 193 | - | |
| 200 | + if (! isset($options["maxbuttons_minify"])) | |
| 201 | + $options["maxbuttons_minify"] = 0; | |
| 202 | + | |
| 194 | 203 | return $options; |
| 195 | - | |
| 204 | + | |
| 196 | 205 | } |
| 197 | 206 | |
| 198 | 207 | /** Returns the full path of the plugin installation directory */ |
| 199 | 208 | public static function get_plugin_path() |
| 200 | 209 | { |
| 201 | - return plugin_dir_path(MAXBUTTONS_ROOT_FILE); | |
| 210 | + return plugin_dir_path(MAXBUTTONS_ROOT_FILE); | |
| 202 | 211 | } |
| 203 | - | |
| 204 | - /** Returns the full URL of the plugin installation path */ | |
| 212 | + | |
| 213 | + /** Returns the full URL of the plugin installation path */ | |
| 205 | 214 | public static function get_plugin_url() |
| 206 | 215 | { |
| 207 | 216 | $url = plugin_dir_url(MAXBUTTONS_ROOT_FILE); |
| 208 | 217 | return $url; |
| 209 | 218 | } |
| 210 | - | |
| 219 | + | |
| 211 | 220 | /** Returns the current installed version */ |
| 212 | 221 | public function get_installed_version() |
| 213 | 222 | { |
| 214 | - return $this->installed_version; | |
| 223 | + return $this->installed_version; | |
| 215 | 224 | } |
| 216 | 225 | |
| 217 | 226 | /** Installs and adds the main menu and the submenu items */ |
| 218 | 227 | function admin_menu() { |
| @@ -228,18 +237,18 @@ | ||
| 228 | 237 | $menu_title = __('MaxButtons', 'maxbuttons'); |
| 229 | 238 | $capability = $maxbuttons_capabilities; |
| 230 | 239 | $admin_capability = 'manage_options'; |
| 231 | 240 | $menu_slug = 'maxbuttons-controller'; |
| 232 | - $function = array($this, 'load_admin_page'); | |
| 241 | + $function = array($this, 'load_admin_page'); | |
| 233 | 242 | $icon_url = $this->plugin_url . 'images/mb-peach-icon.png'; |
| 234 | - $submenu_function = array($this, 'load_admin_page'); | |
| 235 | - | |
| 236 | - add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url); | |
| 237 | - | |
| 243 | + $submenu_function = array($this, 'load_admin_page'); | |
| 244 | + | |
| 245 | + add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, 81); | |
| 246 | + | |
| 238 | 247 | // We add this submenu page with the same slug as the parent to ensure we don't get duplicates |
| 239 | 248 | $sub_menu_title = __('Buttons', 'maxbuttons'); |
| 240 | 249 | $admin_pages[] = add_submenu_page($menu_slug, $page_title, $sub_menu_title, $capability, $menu_slug, $function); |
| 241 | - | |
| 250 | + | |
| 242 | 251 | // Now add the submenu page for the Add New page |
| 243 | 252 | $submenu_page_title = __('MaxButtons: Add/Edit Button', 'maxbuttons'); |
| 244 | 253 | $submenu_title = __('Add New', 'maxbuttons'); |
| 245 | 254 | $submenu_slug = 'maxbuttons-controller&action=edit'; |
| @@ -245,14 +254,9 @@ | ||
| 245 | 254 | $submenu_slug = 'maxbuttons-controller&action=edit'; |
| 246 | 255 | //$submenu_function = 'maxbuttons_button'; |
| 247 | 256 | $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function); |
| 248 | 257 | |
| 249 | - // Now add the submenu page for the Export page | |
| 250 | - $submenu_page_title = __('MaxButtons: Social Share', 'maxbuttons'); | |
| 251 | - $submenu_title = __('Social Share', 'maxbuttons'); | |
| 252 | - $submenu_slug = 'maxbuttons-collections'; | |
| 253 | - $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function); | |
| 254 | - | |
| 258 | + | |
| 255 | 259 | // Now add the submenu page for the Go Pro page |
| 256 | 260 | $submenu_page_title = __('MaxButtons: Upgrade to Pro', 'maxbuttons'); |
| 257 | 261 | $submenu_title = __('Upgrade to Pro', 'maxbuttons'); |
| 258 | 262 | $submenu_slug = 'maxbuttons-pro'; |
| @@ -271,166 +275,186 @@ | ||
| 271 | 275 | $submenu_title = __('Support', 'maxbuttons'); |
| 272 | 276 | $submenu_slug = 'maxbuttons-support'; |
| 273 | 277 | //$submenu_function = 'maxbuttons_support'; |
| 274 | 278 | $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $admin_capability, $submenu_slug, $submenu_function); |
| 275 | - | |
| 276 | - } | |
| 277 | - | |
| 279 | + | |
| 280 | + // Now add the submenu page for the Export page | |
| 281 | + $submenu_page_title = __('MaxButtons: Share Buttons', 'maxbuttons'); | |
| 282 | + $submenu_title = __('Share Buttons', 'maxbuttons'); | |
| 283 | + $submenu_slug = 'maxbuttons-collections'; | |
| 284 | + $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function); | |
| 285 | + | |
| 286 | + } | |
| 287 | + | |
| 278 | 288 | function load_admin_page($page) |
| 279 | 289 | { |
| 280 | 290 | $page = sanitize_text_field($_GET["page"]); |
| 281 | - | |
| 282 | - switch($page) | |
| 291 | + | |
| 292 | + switch($page) | |
| 283 | 293 | { |
| 284 | - case "maxbuttons-button": | |
| 285 | - $pagepath = "includes/maxbuttons-button.php"; | |
| 294 | + case "maxbuttons-button": | |
| 295 | + $pagepath = "includes/maxbuttons-button.php"; | |
| 286 | 296 | break; |
| 287 | - case "maxbuttons-support": | |
| 297 | + case "maxbuttons-support": | |
| 288 | 298 | $pagepath = "includes/maxbuttons-support.php"; |
| 289 | 299 | break; |
| 290 | - case "maxbuttons-settings": | |
| 291 | - $pagepath = "includes/maxbuttons-settings.php"; | |
| 300 | + case "maxbuttons-settings": | |
| 301 | + $pagepath = "includes/maxbuttons-settings.php"; | |
| 292 | 302 | break; |
| 293 | - case "maxbuttons-pro": | |
| 294 | - $pagepath = "includes/maxbuttons-pro.php"; | |
| 303 | + case "maxbuttons-pro": | |
| 304 | + $pagepath = "includes/maxbuttons-pro.php"; | |
| 295 | 305 | break; |
| 296 | - case "maxbuttons-collections": | |
| 297 | - $pagepath = "includes/maxbuttons-collections.php"; | |
| 298 | - break; | |
| 306 | + case "maxbuttons-collections": | |
| 307 | + $pagepath = "includes/maxbuttons-collections.php"; | |
| 308 | + break; | |
| 299 | 309 | default: |
| 300 | - $pagepath = "includes/maxbuttons-controller.php"; | |
| 310 | + $pagepath = "includes/maxbuttons-controller.php"; | |
| 301 | 311 | break; |
| 302 | 312 | } |
| 303 | - $pagepath = $this->plugin_path . $pagepath; | |
| 304 | - | |
| 305 | - include(apply_filters("mb-load-admin-page-$page", $pagepath)); | |
| 313 | + $pagepath = $this->plugin_path . $pagepath; | |
| 314 | + | |
| 315 | + include(apply_filters("mb-load-admin-page-$page", $pagepath)); | |
| 306 | 316 | } |
| 307 | 317 | |
| 308 | 318 | |
| 309 | - function add_admin_styles($hook) { | |
| 310 | - // only hook in maxbuttons realm. | |
| 319 | + function add_admin_styles($hook) { | |
| 320 | + // only hook in maxbuttons realm. | |
| 311 | 321 | if ( strpos($hook,'maxbuttons') === false && $hook != 'post.php' && $hook != 'post-new.php' ) |
| 312 | 322 | { |
| 313 | 323 | if (! isset($_GET['fl_builder'])) // exception for beaver builder |
| 314 | 324 | return; |
| 315 | 325 | } |
| 316 | - | |
| 317 | - $fa_url = apply_filters("mb_fa_url", $this->plugin_url . 'assets/libraries/font-awesome/css/font-awesome.min.css'); | |
| 326 | + | |
| 327 | + $version = MAXBUTTONS_VERSION_NUM; | |
| 328 | + | |
| 329 | + $fa_url = apply_filters("mb_fa_url", $this->plugin_url . 'assets/libraries/font-awesome/css/font-awesome.min.css', array(), $version); | |
| 318 | 330 | if ($fa_url != false && $fa_url != '') |
| 319 | - { | |
| 320 | - wp_register_style('mbpro-font-awesome', $fa_url ); | |
| 321 | - wp_enqueue_style('mbpro-font-awesome'); | |
| 331 | + { | |
| 332 | + wp_register_style('mbpro-font-awesome', $fa_url, array(), $version); | |
| 333 | + wp_enqueue_style('mbpro-font-awesome'); | |
| 322 | 334 | } |
| 323 | - | |
| 324 | - wp_enqueue_style('wp-color-picker'); | |
| 325 | - wp_enqueue_style('maxbuttons-css', $this->plugin_url . 'assets/css/style.css'); | |
| 326 | - | |
| 335 | + | |
| 336 | + wp_enqueue_style('wp-color-picker'); | |
| 337 | + wp_enqueue_style('maxbuttons-css', $this->plugin_url . 'assets/css/style.css', array(), $version); | |
| 338 | + | |
| 327 | 339 | } |
| 328 | 340 | |
| 329 | - /** Add Admin scripts | |
| 341 | + /** Add Admin scripts | |
| 330 | 342 | * |
| 331 | 343 | * Uses WP hook for Admin scripts to add needed js. |
| 332 | 344 | */ |
| 333 | - function add_admin_scripts($hook) { | |
| 345 | + function add_admin_scripts($hook) { | |
| 334 | 346 | // only hook in maxbuttons realm. |
| 335 | - if ( strpos($hook,'maxbuttons') === false ) //&& $hook != 'post.php' && $hook != 'post-new.php' | |
| 347 | + if ( strpos($hook,'maxbuttons') === false ) //&& $hook != 'post.php' && $hook != 'post-new.php' | |
| 336 | 348 | return; |
| 337 | - | |
| 349 | + | |
| 338 | 350 | $version = MAXBUTTONS_VERSION_NUM; |
| 339 | - | |
| 340 | - $js_url = trailingslashit($this->plugin_url . 'js'); | |
| 341 | - if (! $this->debug_mode) | |
| 342 | - $js_url .= 'min/'; | |
| 343 | - | |
| 344 | - | |
| 351 | + | |
| 352 | + $js_url = trailingslashit($this->plugin_url . 'js'); | |
| 353 | + if (! $this->debug_mode) | |
| 354 | + $js_url .= 'min/'; | |
| 355 | + | |
| 356 | + | |
| 345 | 357 | wp_enqueue_script('jquery-ui-draggable'); |
| 346 | - | |
| 347 | - //wp_enqueue_script('maxbuttons-colorpicker-js', $js_url .'colpick.js', array('jquery'), $version, true); | |
| 348 | 358 | |
| 349 | - wp_enqueue_script('maxbutton-admin', $js_url . 'maxbuttons-admin.js', array('jquery', 'jquery-ui-draggable', 'maxbuttons-tabs','maxbuttons-modal', 'wp-color-picker', 'underscore'),$version, true); | |
| 359 | + wp_enqueue_script('maxbutton-admin', $js_url . 'maxbuttons-admin.js', array('jquery', 'jquery-ui-draggable', 'maxbuttons-tabs','maxbuttons-modal', 'wp-color-picker', 'underscore'),$version, true); | |
| 350 | 360 | wp_enqueue_script('maxbutton-js-init', $js_url . 'init.js', array('maxbutton-admin','maxcollections','maxbuttons-modal'),$version, true); |
| 351 | - wp_enqueue_script('maxbuttons-tabs', $js_url . 'maxtabs.js', array('jquery'),$version, true); | |
| 361 | + wp_enqueue_script('maxbuttons-tabs', $js_url . 'maxtabs.js', array('jquery'),$version, true); | |
| 362 | + wp_enqueue_script('maxbuttons-responsive', $js_url . 'responsive.js', array('maxbutton-admin'), $version, true ); | |
| 352 | 363 | |
| 364 | + wp_register_script('maxbuttons-ajax', $js_url . 'maxajax.js', array('maxbutton-admin'), $version, true); | |
| 365 | + wp_localize_script('maxbuttons-ajax', 'maxajax', | |
| 366 | + array( | |
| 367 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 368 | + 'ajax_action' => 'maxajax', | |
| 369 | + 'nonce' => wp_create_nonce('maxajax'), | |
| 370 | + )); | |
| 353 | 371 | |
| 354 | - wp_register_script('maxcollections', $js_url . 'maxcollections.js', | |
| 355 | - array('jquery', 'maxbutton-admin', 'jquery-ui-sortable'),$version, true ); | |
| 356 | - | |
| 372 | + wp_enqueue_script('maxbuttons-ajax'); | |
| 373 | + | |
| 374 | + wp_register_script('maxcollections', $js_url . 'maxcollections.js', | |
| 375 | + array('jquery', 'maxbutton-admin', 'jquery-ui-sortable'),$version, true ); | |
| 376 | + | |
| 357 | 377 | $local = array(); |
| 358 | 378 | $local["ajaxurl"] = admin_url( 'admin-ajax.php' ); |
| 359 | - $local["maxurl"] = $this->plugin_url; | |
| 360 | - wp_localize_script('maxbutton-admin', 'mb_ajax', $local); | |
| 361 | - | |
| 379 | + $local["maxurl"] = $this->plugin_url; | |
| 380 | + wp_localize_script('maxbutton-admin', 'mb_ajax', $local); | |
| 381 | + | |
| 362 | 382 | $local = array( |
| 363 | 383 | "leave_page" => __("You have unsaved data, are you sure you want to leave the page?","maxbuttons"), |
| 364 | - 'picker_title' => __('Select your buttons','maxbuttons'), | |
| 365 | - | |
| 366 | - ); | |
| 367 | - wp_localize_script('maxcollections', 'maxcol_wp', $local); | |
| 368 | - | |
| 369 | - $this->load_modal_script(); | |
| 370 | - | |
| 371 | - wp_enqueue_script('maxcollections'); | |
| 372 | - } | |
| 373 | - | |
| 384 | + 'picker_title' => __('Select your buttons','maxbuttons'), | |
| 385 | + | |
| 386 | + ); | |
| 387 | + wp_localize_script('maxcollections', 'maxcol_wp', $local); | |
| 388 | + | |
| 389 | + $this->load_modal_script(); | |
| 390 | + | |
| 391 | + wp_enqueue_script('maxcollections'); | |
| 392 | + } | |
| 393 | + | |
| 374 | 394 | /** Load the Modal Script |
| 375 | 395 | * The modal script is the generic solution for all popups within the plugin. |
| 376 | 396 | */ |
| 377 | - public function load_modal_script() | |
| 397 | + public function load_modal_script() | |
| 378 | 398 | { |
| 379 | 399 | $version = MAXBUTTONS_VERSION_NUM; |
| 380 | - $js_url = trailingslashit($this->plugin_url . 'js'); | |
| 381 | - if (! $this->debug_mode) | |
| 382 | - $js_url .= 'min/'; | |
| 383 | - | |
| 384 | - wp_register_script('maxbuttons-modal', $js_url . 'maxmodal.js', array('jquery','jquery-ui-draggable'), $version, true); | |
| 385 | - // translations of controls and other elements that can be used in maxmodal | |
| 400 | + $js_url = trailingslashit($this->plugin_url . 'js'); | |
| 401 | + if (! $this->debug_mode) | |
| 402 | + $js_url .= 'min/'; | |
| 403 | + | |
| 404 | + wp_register_script('maxbuttons-modal', $js_url . 'maxmodal.js', array('jquery','jquery-ui-draggable'), $version, true); | |
| 405 | + // translations of controls and other elements that can be used in maxmodal | |
| 386 | 406 | $translations = array( |
| 387 | - 'yes' => __("Yes","maxbuttons"), | |
| 388 | - 'no' => __("No","maxbuttons"), | |
| 389 | - 'ok' => __("OK","maxbuttons"), | |
| 390 | - 'cancel' => __("Cancel","maxbuttons"), | |
| 391 | - ); | |
| 392 | - wp_localize_script('maxbuttons-modal', 'modaltext', $translations); | |
| 393 | - wp_enqueue_script('maxbuttons-modal'); | |
| 407 | + 'yes' => __("Yes","maxbuttons"), | |
| 408 | + 'no' => __("No","maxbuttons"), | |
| 409 | + 'ok' => __("OK","maxbuttons"), | |
| 410 | + 'cancel' => __("Cancel","maxbuttons"), | |
| 411 | + ); | |
| 412 | + wp_localize_script('maxbuttons-modal', 'modaltext', $translations); | |
| 413 | + wp_enqueue_script('maxbuttons-modal'); | |
| 394 | 414 | |
| 395 | 415 | } |
| 396 | - | |
| 397 | - /** Load Media Buttons Script | |
| 398 | - | |
| 399 | - Useful for integrations that don't implement the media button but uses the media button JS for loading the button picker | |
| 400 | - | |
| 416 | + | |
| 417 | + /** Load Media Buttons Script | |
| 418 | + * | |
| 419 | + * Useful for integrations that don't implement the media button but uses the media button JS for loading the button picker | |
| 420 | + * | |
| 401 | 421 | */ |
| 402 | - public function load_media_script() | |
| 422 | + public function load_media_script() | |
| 403 | 423 | { |
| 404 | 424 | $version = MAXBUTTONS_VERSION_NUM; |
| 405 | 425 | |
| 406 | - $js_url = trailingslashit($this->plugin_url . 'js'); | |
| 407 | - if (! $this->debug_mode) | |
| 408 | - $js_url .= 'min/'; | |
| 409 | - | |
| 410 | - $fa_url = apply_filters("mb_fa_url", $this->plugin_url . 'assets/libraries/font-awesome/css/font-awesome.min.css'); | |
| 426 | + $js_url = trailingslashit($this->plugin_url . 'js'); | |
| 427 | + if (! $this->debug_mode) | |
| 428 | + $js_url .= 'min/'; | |
| 429 | + | |
| 430 | + $fa_url = apply_filters("mb_fa_url", $this->plugin_url . 'assets/libraries/font-awesome/css/font-awesome.min.css'); | |
| 411 | 431 | if ($fa_url != false && $fa_url != '') |
| 412 | 432 | { |
| 413 | - wp_register_style('mbpro-font-awesome', $fa_url); | |
| 414 | - wp_enqueue_style('mbpro-font-awesome'); | |
| 433 | + wp_register_style('mbpro-font-awesome', $fa_url, array(), $version); | |
| 434 | + wp_enqueue_style('mbpro-font-awesome'); | |
| 415 | 435 | } |
| 416 | - | |
| 417 | - wp_enqueue_script('mb-media-button', $js_url . 'maxbuttons_media_button.js', array('jquery', 'maxbuttons-modal'), $version, true); | |
| 436 | + | |
| 437 | + wp_enqueue_script('mb-media-button', $js_url . 'maxbuttons_media_button.js', array('jquery', 'maxbuttons-modal'), $version, true); | |
| 418 | 438 | $this->load_modal_script(); |
| 419 | - | |
| 439 | + | |
| 420 | 440 | $translations = array( |
| 421 | - 'insert' => __('Insert Button into Editor', 'maxbuttons'), | |
| 422 | - 'loading' => __("Loading your buttons","maxbuttons"), | |
| 423 | - 'select' => __('Select a button from the list below to place the button shortcode in the editor.', 'maxbuttons'), | |
| 424 | - 'cancel' => __('Cancel', 'maxbuttons'), | |
| 425 | - 'windowtitle' => __("Select a MaxButton","maxbuttons"), | |
| 426 | - 'icon' => $this->plugin_url . 'images/mb-peach-32.png', | |
| 427 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 428 | - ); | |
| 429 | - | |
| 430 | - wp_localize_script('mb-media-button','mbtrans', $translations); | |
| 441 | + 'insert' => __('Insert Button into Editor', 'maxbuttons'), | |
| 442 | + 'loading' => __("Loading your buttons","maxbuttons"), | |
| 443 | + 'select' => __('Click on a button from the list below to place the button shortcode in the editor.', 'maxbuttons'), | |
| 444 | + 'cancel' => __('Cancel', 'maxbuttons'), | |
| 445 | + 'windowtitle' => __("Select a MaxButton","maxbuttons"), | |
| 446 | + 'icon' => $this->plugin_url . 'images/mb-peach-32.png', | |
| 447 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 448 | + 'short_url_label' => __('Button URL', 'maxbuttons'), | |
| 449 | + 'short_text_label' => __('Button Text', 'maxbuttons'), | |
| 450 | + 'short_options_explain' => __('If you want to change the URL or Text of the Button, enter the appropiate field. If you want to use the button values, just click Add to editor', 'maxbuttons'), | |
| 451 | + 'short_add_button' => __('Add to Editor', 'maxbuttons'), | |
| 452 | + ); | |
| 453 | + | |
| 454 | + wp_localize_script('mb-media-button','mbtrans', $translations); | |
| 431 | 455 | } |
| 432 | - | |
| 456 | + | |
| 433 | 457 | /** Load Media Button in WP editor |
| 434 | 458 | * |
| 435 | 459 | * The 'add button' interface in WP post and page editor to simplify adding buttons. Loads button plus required Javascript. |
| 436 | 460 | */ |
| @@ -436,9 +460,9 @@ | ||
| 436 | 460 | */ |
| 437 | 461 | function media_button($editor_id) { |
| 438 | 462 | $output = ''; |
| 439 | 463 | |
| 440 | - // options | |
| 464 | + // options | |
| 441 | 465 | if (get_option('maxbuttons_noshowtinymce') == 1) return; |
| 442 | 466 | |
| 443 | 467 | $this->load_media_script(); |
| 444 | 468 | |
| @@ -446,92 +470,93 @@ | ||
| 446 | 470 | |
| 447 | 471 | $title = __('Add Button', 'maxbuttons'); |
| 448 | 472 | $icon = $this->plugin_url . 'images/mb-peach-icon.png'; |
| 449 | 473 | $img = '<span class="wp-media-buttons-icon" style="background-image: url(' . $icon . '); width: 16px; height: 16px; margin-top: 1px;"></span>'; |
| 450 | - $output = '<a href="javascript:void(0);" class="button maxbutton_media_button" data-callback="window.maxMedia.buttonToEditor" title="' . $title . '" style="padding-left: .4em;">' . $img . ' ' . $title . '</a>'; | |
| 474 | + $output = '<a href="javascript:void(0);" class="button maxbutton_media_button" data-callback="window.maxMedia.showShortcodeOptions" title="' . $title . '" style="padding-left: .4em;">' . $img . ' ' . $title . '</a>'; | |
| 451 | 475 | |
| 452 | 476 | echo $output; |
| 453 | 477 | } |
| 454 | - | |
| 455 | - /** Scripts run on front-end | |
| 456 | - Load font-awesome, and limited javascript for the front-end. This is being kept extremely limited for performance reasons. | |
| 478 | + | |
| 479 | + /** Scripts run on front-end | |
| 480 | + * Load font-awesome, and limited javascript for the front-end. This is being kept extremely limited for performance reasons. | |
| 457 | 481 | */ |
| 458 | - public function front_scripts() | |
| 482 | + public function front_scripts() | |
| 459 | 483 | { |
| 460 | - | |
| 461 | - $fa_url = apply_filters("mb_fa_url", $this->plugin_url . 'assets/libraries/font-awesome/css/font-awesome.min.css'); | |
| 484 | + $version = MAXBUTTONS_VERSION_NUM; | |
| 485 | + | |
| 486 | + $fa_url = apply_filters("mb_fa_url", $this->plugin_url . 'assets/libraries/font-awesome/css/font-awesome.min.css'); | |
| 462 | 487 | if ($fa_url != false && $fa_url != '') |
| 463 | 488 | { |
| 464 | - wp_register_style('mbpro-font-awesome', $fa_url); | |
| 465 | - wp_enqueue_style('mbpro-font-awesome'); | |
| 466 | - } | |
| 467 | - | |
| 489 | + wp_register_style('mbpro-font-awesome', $fa_url, array(), $version); | |
| 490 | + wp_enqueue_style('mbpro-font-awesome'); | |
| 491 | + } | |
| 492 | + | |
| 468 | 493 | // load backend script on front in Beaver Builder |
| 469 | 494 | if (isset($_GET['fl_builder'])) |
| 470 | 495 | { |
| 471 | - $this->add_admin_styles('maxbuttons'); | |
| 496 | + $this->add_admin_styles('maxbuttons'); | |
| 472 | 497 | } |
| 473 | - | |
| 474 | - wp_enqueue_script('maxbuttons-front', $this->plugin_url . 'js/min/front.js', array('jquery'), true); | |
| 475 | - $local = array(); | |
| 498 | + | |
| 499 | + wp_enqueue_script('maxbuttons-front', $this->plugin_url . 'js/min/front.js', array('jquery'), $version); | |
| 500 | + $local = array(); | |
| 476 | 501 | $local["ajaxurl"] = admin_url( 'admin-ajax.php' ); |
| 477 | 502 | |
| 478 | - wp_localize_script('maxbuttons-front', 'mb_ajax', $local); | |
| 503 | + wp_localize_script('maxbuttons-front', 'mb_ajax', $local); | |
| 479 | 504 | } |
| 480 | - | |
| 481 | - /** Extra text to display in admin footer */ | |
| 505 | + | |
| 506 | + /** Extra text to display in admin footer */ | |
| 482 | 507 | function admin_footer_text($text) |
| 483 | 508 | { |
| 484 | 509 | if (! isset($_GET["page"])) |
| 485 | 510 | return $text; |
| 486 | - | |
| 511 | + | |
| 487 | 512 | if ( strpos($_GET["page"],'maxbuttons') === false) |
| 488 | - return $text; | |
| 513 | + return $text; | |
| 489 | 514 | $text = ''; |
| 490 | 515 | |
| 491 | - $text .= sprintf("If you like MaxButtons please give us a %s★★★★★%s rating!", | |
| 492 | - "<a href='https://wordpress.org/support/view/plugin-reviews/maxbuttons#postform' target='_blank'>", | |
| 493 | - "</a>") ; | |
| 494 | - return $text; | |
| 495 | - | |
| 516 | + $text .= sprintf("If you like MaxButtons please give us a %s★★★★★%s rating!", | |
| 517 | + "<a href='https://wordpress.org/support/view/plugin-reviews/maxbuttons#postform' target='_blank'>", | |
| 518 | + "</a>") ; | |
| 519 | + return $text; | |
| 520 | + | |
| 496 | 521 | } |
| 497 | - | |
| 498 | - | |
| 499 | - function shortcode($atts) | |
| 522 | + | |
| 523 | + | |
| 524 | + function shortcode($atts) | |
| 500 | 525 | { |
| 501 | 526 | $button = $this->getClass("button"); |
| 502 | - return $button->shortcode($atts); | |
| 527 | + return $button->shortcode($atts); | |
| 503 | 528 | } |
| 504 | 529 | |
| 505 | 530 | public function collection_shortcode($atts, $content = null) |
| 506 | 531 | { |
| 507 | 532 | $atts = shortcode_atts(array( |
| 508 | - "id" => 0, | |
| 509 | - "name" => '', | |
| 510 | - "nocache" => false, // these are button options. | |
| 511 | - "mode" => "normal", | |
| 512 | - "style" => "footer", | |
| 533 | + "id" => 0, | |
| 534 | + "name" => '', | |
| 535 | + "nocache" => false, // these are button options. | |
| 536 | + "mode" => "normal", | |
| 537 | + "style" => "footer", | |
| 513 | 538 | ), |
| 514 | - | |
| 539 | + | |
| 515 | 540 | $atts); |
| 516 | - | |
| 517 | - $id = intval($atts["id"]); | |
| 518 | - $name = sanitize_text_field($atts["name"]); | |
| 519 | - | |
| 520 | - if ($id > 0) | |
| 541 | + | |
| 542 | + $id = intval($atts["id"]); | |
| 543 | + $name = sanitize_text_field($atts["name"]); | |
| 544 | + | |
| 545 | + if ($id > 0) | |
| 521 | 546 | $collection = maxCollections::getCollectionByID($id); |
| 522 | - elseif ($atts["name"] != '') | |
| 547 | + elseif ($atts["name"] != '') | |
| 523 | 548 | $collection = maxCollections::getCollectionByName($name); |
| 524 | - | |
| 525 | - | |
| 549 | + | |
| 550 | + | |
| 526 | 551 | if ($collection) |
| 527 | 552 | return $collection->shortcode($atts,$content); |
| 528 | - | |
| 553 | + | |
| 529 | 554 | } |
| 530 | - | |
| 531 | 555 | |
| 556 | + | |
| 532 | 557 | function plugin_action_links($links, $file) { |
| 533 | - | |
| 558 | + | |
| 534 | 559 | if ($file == plugin_basename(dirname(MAXBUTTONS_ROOT_FILE) . '/maxbuttons.php')) { |
| 535 | 560 | $label = __('Buttons', 'maxbuttons'); |
| 536 | 561 | $dashboard_link = '<a href="' . admin_url() . 'admin.php?page=maxbuttons-controller&action=list">' . $label . '</a>'; |
| 537 | 562 | array_unshift($links, $dashboard_link); |
| @@ -544,9 +569,9 @@ | ||
| 544 | 569 | function plugin_row_meta($links, $file) { |
| 545 | 570 | if ($file == plugin_basename(dirname(__FILE__) . '/maxbuttons.php')) { |
| 546 | 571 | $links[] = sprintf(__('%sUpgrade to Pro Version%s', 'maxbuttons'), '<a href="http://maxbuttons.com/?ref=mbfree" target="_blank">', '</a>'); |
| 547 | 572 | } |
| 548 | - | |
| 573 | + | |
| 549 | 574 | return $links; |
| 550 | 575 | } |
| 551 | 576 | |
| 552 | 577 | |
| @@ -551,134 +576,136 @@ | ||
| 551 | 576 | |
| 552 | 577 | |
| 553 | 578 | function do_footer($id, $code, $type = "css") |
| 554 | 579 | { |
| 555 | - | |
| 556 | - $this->footer[$type][$id] = $code; | |
| 557 | - | |
| 580 | + | |
| 581 | + $this->footer[$type][$id] = $code; | |
| 582 | + | |
| 558 | 583 | } |
| 559 | 584 | function footer() |
| 560 | 585 | { |
| 561 | 586 | if(count($this->footer) == 0) return; // nothing |
| 562 | - | |
| 563 | - foreach ($this->footer as $type => $part) | |
| 587 | + | |
| 588 | + foreach ($this->footer as $type => $part) | |
| 564 | 589 | { |
| 565 | 590 | // add tag |
| 566 | - if ($type == 'css') | |
| 591 | + if ($type == 'css') | |
| 567 | 592 | { |
| 568 | 593 | echo "<!--email_off--><style type='text/css'>"; |
| 569 | - } | |
| 594 | + } | |
| 570 | 595 | foreach ($part as $id => $statements) |
| 571 | 596 | { |
| 572 | - if (strlen($statements) > 0) // prevent whitespace | |
| 573 | - echo $statements . "\n"; | |
| 597 | + if (strlen($statements) > 0) // prevent whitespace | |
| 598 | + echo $statements . "\n"; | |
| 574 | 599 | } |
| 575 | - if ($type == 'css') | |
| 600 | + if ($type == 'css') | |
| 576 | 601 | { |
| 577 | - echo "</style><!--/email_off-->\n"; | |
| 578 | - } | |
| 602 | + echo "</style><!--/email_off-->\n"; | |
| 603 | + } | |
| 579 | 604 | } |
| 580 | - | |
| 605 | + | |
| 581 | 606 | } |
| 582 | - | |
| 607 | + | |
| 583 | 608 | public function do_review_notice () { |
| 584 | - | |
| 585 | - $current_user_id = get_current_user_id(); | |
| 609 | + | |
| 610 | + $current_user_id = get_current_user_id(); | |
| 611 | + $version = MAXBUTTONS_VERSION_NUM; | |
| 612 | + | |
| 586 | 613 | $review = get_user_meta( $current_user_id, 'maxbuttons_review_notice' , true ); |
| 587 | - | |
| 614 | + | |
| 588 | 615 | if ($review == '') |
| 589 | 616 | { |
| 590 | 617 | //$created = get_option("MBFREE_CREATED"); |
| 591 | - $show = time() + (7* DAY_IN_SECONDS); | |
| 618 | + $show = time() + (7* DAY_IN_SECONDS); | |
| 592 | 619 | update_user_meta($current_user_id, 'maxbuttons_review_notice', $show); |
| 593 | - return; | |
| 620 | + return; | |
| 594 | 621 | } |
| 595 | 622 | |
| 596 | - | |
| 623 | + | |
| 597 | 624 | $display_review = false; |
| 598 | - | |
| 599 | - if ($review == 'off') | |
| 600 | - { return; // no show | |
| 601 | - | |
| 625 | + | |
| 626 | + if ($review == 'off') | |
| 627 | + { return; // no show | |
| 628 | + | |
| 602 | 629 | } |
| 603 | 630 | elseif (is_numeric($review)) |
| 604 | - { | |
| 605 | - $now = time(); | |
| 631 | + { | |
| 632 | + $now = time(); | |
| 606 | 633 | |
| 607 | 634 | if ($now > $review) |
| 608 | - { | |
| 635 | + { | |
| 609 | 636 | $display_review = true; |
| 610 | 637 | |
| 611 | 638 | } |
| 612 | 639 | } |
| 613 | - | |
| 614 | - // load style / script. It's seperated since it should show everywhere in admin. | |
| 640 | + | |
| 641 | + // load style / script. It's seperated since it should show everywhere in admin. | |
| 615 | 642 | if ($display_review) |
| 616 | 643 | { |
| 617 | - add_action( 'admin_notices', array('maxAdmin', 'mb_review_notice')); | |
| 618 | - wp_enqueue_style('maxbuttons-review-notice', $this->plugin_url . 'assets/css/review_notice.css'); | |
| 619 | - wp_enqueue_script('maxbuttons-review-notice', $this->plugin_url . 'js/min/review-notice.js', array('jquery'), true); | |
| 644 | + add_action( 'admin_notices', array( maxUtils::namespaceit('maxAdmin'), 'mb_review_notice')); | |
| 645 | + wp_enqueue_style('maxbuttons-review-notice', $this->plugin_url . 'assets/css/review_notice.css', array(), $version); | |
| 646 | + wp_enqueue_script('maxbuttons-review-notice', $this->plugin_url . 'js/min/review-notice.js', array('jquery'), $version); | |
| 620 | 647 | |
| 621 | - $local = array(); | |
| 648 | + $local = array(); | |
| 622 | 649 | $local["ajaxurl"] = admin_url( 'admin-ajax.php' ); |
| 623 | 650 | wp_localize_script('maxbuttons-review-notice', 'mb_ajax_review', $local); |
| 624 | 651 | } |
| 625 | - | |
| 652 | + | |
| 626 | 653 | } |
| 627 | - | |
| 628 | - public function setReviewNoticeStatus() | |
| 654 | + | |
| 655 | + public function setReviewNoticeStatus() | |
| 629 | 656 | { |
| 630 | - $status = isset($_POST["status"]) ? sanitize_text_field($_POST["status"]) : ''; | |
| 631 | - $current_user_id = get_current_user_id(); | |
| 632 | - | |
| 633 | - $updated = false; | |
| 634 | - | |
| 635 | - if ($status == 'off') | |
| 657 | + $status = isset($_POST["status"]) ? sanitize_text_field($_POST["status"]) : ''; | |
| 658 | + $current_user_id = get_current_user_id(); | |
| 659 | + | |
| 660 | + $updated = false; | |
| 661 | + | |
| 662 | + if ($status == 'off') | |
| 636 | 663 | { |
| 637 | - $updated = true; | |
| 638 | - update_user_meta($current_user_id, 'maxbuttons_review_notice', 'off'); | |
| 639 | - | |
| 664 | + $updated = true; | |
| 665 | + update_user_meta($current_user_id, 'maxbuttons_review_notice', 'off'); | |
| 666 | + | |
| 640 | 667 | } |
| 641 | - if ($status == 'later') | |
| 668 | + if ($status == 'later') | |
| 642 | 669 | { |
| 643 | 670 | $updated = true; |
| 644 | - $later = time() + (14 * DAY_IN_SECONDS ); | |
| 645 | - | |
| 646 | - update_user_meta($current_user_id, 'maxbuttons_review_notice', $later); | |
| 671 | + $later = time() + (14 * DAY_IN_SECONDS ); | |
| 672 | + | |
| 673 | + update_user_meta($current_user_id, 'maxbuttons_review_notice', $later); | |
| 647 | 674 | } |
| 648 | 675 | if ($status == 'reviewoffer-dismiss') // different ad! |
| 649 | 676 | { |
| 650 | - $updated = true; | |
| 651 | - update_user_meta($current_user_id, 'maxbuttons_review_offer', 'off'); | |
| 652 | - | |
| 677 | + $updated = true; | |
| 678 | + update_user_meta($current_user_id, 'maxbuttons_review_offer', 'off'); | |
| 679 | + | |
| 653 | 680 | } |
| 654 | - | |
| 655 | - echo json_encode(array("updated" => $updated)) ; | |
| 656 | - | |
| 657 | - exit(); | |
| 681 | + | |
| 682 | + echo json_encode(array("updated" => $updated)) ; | |
| 683 | + | |
| 684 | + exit(); | |
| 658 | 685 | } |
| 659 | - | |
| 660 | - /* Add a notice | |
| 661 | - | |
| 662 | - The added notice will be displayed to the user in WordPress format. | |
| 686 | + | |
| 687 | + /* Add a notice | |
| 688 | + | |
| 689 | + The added notice will be displayed to the user in WordPress format. | |
| 663 | 690 | @see display_notices |
| 664 | - | |
| 691 | + | |
| 665 | 692 | @param $type string message | notice | error | fatal |
| 666 | 693 | @param $message string User understandable message |
| 667 | - | |
| 694 | + | |
| 668 | 695 | */ |
| 669 | 696 | public static function add_notice($type, $message) |
| 670 | 697 | { |
| 671 | - self::$notices[] = array("type" => $type, | |
| 698 | + self::$notices[] = array("type" => $type, | |
| 672 | 699 | "message" => $message |
| 673 | - ); | |
| 674 | - | |
| 700 | + ); | |
| 701 | + | |
| 675 | 702 | } |
| 676 | - | |
| 703 | + | |
| 677 | 704 | /* Display all notices |
| 678 | - | |
| 705 | + | |
| 679 | 706 | Then notices added by @see add_notice will be displayed. This function is called by an action hook |
| 680 | - | |
| 707 | + | |
| 681 | 708 | @param $echo echo the results or silently return. |
| 682 | 709 | @return string|null If not written to screen via echo, the HTML output will be returned |
| 683 | 710 | */ |
| 684 | 711 | public function display_notices($echo = true) |
| @@ -684,27 +711,25 @@ | ||
| 684 | 711 | public function display_notices($echo = true) |
| 685 | 712 | { |
| 686 | 713 | |
| 687 | 714 | if ($echo === '') $echo = true; |
| 688 | - $notices = self::$notices; | |
| 689 | - $output = ''; | |
| 715 | + $notices = self::$notices; | |
| 716 | + $output = ''; | |
| 690 | 717 | if (count($notices) == 0) |
| 691 | 718 | return; |
| 692 | - | |
| 719 | + | |
| 693 | 720 | foreach($notices as $index => $notice) |
| 694 | 721 | { |
| 695 | - $type = $notice["type"]; | |
| 696 | - $message = $notice["message"]; | |
| 697 | - $output .= "<div class='mb-message $type'> "; | |
| 698 | - $output .= $message ; | |
| 699 | - $output .= "</div>"; | |
| 700 | - } | |
| 722 | + $type = $notice["type"]; | |
| 723 | + $message = $notice["message"]; | |
| 724 | + $output .= "<div class='mb-message $type'> "; | |
| 725 | + $output .= $message ; | |
| 726 | + $output .= "</div>"; | |
| 727 | + } | |
| 701 | 728 | |
| 702 | - self::$notices = array(); // empty notices to prevent double display | |
| 703 | - | |
| 704 | - if ($echo) echo $output; | |
| 729 | + self::$notices = array(); // empty notices to prevent double display | |
| 730 | + | |
| 731 | + if ($echo) echo $output; | |
| 705 | 732 | else return $output; |
| 706 | 733 | } |
| 707 | - | |
| 734 | + | |
| 708 | 735 | } // class |
| 709 | - | |
| 710 | - | |