PluginProbe
WP Bottom Menu / 2.2.1
WP Bottom Menu v2.2.1
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
wp-bottom-menu / wp-bottom-menu.php

wp-bottom-menu.php in WP Bottom Menu 2.2.1, at wp-bottom-menu.php

466 lines 20.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: WP Bottom Menu
4 * Description: WP Bottom Menu allows you to add a woocommerce supported bottom menu to your site.
5 * Version: 2.2.1
6 * Author: J4 & LiquidThemes
7 * Author URI: https://hub.liquid-themes.com/
8 * License: GPL v2 or later
9 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
10 * Text Domain: wp-bottom-menu
11 * Domain Path: /languages
12 *
13 * WP Bottom Menu is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 2 of the License, or
16 * any later version.
17 *
18 * WP Bottom Menu is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 */
23
24 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
25
26 define( 'WP_BOTTOM_MENU_VERSION', '2.2.1' );
27 define( 'WP_BOTTOM_MENU_DIR_URL', plugin_dir_url( __FILE__ ) );
28 define( 'WP_BOTTOM_MENU_DIR_PATH', plugin_dir_path( __FILE__ ) );
29
30
31 final class WPBottomMenu{
32
33 /**
34 * Instance
35 *
36 * @since 1.0.0
37 *
38 * @access private
39 * @static
40 *
41 * @var WPBottomMenu The single instance of the class.
42 */
43 private static $_instance = null;
44
45 /**
46 * Instance
47 *
48 * Ensures only one instance of the class is loaded or can be loaded.
49 *
50 * @since 1.0.0
51 *
52 * @access public
53 * @static
54 *
55 * @return WPBottomMenu An instance of the class.
56 */
57 public static function instance() {
58
59 if ( is_null( self::$_instance ) ) {
60 self::$_instance = new self();
61 }
62 return self::$_instance;
63 }
64
65 /**
66 * Constructor
67 *
68 * @since 1.0.0
69 *
70 * @access public
71 */
72 public function __construct() {
73 $this->init();
74 }
75
76 /**
77 * Load Textdomain
78 *
79 * Load plugin localization files.
80 *
81 * Fired by `init` action hook.
82 *
83 * @since 1.0.0
84 *
85 * @access public
86 */
87 public function i18n() {
88
89 load_plugin_textdomain( 'wp-bottom-menu' );
90
91 }
92
93 /**
94 * Initialize the plugin
95 *
96 * Load the files required to run the plugin.
97 *
98 * @since 1.0.0
99 *
100 * @access public
101 */
102 function init(){
103
104 $this->i18n();
105 $this->include_files();
106 $this->promote_hub();
107
108 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
109 add_action( 'wp_footer', array($this, 'wp_bottom_menu' ) );
110 add_filter( 'plugin_action_links', array($this, 'wp_bottom_menu_action_links'), 10, 2 );
111
112 // Admin menu - Settings > WP Bottom Menu
113 add_action( 'admin_menu', function() {
114 add_submenu_page(
115 'options-general.php', 'WP Bottom Menu', 'WP Bottom Menu', 'manage_options', 'wp-bottom-menu',
116 function(){
117 wp_redirect( admin_url( 'customize.php?autofocus[panel]=wpbottommenu_panel' ) );
118 }
119 );
120 } );
121
122 add_action( 'customize_controls_enqueue_scripts', function(){
123
124 // customizer js
125 wp_enqueue_script( 'wp-bottom-menu-customize', WP_BOTTOM_MENU_DIR_URL . 'assets/js/customizer.js', array( 'jquery', 'customize-controls' ), false, true );
126
127 // select2
128 wp_enqueue_script( 'select2', WP_BOTTOM_MENU_DIR_URL . 'assets/vendors/select2/select2.min.js', [], false, false );
129 wp_enqueue_style( 'select2', WP_BOTTOM_MENU_DIR_URL . 'assets/vendors/select2/select2.min.css', array(), WP_BOTTOM_MENU_VERSION, 'all' );
130 wp_add_inline_script( 'wp-bottom-menu-customize', '
131 jQuery( document ).ready(function() {
132 jQuery(".wp-bottom-menu-select2").select2({
133 placeholder: "Select an option"
134 });
135 });
136 ');
137 } );
138
139 // Load WooCommerce Fragments
140 if ( class_exists( 'WooCommerce' ) ){
141 add_filter( 'woocommerce_add_to_cart_fragments', array($this, 'wp_bottom_menu_add_to_cart_fragment'), 10, 1 );
142 }
143
144 // Register Nav Menus
145 add_action( 'after_setup_theme', function() {
146 register_nav_menus( array(
147 'wpbm_custom' => __( 'WP Bottom Menu', 'wp-bottom-menu' ),
148 ) );
149 } );
150 }
151
152 function include_files(){
153
154 require_once( WP_BOTTOM_MENU_DIR_PATH . 'inc/customizer/customizer-repeater/functions.php' );
155 require_once( WP_BOTTOM_MENU_DIR_PATH . 'inc/customizer/customizer.php' );
156 require_once( WP_BOTTOM_MENU_DIR_PATH . 'inc/customizer/condition.php' );
157
158 }
159
160 function promote_hub(){
161
162 // Hub promote notice
163 if ( isset( $_GET['hub_promote'] ) && 'false' === $_GET['hub_promote'] ) {
164 set_transient( 'hub_promote', [], 4 * WEEK_IN_SECONDS );
165 }
166
167 if ( false === get_transient( 'hub_promote' ) ){
168 add_action( 'admin_notices', function() {
169 if ( 'Hub' === wp_get_theme()->get( 'Name' ) || 'Hub Child' === wp_get_theme()->get( 'Name' ) ) {
170 return;
171 }
172 ?>
173 <div class="notice">
174 <h3 style="margin-bottom:0.5em">Looking for an ultra fast WP theme?</h3>
175 <h4 style="margin:0">WP Bottom Menu developers recommend Hub:</h4>
176 <ul style="list-style:disc;margin-left:2em">
177 <li>The Best Selling Theme of the Year</li>
178 <li>Free Support + Updates + Plugins</li>
179 <li>Elementor + WP Bakery + WP Bottom Menu Support</li>
180 <li>800+ Award-Winning Templates</li>
181 <li>And Many More!</li>
182 </ul>
183 <p style="display:flex;align-items:center;">
184 <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' ); ?>" >
185 Join Hub
186 </a>
187 <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' ); ?>" >
188 Learn More
189 </a>
190 <a style="margin-left:auto" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'hub_promote', 'false' ), 'false' ) ); ?>" >
191 Hide Notification
192 </a>
193 </p>
194 </div>
195 <?php
196 } );
197 }
198
199 }
200
201 // enqueue scripts
202 function enqueue_scripts() {
203
204 // check the display condition
205 if ( $this->display_condition() ){
206
207 wp_enqueue_style( 'wp-bottom-menu', WP_BOTTOM_MENU_DIR_URL . 'assets/css/style.css', array(), WP_BOTTOM_MENU_VERSION, 'all' );
208 wp_enqueue_script( 'wp-bottom-menu', WP_BOTTOM_MENU_DIR_URL . 'assets/js/main.js', array(), WP_BOTTOM_MENU_VERSION, true );
209
210 if ( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome' ){
211 wp_enqueue_style( 'font-awesome', WP_BOTTOM_MENU_DIR_URL . 'inc/customizer/customizer-repeater/css/font-awesome.min.css', array(), CUSTOMIZER_REPEATER_VERSION );
212 }
213 if ( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome2' ){
214 wp_enqueue_style( 'font-awesome-wpbm', WP_BOTTOM_MENU_DIR_URL . 'assets/vendors/fontawesome/all.min.css', array(), '6.1.1' );
215 }
216
217 wp_localize_script( 'wp-bottom-menu', 'WPBM',
218 array(
219 'ajaxurl' => admin_url( 'admin-ajax.php' ),
220 'siteurl' => site_url(),
221 )
222 );
223
224 }
225
226 }
227
228 // wp bottom menu
229 function wp_bottom_menu() {
230
231 // check the display condition
232 if ( !$this->display_condition() ){
233 return;
234 }
235
236 ?>
237 <div class="wp-bottom-menu" id="wp-bottom-menu">
238
239 <?php
240 $customizer_repeater_wpbm = get_option('customizer_repeater_wpbm', json_encode( array(
241 array("choice" => "wpbm-homepage" ,"subtitle" => "fa-home", "title" => "Home", "id" => "customizer_repeater_1" ),
242 array("choice" => "wpbm-woo-account" ,"subtitle" => "fa-user", "title" => "Account", "id" => "customizer_repeater_2" ),
243 array("choice" => "wpbm-woo-cart" ,"subtitle" => "fa-shopping-cart", "title" => "Cart", "id" => "customizer_repeater_3" ),
244 array("choice" => "wpbm-woo-search" ,"subtitle" => "fa-search", "title" => "Search", "id" => "customizer_repeater_4" ),
245 ) ) );
246 /*This returns a json so we have to decode it*/
247
248 $customizer_repeater_wpbm_decoded = json_decode($customizer_repeater_wpbm);
249 $wpbm_woo_search = $wpbm_post_search = $wpbm_custom_search = $wpbm_custom_menu = false;
250 $search_icon = 'fa-search';
251 $wpbm_link_target = get_option( 'wpbottommenu_target' ) ? 'target=_blank' : '';
252 foreach ( $customizer_repeater_wpbm_decoded as $repeater_item ) {
253
254 $tag = 'a';
255
256 if ( $repeater_item->choice == "wpbm-woo-search" || $repeater_item->choice == "wpbm-post-search" || $repeater_item->choice == "wpbm-custom-search" ):
257 $tag = 'div';
258 if ( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome' ) {
259 $search_icon = 'fa ' . $repeater_item->subtitle;
260 } elseif ( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome2' || get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'svg' ) {
261 $search_icon = $repeater_item->subtitle;
262 }
263 ?>
264 <<?php echo $tag; ?> title="<?php echo esc_attr( $repeater_item->title ); ?>" class="wp-bottom-menu-item wp-bottom-menu-search-form-trigger">
265 <?php elseif ( $repeater_item->choice == "wpbm-menu" ): ?>
266 <?php $tag = 'div'; ?>
267 <<?php echo $tag; ?> title="<?php echo esc_attr( $repeater_item->title ); ?>" class="wp-bottom-menu-item wp-bottom-menu-nav-trigger">
268 <?php elseif ( $repeater_item->choice == "wpbm-onclick" ): ?>
269 <?php $tag = 'div'; ?>
270 <<?php echo $tag; ?> onclick="<?php echo $repeater_item->text; ?>" title="<?php echo esc_attr( $repeater_item->title ); ?>" class="wp-bottom-menu-item">
271 <?php else: ?>
272 <?php
273 $wpbm_item_url = '';
274 $classes = array('wp-bottom-menu-item');
275 switch($repeater_item->choice){
276 case "wpbm-homepage":
277 $wpbm_item_url = esc_url( home_url() );
278 if ( is_front_page() ){
279 array_push( $classes, 'active' );
280 }
281 break;
282 case "wpbm-woo-cart":
283 if ( class_exists( 'WooCommerce' ) ) {
284 $wpbm_item_url = esc_url( wc_get_page_permalink( 'cart' ) );
285 } else {
286 $wpbm_item_url = '#';
287 }
288 break;
289 case "wpbm-woo-account":
290 if ( class_exists( 'WooCommerce' ) ) {
291 $wpbm_item_url = esc_url( wc_get_page_permalink( 'myaccount' ) );
292 } else {
293 $wpbm_item_url = '#';
294 }
295 break;
296 case "wpbm-page-back":
297 $wpbm_item_url = 'javascript:void(0)';
298 array_push( $classes, 'wpbm-page-back' );
299 break;
300 default:
301 $wpbm_item_url = esc_url( $repeater_item->link );
302 }
303
304 if ( url_to_postid($wpbm_item_url) === get_the_ID() ){
305 array_push( $classes, 'active' );
306 } elseif ( class_exists('WooCommerce') && is_shop() && url_to_postid($wpbm_item_url) === 0 ) {
307 if ( $wpbm_item_url !== home_url() ) {
308 array_push( $classes, 'active' );
309 }
310 }
311
312 ?>
313 <<?php echo $tag; ?> href="<?php echo $wpbm_item_url; ?>" class="<?php echo esc_attr( join( ' ', $classes ) ); ?>" <?php echo esc_attr( $wpbm_link_target ); ?>>
314 <?php endif; ?>
315
316 <div class="wp-bottom-menu-icon-wrapper">
317 <?php if( get_option( 'wpbottommenu_show_cart_count', false ) ): ?>
318 <?php if ( class_exists( 'WooCommerce' ) && $repeater_item->choice == "wpbm-woo-cart" ) : ?>
319 <div class="wp-bottom-menu-cart-count"><?php echo esc_html( WC()->cart->get_cart_contents_count() ); ?></div>
320 <?php endif; ?>
321 <?php endif; ?>
322
323 <?php if( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome' ): ?>
324 <i class="wp-bottom-menu-item-icons fa <?php echo esc_attr( $repeater_item->subtitle ); ?>"></i>
325 <?php elseif( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome2' ): ?>
326 <i class="wp-bottom-menu-item-icons <?php echo esc_attr( $repeater_item->subtitle ); ?>"></i>
327 <?php else: ?>
328 <?php echo html_entity_decode( $repeater_item->subtitle ); ?>
329 <?php endif; ?>
330 </div>
331 <?php if( !get_option( 'wpbottommenu_disable_title', false ) ): ?>
332 <?php if( get_option( 'wpbottommenu_show_cart_total', false ) && $repeater_item->choice == "wpbm-woo-cart" && class_exists( 'WooCommerce' ) ): ?>
333 <span class="wp-bottom-menu-cart-total"><?php WC()->cart->get_cart_total(); ?></span>
334 <?php elseif( get_option( 'wpbottommenu_show_account_name' ) && $repeater_item->choice == "wpbm-woo-account" && class_exists( 'WooCommerce' ) && is_user_logged_in() ): ?>
335 <?php echo wp_get_current_user()->first_name ? wp_get_current_user()->first_name : wp_get_current_user()->user_login; ?>
336 <?php else: ?>
337 <span><?php echo $repeater_item->title; ?></span>
338 <?php endif; ?>
339 <?php endif; ?>
340
341 </<?php echo $tag; ?>>
342 <?php
343
344 if ( $repeater_item->choice == "wpbm-woo-search" && !$wpbm_woo_search )
345 $wpbm_woo_search = true;
346
347 if ( $repeater_item->choice == "wpbm-post-search" && !$wpbm_post_search )
348 $wpbm_post_search = true;
349
350 if ( $repeater_item->choice == "wpbm-custom-search" && !$wpbm_custom_search )
351 $wpbm_custom_search = true;
352
353 if ( $repeater_item->choice == "wpbm-menu" && !$wpbm_custom_menu )
354 $wpbm_custom_menu = true;
355
356 }
357 ?>
358 </div>
359
360 <?php if ( $wpbm_custom_menu ) : ?>
361 <div class="wp-bottom-menu-nav-wrapper">
362 <span class="wpbm-nav-close">&times;</span>
363 <?php
364 if ( has_nav_menu( 'wpbm_custom' ) ) {
365 wp_nav_menu( array(
366 'menu' => 'wpbm_custom',
367 'container' => 'ul',
368 'menu_id' => 'wpbm-nav',
369 'menu_class' => 'wpbm-nav-items',
370 ) );
371 } else {
372 esc_html_e( 'Add a menu in "WP Dashboard->Appearance->Menus" and select Display location "WP Bottom Menu"', 'wp-bottom-menu' );
373 }
374 ?>
375 </div>
376 <?php endif;
377
378 if ( $wpbm_woo_search || $wpbm_post_search || $wpbm_custom_search ): ?>
379 <div class="wp-bottom-menu-search-form-wrapper" id="wp-bottom-menu-search-form-wrapper">
380 <form role="search" method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>" class="wp-bottom-menu-search-form">
381 <?php if ( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'svg' ) : ?>
382 <?php echo html_entity_decode( $search_icon ); ?>
383 <?php else : ?>
384 <i class="<?php echo esc_attr( $search_icon ); ?>"></i>
385 <?php endif; ?>
386 <?php if ( $wpbm_woo_search && class_exists( 'WooCommerce' ) ) { ?>
387 <input type="hidden" name="post_type" value="product" />
388 <?php } elseif ( $wpbm_post_search ) { ?>
389 <input type="hidden" name="post_type" value="post" />
390 <?php } else {
391 $search_cpt = get_option( 'wpbottommenu_search_cpt', 'all' );
392 if ( $search_cpt === 'all' || empty( $search_cpt ) ){
393 ?><input type="hidden" name="post_type" value="all" /><?php
394 } else {
395 $search_cpt = explode(',', $search_cpt);
396 foreach( $search_cpt as $cpt ){
397 if ( !empty( $cpt ) ){
398 ?><input type="hidden" name="post_type[]" value="<?php echo esc_attr( $cpt ); ?>" /><?php
399 }
400 }
401 }
402 } ?>
403 <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" />
404 </form>
405 </div>
406 <?php endif;
407
408 }
409
410 function display_condition(){
411
412 $condition = new \WPBottomMenu_Condition();
413 return $condition->get_condition();
414
415 }
416
417 // woocommerce cart fragment
418 function wp_bottom_menu_add_to_cart_fragment( $fragments ) {
419 $fragments['div.wp-bottom-menu-cart-count'] = '<div class="wp-bottom-menu-cart-count">' . WC()->cart->get_cart_contents_count() . '</div>';
420 $fragments['span.wp-bottom-menu-cart-total'] = '<span class="wp-bottom-menu-cart-total">' . WC()->cart->get_cart_total() . '</span>';
421 return $fragments;
422 }
423
424 // plugin action links
425 function wp_bottom_menu_action_links( $links_array, $plugin_file_name ){
426 if( strpos( $plugin_file_name, basename(__FILE__) ) ) {
427 array_unshift( $links_array, '<a href="' . admin_url( 'customize.php?autofocus[panel]=wpbottommenu_panel' ) . '">Settings</a>' );
428 }
429 return $links_array;
430 }
431
432 } // class
433 WPBottomMenu::instance();
434
435
436 function wp_bottom_menu_plugin_activate() {
437 flush_rewrite_rules();
438 }
439 register_activation_hook( __FILE__, 'wp_bottom_menu_plugin_activate' );
440
441 function wp_bottom_menu_plugin_deactivate() {
442 /* If you want all settings to be deleted when the plugin is deactive, activate this field.
443
444 delete_option(' customizer_repeater_wpbm' );
445 delete_option( 'wpbottommenu_display_px' );
446 delete_option( 'wpbottommenu_display_always' );
447 delete_option( 'wpbottommenu_fontsize' );
448 delete_option( 'wpbottommenu_iconsize' );
449 delete_option( 'wpbottommenu_textcolor' );
450 delete_option( 'wpbottommenu_htextcolor' );
451 delete_option( 'wpbottommenu_iconcolor' );
452 delete_option( 'wpbottommenu_hiconcolor' );
453 delete_option( 'wpbottommenu_bgcolor' );
454 delete_option( 'wpbottommenu_zindex' );
455 delete_option( 'wpbottommenu_disable_title' );
456 delete_option( 'wpbottommenu_iconset' );
457 delete_option( 'wpbottommenu_placeholder_text' );
458 delete_option( 'wpbottommenu_show_cart_count' );
459 delete_option( 'wpbottommenu_show_cart_total' );
460 delete_option( 'wpbottommenu_cart_count_bgcolor' );
461 delete_option( 'wpbottommenu_hide_pages' );
462 delete_option( 'wpbottommenu_wrapper_padding' );
463 */
464 flush_rewrite_rules();
465 }
466 register_deactivation_hook( __FILE__, 'wp_bottom_menu_plugin_deactivate' );