| @@ -1,10 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: WP Bottom Menu |
| 4 | 4 | * Description: WP Bottom Menu allows you to add a woocommerce supported bottom menu to your site. |
| 5 | - * Version: 2.0 | |
| 6 | - * Author: J4 | |
| 5 | + * Version: 2.2.3 | |
| 6 | + * Author: J4 & LiquidThemes | |
| 7 | 7 | * Author URI: https://hub.liquid-themes.com/ |
| 8 | 8 | * License: GPL v2 or later |
| 9 | 9 | * License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 10 | 10 | * Text Domain: wp-bottom-menu |
| @@ -22,9 +22,9 @@ | ||
| 22 | 22 | */ |
| 23 | 23 | |
| 24 | 24 | if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 25 | 25 | |
| 26 | -define( 'WP_BOTTOM_MENU_VERSION', '2.0' ); | |
| 26 | +define( 'WP_BOTTOM_MENU_VERSION', '2.2.3' ); | |
| 27 | 27 | define( 'WP_BOTTOM_MENU_DIR_URL', plugin_dir_url( __FILE__ ) ); |
| 28 | 28 | define( 'WP_BOTTOM_MENU_DIR_PATH', plugin_dir_path( __FILE__ ) ); |
| 29 | 29 | |
| 30 | 30 | |
| @@ -102,14 +102,23 @@ | ||
| 102 | 102 | function init(){ |
| 103 | 103 | |
| 104 | 104 | $this->i18n(); |
| 105 | 105 | $this->include_files(); |
| 106 | - $this->promote_hub(); | |
| 107 | 106 | |
| 108 | 107 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
| 109 | 108 | add_action( 'wp_footer', array($this, 'wp_bottom_menu' ) ); |
| 110 | 109 | add_filter( 'plugin_action_links', array($this, 'wp_bottom_menu_action_links'), 10, 2 ); |
| 111 | 110 | |
| 111 | + // Admin menu - Settings > WP Bottom Menu | |
| 112 | + add_action( 'admin_menu', function() { | |
| 113 | + add_submenu_page( | |
| 114 | + 'options-general.php', 'WP Bottom Menu', 'WP Bottom Menu', 'manage_options', 'wp-bottom-menu', | |
| 115 | + function(){ | |
| 116 | + wp_redirect( admin_url( 'customize.php?autofocus[panel]=wpbottommenu_panel' ) ); | |
| 117 | + } | |
| 118 | + ); | |
| 119 | + } ); | |
| 120 | + | |
| 112 | 121 | add_action( 'customize_controls_enqueue_scripts', function(){ |
| 113 | 122 | |
| 114 | 123 | // customizer js |
| 115 | 124 | wp_enqueue_script( 'wp-bottom-menu-customize', WP_BOTTOM_MENU_DIR_URL . 'assets/js/customizer.js', array( 'jquery', 'customize-controls' ), false, true ); |
| @@ -129,8 +138,34 @@ | ||
| 129 | 138 | // Load WooCommerce Fragments |
| 130 | 139 | if ( class_exists( 'WooCommerce' ) ){ |
| 131 | 140 | add_filter( 'woocommerce_add_to_cart_fragments', array($this, 'wp_bottom_menu_add_to_cart_fragment'), 10, 1 ); |
| 132 | 141 | } |
| 142 | + | |
| 143 | + // Register Nav Menus | |
| 144 | + add_action( 'after_setup_theme', function() { | |
| 145 | + register_nav_menus( array( | |
| 146 | + 'wpbm_custom' => __( 'WP Bottom Menu', 'wp-bottom-menu' ), | |
| 147 | + ) ); | |
| 148 | + } ); | |
| 149 | + | |
| 150 | + // Polylang register translatable strings | |
| 151 | + add_action('init', function(){ | |
| 152 | + if ( function_exists('pll_register_string') ) { | |
| 153 | + $customizer_repeater_wpbm = get_option('customizer_repeater_wpbm', json_encode( array( | |
| 154 | + array("choice" => "wpbm-homepage" ,"subtitle" => "fa-home", "title" => "Home", "id" => "customizer_repeater_1" ), | |
| 155 | + array("choice" => "wpbm-woo-account" ,"subtitle" => "fa-user", "title" => "Account", "id" => "customizer_repeater_2" ), | |
| 156 | + array("choice" => "wpbm-woo-cart" ,"subtitle" => "fa-shopping-cart", "title" => "Cart", "id" => "customizer_repeater_3" ), | |
| 157 | + array("choice" => "wpbm-woo-search" ,"subtitle" => "fa-search", "title" => "Search", "id" => "customizer_repeater_4" ), | |
| 158 | + ) ) ); | |
| 159 | + | |
| 160 | + $customizer_repeater_wpbm_decoded = json_decode($customizer_repeater_wpbm); | |
| 161 | + | |
| 162 | + foreach ( $customizer_repeater_wpbm_decoded as $repeater_item ) { | |
| 163 | + pll_register_string( 'Menu Item', $repeater_item->title, 'WP Bottom Menu' ); | |
| 164 | + } | |
| 165 | + } | |
| 166 | + }); | |
| 167 | + | |
| 133 | 168 | } |
| 134 | 169 | |
| 135 | 170 | function include_files(){ |
| 136 | 171 | |
| @@ -139,49 +174,8 @@ | ||
| 139 | 174 | require_once( WP_BOTTOM_MENU_DIR_PATH . 'inc/customizer/condition.php' ); |
| 140 | 175 | |
| 141 | 176 | } |
| 142 | 177 | |
| 143 | - function promote_hub(){ | |
| 144 | - | |
| 145 | - // Hub promote notice | |
| 146 | - if ( isset( $_GET['hub_promote'] ) && 'false' === $_GET['hub_promote'] ) { | |
| 147 | - set_transient( 'hub_promote', [], 4 * WEEK_IN_SECONDS ); | |
| 148 | - } | |
| 149 | - | |
| 150 | - if ( false === get_transient( 'hub_promote' ) ){ | |
| 151 | - add_action( 'admin_notices', function() { | |
| 152 | - if ( 'Hub' === wp_get_theme()->get( 'Name' ) || 'Hub Child' === wp_get_theme()->get( 'Name' ) ) { | |
| 153 | - return; | |
| 154 | - } | |
| 155 | - ?> | |
| 156 | - <div class="notice"> | |
| 157 | - <h3 style="margin-bottom:0.5em">Looking for an ultra fast WP theme?</h3> | |
| 158 | - <h4 style="margin:0">WP Bottom Menu developers recommend Hub:</h4> | |
| 159 | - <ul style="list-style:disc;margin-left:2em"> | |
| 160 | - <li>The Best Selling Theme of the Year</li> | |
| 161 | - <li>Free Support + Updates + Plugins</li> | |
| 162 | - <li>Elementor + WP Bakery + WP Bottom Menu Support</li> | |
| 163 | - <li>800+ Award-Winning Templates</li> | |
| 164 | - <li>And Many More!</li> | |
| 165 | - </ul> | |
| 166 | - <p style="display:flex;align-items:center;"> | |
| 167 | - <a class="button button-primary" target="_blank" href="<?php echo esc_url( 'https://themeforest.net/item/hub-responsive-multipurpose-wordpress-theme/31569152?utm_source=wp_bottom_menu&utm_medium=banner&utm_campaign=wpbm_promote' ); ?>" > | |
| 168 | - Join Hub | |
| 169 | - </a> | |
| 170 | - <a style="margin-left:1em" class="button button-secondary" target="_blank" href="<?php echo esc_url( 'https://hub.liquid-themes.com/?utm_source=wp_bottom_menu&utm_medium=banner&utm_campaign=wpbm_promote' ); ?>" > | |
| 171 | - Learn More | |
| 172 | - </a> | |
| 173 | - <a style="margin-left:auto" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'hub_promote', 'false' ), 'false' ) ); ?>" > | |
| 174 | - Hide Notification | |
| 175 | - </a> | |
| 176 | - </p> | |
| 177 | - </div> | |
| 178 | - <?php | |
| 179 | - } ); | |
| 180 | - } | |
| 181 | - | |
| 182 | - } | |
| 183 | - | |
| 184 | 178 | // enqueue scripts |
| 185 | 179 | function enqueue_scripts() { |
| 186 | 180 | |
| 187 | 181 | // check the display condition |
| @@ -190,13 +184,20 @@ | ||
| 190 | 184 | wp_enqueue_style( 'wp-bottom-menu', WP_BOTTOM_MENU_DIR_URL . 'assets/css/style.css', array(), WP_BOTTOM_MENU_VERSION, 'all' ); |
| 191 | 185 | wp_enqueue_script( 'wp-bottom-menu', WP_BOTTOM_MENU_DIR_URL . 'assets/js/main.js', array(), WP_BOTTOM_MENU_VERSION, true ); |
| 192 | 186 | |
| 193 | 187 | if ( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome' ){ |
| 194 | - wp_enqueue_style( 'font-awesome', WP_BOTTOM_MENU_DIR_URL . 'inc/customizer-repeater/css/font-awesome.min.css', array(), CUSTOMIZER_REPEATER_VERSION ); | |
| 188 | + wp_enqueue_style( 'font-awesome', WP_BOTTOM_MENU_DIR_URL . 'inc/customizer/customizer-repeater/css/font-awesome.min.css', array(), CUSTOMIZER_REPEATER_VERSION ); | |
| 195 | 189 | } |
| 196 | 190 | if ( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome2' ){ |
| 197 | 191 | wp_enqueue_style( 'font-awesome-wpbm', WP_BOTTOM_MENU_DIR_URL . 'assets/vendors/fontawesome/all.min.css', array(), '6.1.1' ); |
| 198 | 192 | } |
| 193 | + | |
| 194 | + wp_localize_script( 'wp-bottom-menu', 'WPBM', | |
| 195 | + array( | |
| 196 | + 'ajaxurl' => admin_url( 'admin-ajax.php' ), | |
| 197 | + 'siteurl' => site_url(), | |
| 198 | + ) | |
| 199 | + ); | |
| 199 | 200 | |
| 200 | 201 | } |
| 201 | 202 | |
| 202 | 203 | } |
| @@ -221,23 +222,39 @@ | ||
| 221 | 222 | ) ) ); |
| 222 | 223 | /*This returns a json so we have to decode it*/ |
| 223 | 224 | |
| 224 | 225 | $customizer_repeater_wpbm_decoded = json_decode($customizer_repeater_wpbm); |
| 225 | - $wpbm_woo_search = false; | |
| 226 | - $wpbm_post_search = false; | |
| 226 | + $wpbm_woo_search = $wpbm_post_search = $wpbm_custom_search = $wpbm_custom_menu = false; | |
| 227 | + $search_icon = 'fa-search'; | |
| 227 | 228 | $wpbm_link_target = get_option( 'wpbottommenu_target' ) ? 'target=_blank' : ''; |
| 228 | - foreach($customizer_repeater_wpbm_decoded as $repeater_item){ | |
| 229 | + foreach ( $customizer_repeater_wpbm_decoded as $repeater_item ) { | |
| 229 | 230 | |
| 230 | - if($repeater_item->choice == "wpbm-woo-search" or $repeater_item->choice == "wpbm-post-search"):?> | |
| 231 | - <a href="javascript:void(0);" title="<?php echo esc_attr( $repeater_item->title ); ?>" class="wp-bottom-menu-item wp-bottom-menu-search-form-trigger"> | |
| 231 | + $tag = 'a'; | |
| 232 | + | |
| 233 | + if ( $repeater_item->choice == "wpbm-woo-search" || $repeater_item->choice == "wpbm-post-search" || $repeater_item->choice == "wpbm-custom-search" ): | |
| 234 | + $tag = 'div'; | |
| 235 | + if ( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome' ) { | |
| 236 | + $search_icon = 'fa ' . $repeater_item->subtitle; | |
| 237 | + } elseif ( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome2' || get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'svg' ) { | |
| 238 | + $search_icon = $repeater_item->subtitle; | |
| 239 | + } | |
| 240 | + ?> | |
| 241 | + <<?php echo $tag; ?> title="<?php echo esc_attr( $repeater_item->title ); ?>" class="wp-bottom-menu-item wp-bottom-menu-search-form-trigger"> | |
| 242 | + <?php elseif ( $repeater_item->choice == "wpbm-menu" ): ?> | |
| 243 | + <?php $tag = 'div'; ?> | |
| 244 | + <<?php echo $tag; ?> title="<?php echo esc_attr( $repeater_item->title ); ?>" class="wp-bottom-menu-item wp-bottom-menu-nav-trigger"> | |
| 245 | + <?php elseif ( $repeater_item->choice == "wpbm-onclick" ): ?> | |
| 246 | + <?php $tag = 'div'; ?> | |
| 247 | + <<?php echo $tag; ?> onclick="<?php echo $repeater_item->text; ?>" title="<?php echo esc_attr( $repeater_item->title ); ?>" class="wp-bottom-menu-item"> | |
| 232 | 248 | <?php else: ?> |
| 233 | 249 | <?php |
| 234 | - $wpbm_item_url = $wpbm_item_active = ''; | |
| 250 | + $wpbm_item_url = ''; | |
| 251 | + $classes = array('wp-bottom-menu-item'); | |
| 235 | 252 | switch($repeater_item->choice){ |
| 236 | 253 | case "wpbm-homepage": |
| 237 | 254 | $wpbm_item_url = esc_url( home_url() ); |
| 238 | 255 | if ( is_front_page() ){ |
| 239 | - $wpbm_item_active = 'active'; | |
| 256 | + array_push( $classes, 'active' ); | |
| 240 | 257 | } |
| 241 | 258 | break; |
| 242 | 259 | case "wpbm-woo-cart": |
| 243 | 260 | if ( class_exists( 'WooCommerce' ) ) { |
| @@ -252,18 +269,26 @@ | ||
| 252 | 269 | } else { |
| 253 | 270 | $wpbm_item_url = '#'; |
| 254 | 271 | } |
| 255 | 272 | break; |
| 273 | + case "wpbm-page-back": | |
| 274 | + $wpbm_item_url = 'javascript:void(0)'; | |
| 275 | + array_push( $classes, 'wpbm-page-back' ); | |
| 276 | + break; | |
| 256 | 277 | default: |
| 257 | 278 | $wpbm_item_url = esc_url( $repeater_item->link ); |
| 258 | 279 | } |
| 259 | 280 | |
| 260 | 281 | if ( url_to_postid($wpbm_item_url) === get_the_ID() ){ |
| 261 | - $wpbm_item_active = 'active'; | |
| 282 | + array_push( $classes, 'active' ); | |
| 283 | + } elseif ( class_exists('WooCommerce') && is_shop() && url_to_postid($wpbm_item_url) === 0 ) { | |
| 284 | + if ( $wpbm_item_url !== home_url() ) { | |
| 285 | + array_push( $classes, 'active' ); | |
| 286 | + } | |
| 262 | 287 | } |
| 263 | 288 | |
| 264 | 289 | ?> |
| 265 | - <a href="<?php echo $wpbm_item_url; ?>" class="wp-bottom-menu-item <?php echo esc_attr( $wpbm_item_active ); ?>" <?php echo esc_attr( $wpbm_link_target ); ?>> | |
| 290 | + <<?php echo $tag; ?> href="<?php echo $wpbm_item_url; ?>" class="<?php echo esc_attr( join( ' ', $classes ) ); ?>" <?php echo esc_attr( $wpbm_link_target ); ?>> | |
| 266 | 291 | <?php endif; ?> |
| 267 | 292 | |
| 268 | 293 | <div class="wp-bottom-menu-icon-wrapper"> |
| 269 | 294 | <?php if( get_option( 'wpbottommenu_show_cart_count', false ) ): ?> |
| @@ -281,15 +306,17 @@ | ||
| 281 | 306 | <?php endif; ?> |
| 282 | 307 | </div> |
| 283 | 308 | <?php if( !get_option( 'wpbottommenu_disable_title', false ) ): ?> |
| 284 | 309 | <?php if( get_option( 'wpbottommenu_show_cart_total', false ) && $repeater_item->choice == "wpbm-woo-cart" && class_exists( 'WooCommerce' ) ): ?> |
| 285 | - <span class="wp-bottom-menu-cart-total"><?php WC()->cart->get_cart_total(); ?></span> | |
| 286 | - <?php else: ?> | |
| 287 | - <span><?php echo $repeater_item->title; ?></span> | |
| 310 | + <span class="wp-bottom-menu-cart-total"><?php WC()->cart->get_cart_total(); ?></span> | |
| 311 | + <?php elseif( get_option( 'wpbottommenu_show_account_name' ) && $repeater_item->choice == "wpbm-woo-account" && class_exists( 'WooCommerce' ) && is_user_logged_in() ): ?> | |
| 312 | + <?php echo wp_get_current_user()->first_name ? wp_get_current_user()->first_name : wp_get_current_user()->user_login; ?> | |
| 313 | + <?php else: ?> | |
| 314 | + <span><?php echo $this->translated_menu_title($repeater_item->title); ?></span> | |
| 288 | 315 | <?php endif; ?> |
| 289 | 316 | <?php endif; ?> |
| 290 | 317 | |
| 291 | - </a> | |
| 318 | + </<?php echo $tag; ?>> | |
| 292 | 319 | <?php |
| 293 | 320 | |
| 294 | 321 | if ( $repeater_item->choice == "wpbm-woo-search" && !$wpbm_woo_search ) |
| 295 | 322 | $wpbm_woo_search = true; |
| @@ -295,25 +322,77 @@ | ||
| 295 | 322 | $wpbm_woo_search = true; |
| 296 | 323 | |
| 297 | 324 | if ( $repeater_item->choice == "wpbm-post-search" && !$wpbm_post_search ) |
| 298 | 325 | $wpbm_post_search = true; |
| 299 | - | |
| 326 | + | |
| 327 | + if ( $repeater_item->choice == "wpbm-custom-search" && !$wpbm_custom_search ) | |
| 328 | + $wpbm_custom_search = true; | |
| 329 | + | |
| 330 | + if ( $repeater_item->choice == "wpbm-menu" && !$wpbm_custom_menu ) | |
| 331 | + $wpbm_custom_menu = true; | |
| 332 | + | |
| 300 | 333 | } |
| 301 | 334 | ?> |
| 302 | 335 | </div> |
| 336 | + | |
| 337 | + <?php if ( $wpbm_custom_menu ) : ?> | |
| 338 | + <div class="wp-bottom-menu-nav-wrapper"> | |
| 339 | + <span class="wpbm-nav-close">×</span> | |
| 340 | + <?php | |
| 341 | + if ( has_nav_menu( 'wpbm_custom' ) ) { | |
| 342 | + wp_nav_menu( array( | |
| 343 | + 'menu' => 'wpbm_custom', | |
| 344 | + 'container' => 'ul', | |
| 345 | + 'menu_id' => 'wpbm-nav', | |
| 346 | + 'menu_class' => 'wpbm-nav-items', | |
| 347 | + ) ); | |
| 348 | + } else { | |
| 349 | + esc_html_e( 'Add a menu in "WP Dashboard->Appearance->Menus" and select Display location "WP Bottom Menu"', 'wp-bottom-menu' ); | |
| 350 | + } | |
| 351 | + ?> | |
| 352 | + </div> | |
| 353 | + <?php endif; | |
| 303 | 354 | |
| 304 | - <?php if ( $wpbm_woo_search || $wpbm_post_search ): ?> | |
| 355 | + if ( $wpbm_woo_search || $wpbm_post_search || $wpbm_custom_search ): ?> | |
| 305 | 356 | <div class="wp-bottom-menu-search-form-wrapper" id="wp-bottom-menu-search-form-wrapper"> |
| 306 | 357 | <form role="search" method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>" class="wp-bottom-menu-search-form"> |
| 307 | - <i class="fa fa-search"></i> | |
| 308 | - <input type="hidden" name="post_type" value="<?php if( $wpbm_woo_search && class_exists( 'WooCommerce' ) ) echo esc_attr("product"); else echo esc_attr("post"); ?>" /> | |
| 358 | + <?php if ( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'svg' ) : ?> | |
| 359 | + <?php echo html_entity_decode( $search_icon ); ?> | |
| 360 | + <?php else : ?> | |
| 361 | + <i class="<?php echo esc_attr( $search_icon ); ?>"></i> | |
| 362 | + <?php endif; ?> | |
| 363 | + <?php if ( $wpbm_woo_search && class_exists( 'WooCommerce' ) ) { ?> | |
| 364 | + <input type="hidden" name="post_type" value="product" /> | |
| 365 | + <?php } elseif ( $wpbm_post_search ) { ?> | |
| 366 | + <input type="hidden" name="post_type" value="post" /> | |
| 367 | + <?php } else { | |
| 368 | + $search_cpt = get_option( 'wpbottommenu_search_cpt', 'all' ); | |
| 369 | + if ( $search_cpt === 'all' || empty( $search_cpt ) ){ | |
| 370 | + ?><input type="hidden" name="post_type" value="all" /><?php | |
| 371 | + } else { | |
| 372 | + $search_cpt = explode(',', $search_cpt); | |
| 373 | + foreach( $search_cpt as $cpt ){ | |
| 374 | + if ( !empty( $cpt ) ){ | |
| 375 | + ?><input type="hidden" name="post_type[]" value="<?php echo esc_attr( $cpt ); ?>" /><?php | |
| 376 | + } | |
| 377 | + } | |
| 378 | + } | |
| 379 | + } ?> | |
| 309 | 380 | <input type="search" class="search-field" placeholder="<?php if( get_option( 'wpbottommenu_placeholder_text', 'Search' ) ) echo get_option( 'wpbottommenu_placeholder_text', 'Search' ); else echo esc_attr_x( 'Search', 'wp-bottom-menu' ); ?>" value="<?php echo get_search_query(); ?>" name="s" /> |
| 310 | 381 | </form> |
| 311 | 382 | </div> |
| 312 | - <?php endif; | |
| 383 | + <?php endif; | |
| 313 | 384 | |
| 314 | - } | |
| 385 | + } | |
| 315 | 386 | |
| 387 | + function translated_menu_title( $title ) { | |
| 388 | + if ( function_exists('pll__') ) { | |
| 389 | + return pll__( $title ); | |
| 390 | + } | |
| 391 | + | |
| 392 | + return $title; | |
| 393 | + } | |
| 394 | + | |
| 316 | 395 | function display_condition(){ |
| 317 | 396 | |
| 318 | 397 | $condition = new \WPBottomMenu_Condition(); |
| 319 | 398 | return $condition->get_condition(); |
| @@ -345,8 +424,9 @@ | ||
| 345 | 424 | register_activation_hook( __FILE__, 'wp_bottom_menu_plugin_activate' ); |
| 346 | 425 | |
| 347 | 426 | function wp_bottom_menu_plugin_deactivate() { |
| 348 | 427 | /* If you want all settings to be deleted when the plugin is deactive, activate this field. |
| 428 | + TODO : Add reset all settings option | |
| 349 | 429 | |
| 350 | 430 | delete_option(' customizer_repeater_wpbm' ); |
| 351 | 431 | delete_option( 'wpbottommenu_display_px' ); |
| 352 | 432 | delete_option( 'wpbottommenu_display_always' ); |