PluginProbe
WP Bottom Menu / 2.2.3
WP Bottom Menu v2.2.3
trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1 1.1.1 1.1.2 1.2 1.3 1.3.2 1.4 1.4.2 1.4.3 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.2 2.2.1 2.2.2 All 27 releases
← All changes | wp-bottom-menu.php +104 -72 2.12.2.3 View file →
@@ -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.1
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.1' );
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 );
@@ -136,8 +145,27 @@
136 145 register_nav_menus( array(
137 146 'wpbm_custom' => __( 'WP Bottom Menu', 'wp-bottom-menu' ),
138 147 ) );
139 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 +
140 168 }
141 169
142 170 function include_files(){
143 171
@@ -146,49 +174,8 @@
146 174 require_once( WP_BOTTOM_MENU_DIR_PATH . 'inc/customizer/condition.php' );
147 175
148 176 }
149 177
150 - function promote_hub(){
151 -
152 - // Hub promote notice
153 - if ( isset( $_GET['hub_promote'] ) && 'false' === $_GET['hub_promote'] ) {
154 - set_transient( 'hub_promote', [], 4 * WEEK_IN_SECONDS );
155 - }
156 -
157 - if ( false === get_transient( 'hub_promote' ) ){
158 - add_action( 'admin_notices', function() {
159 - if ( 'Hub' === wp_get_theme()->get( 'Name' ) || 'Hub Child' === wp_get_theme()->get( 'Name' ) ) {
160 - return;
161 - }
162 - ?>
163 - <div class="notice">
164 - <h3 style="margin-bottom:0.5em">Looking for an ultra fast WP theme?</h3>
165 - <h4 style="margin:0">WP Bottom Menu developers recommend Hub:</h4>
166 - <ul style="list-style:disc;margin-left:2em">
167 - <li>The Best Selling Theme of the Year</li>
168 - <li>Free Support + Updates + Plugins</li>
169 - <li>Elementor + WP Bakery + WP Bottom Menu Support</li>
170 - <li>800+ Award-Winning Templates</li>
171 - <li>And Many More!</li>
172 - </ul>
173 - <p style="display:flex;align-items:center;">
174 - <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' ); ?>" >
175 - Join Hub
176 - </a>
177 - <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' ); ?>" >
178 - Learn More
179 - </a>
180 - <a style="margin-left:auto" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'hub_promote', 'false' ), 'false' ) ); ?>" >
181 - Hide Notification
182 - </a>
183 - </p>
184 - </div>
185 - <?php
186 - } );
187 - }
188 -
189 - }
190 -
191 178 // enqueue scripts
192 179 function enqueue_scripts() {
193 180
194 181 // check the display condition
@@ -202,8 +189,15 @@
202 189 }
203 190 if ( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome2' ){
204 191 wp_enqueue_style( 'font-awesome-wpbm', WP_BOTTOM_MENU_DIR_URL . 'assets/vendors/fontawesome/all.min.css', array(), '6.1.1' );
205 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 + );
206 200
207 201 }
208 202
209 203 }
@@ -228,27 +222,39 @@
228 222 ) ) );
229 223 /*This returns a json so we have to decode it*/
230 224
231 225 $customizer_repeater_wpbm_decoded = json_decode($customizer_repeater_wpbm);
232 - $wpbm_woo_search = $wpbm_post_search = $wpbm_custom_search = false;
226 + $wpbm_woo_search = $wpbm_post_search = $wpbm_custom_search = $wpbm_custom_menu = false;
233 227 $search_icon = 'fa-search';
234 228 $wpbm_link_target = get_option( 'wpbottommenu_target' ) ? 'target=_blank' : '';
235 - foreach($customizer_repeater_wpbm_decoded as $repeater_item){
229 + foreach ( $customizer_repeater_wpbm_decoded as $repeater_item ) {
236 230
231 + $tag = 'a';
232 +
237 233 if ( $repeater_item->choice == "wpbm-woo-search" || $repeater_item->choice == "wpbm-post-search" || $repeater_item->choice == "wpbm-custom-search" ):
238 - $search_icon = $repeater_item->subtitle;
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 + }
239 240 ?>
240 - <a href="javascript:void(0);" title="<?php echo esc_attr( $repeater_item->title ); ?>" class="wp-bottom-menu-item wp-bottom-menu-search-form-trigger">
241 + <<?php echo $tag; ?> title="<?php echo esc_attr( $repeater_item->title ); ?>" class="wp-bottom-menu-item wp-bottom-menu-search-form-trigger">
241 242 <?php elseif ( $repeater_item->choice == "wpbm-menu" ): ?>
242 - <a href="javascript:void(0);" title="<?php echo esc_attr( $repeater_item->title ); ?>" class="wp-bottom-menu-item wp-bottom-menu-nav-trigger">
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">
243 248 <?php else: ?>
244 249 <?php
245 - $wpbm_item_url = $wpbm_item_active = '';
250 + $wpbm_item_url = '';
251 + $classes = array('wp-bottom-menu-item');
246 252 switch($repeater_item->choice){
247 253 case "wpbm-homepage":
248 254 $wpbm_item_url = esc_url( home_url() );
249 255 if ( is_front_page() ){
250 - $wpbm_item_active = 'active';
256 + array_push( $classes, 'active' );
251 257 }
252 258 break;
253 259 case "wpbm-woo-cart":
254 260 if ( class_exists( 'WooCommerce' ) ) {
@@ -263,18 +269,26 @@
263 269 } else {
264 270 $wpbm_item_url = '#';
265 271 }
266 272 break;
273 + case "wpbm-page-back":
274 + $wpbm_item_url = 'javascript:void(0)';
275 + array_push( $classes, 'wpbm-page-back' );
276 + break;
267 277 default:
268 278 $wpbm_item_url = esc_url( $repeater_item->link );
269 279 }
270 280
271 281 if ( url_to_postid($wpbm_item_url) === get_the_ID() ){
272 - $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 + }
273 287 }
274 288
275 289 ?>
276 - <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 ); ?>>
277 291 <?php endif; ?>
278 292
279 293 <div class="wp-bottom-menu-icon-wrapper">
280 294 <?php if( get_option( 'wpbottommenu_show_cart_count', false ) ): ?>
@@ -292,15 +306,17 @@
292 306 <?php endif; ?>
293 307 </div>
294 308 <?php if( !get_option( 'wpbottommenu_disable_title', false ) ): ?>
295 309 <?php if( get_option( 'wpbottommenu_show_cart_total', false ) && $repeater_item->choice == "wpbm-woo-cart" && class_exists( 'WooCommerce' ) ): ?>
296 - <span class="wp-bottom-menu-cart-total"><?php WC()->cart->get_cart_total(); ?></span>
297 - <?php else: ?>
298 - <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>
299 315 <?php endif; ?>
300 316 <?php endif; ?>
301 317
302 - </a>
318 + </<?php echo $tag; ?>>
303 319 <?php
304 320
305 321 if ( $repeater_item->choice == "wpbm-woo-search" && !$wpbm_woo_search )
306 322 $wpbm_woo_search = true;
@@ -310,34 +326,41 @@
310 326
311 327 if ( $repeater_item->choice == "wpbm-custom-search" && !$wpbm_custom_search )
312 328 $wpbm_custom_search = true;
313 329
330 + if ( $repeater_item->choice == "wpbm-menu" && !$wpbm_custom_menu )
331 + $wpbm_custom_menu = true;
332 +
314 333 }
315 334 ?>
316 335 </div>
317 336
318 - <?php if ( $repeater_item->choice == "wpbm-menu" ) : ?>
319 -
337 + <?php if ( $wpbm_custom_menu ) : ?>
320 338 <div class="wp-bottom-menu-nav-wrapper">
321 - <a href="javascript:void(0)" class="wpbm-nav-close">&times;</a>
339 + <span class="wpbm-nav-close">&times;</span>
322 340 <?php
323 -
324 - wp_nav_menu( array(
325 - 'menu' => 'wpbm_custom',
326 - 'container' => 'ul',
327 - 'menu_id' => 'wpbm-nav',
328 - 'menu_class' => 'wpbm-nav-items',
329 - ) );
330 -
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 + }
331 351 ?>
332 352 </div>
333 -
334 353 <?php endif;
335 354
336 355 if ( $wpbm_woo_search || $wpbm_post_search || $wpbm_custom_search ): ?>
337 356 <div class="wp-bottom-menu-search-form-wrapper" id="wp-bottom-menu-search-form-wrapper">
338 357 <form role="search" method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>" class="wp-bottom-menu-search-form">
339 - <i class="fa <?php echo esc_attr( $search_icon ); ?>"></i>
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; ?>
340 363 <?php if ( $wpbm_woo_search && class_exists( 'WooCommerce' ) ) { ?>
341 364 <input type="hidden" name="post_type" value="product" />
342 365 <?php } elseif ( $wpbm_post_search ) { ?>
343 366 <input type="hidden" name="post_type" value="post" />
@@ -358,10 +381,18 @@
358 381 </form>
359 382 </div>
360 383 <?php endif;
361 384
362 - }
385 + }
363 386
387 + function translated_menu_title( $title ) {
388 + if ( function_exists('pll__') ) {
389 + return pll__( $title );
390 + }
391 +
392 + return $title;
393 + }
394 +
364 395 function display_condition(){
365 396
366 397 $condition = new \WPBottomMenu_Condition();
367 398 return $condition->get_condition();
@@ -393,8 +424,9 @@
393 424 register_activation_hook( __FILE__, 'wp_bottom_menu_plugin_activate' );
394 425
395 426 function wp_bottom_menu_plugin_deactivate() {
396 427 /* If you want all settings to be deleted when the plugin is deactive, activate this field.
428 + TODO : Add reset all settings option
397 429
398 430 delete_option(' customizer_repeater_wpbm' );
399 431 delete_option( 'wpbottommenu_display_px' );
400 432 delete_option( 'wpbottommenu_display_always' );