PluginProbe
WP Bottom Menu / 2.1.4
WP Bottom Menu v2.1.4
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.1.4, at wp-bottom-menu.php

446 lines 18.8 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.1.4
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.1.4' );
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 add_action( 'customize_controls_enqueue_scripts', function(){
113
114 // customizer js
115 wp_enqueue_script( 'wp-bottom-menu-customize', WP_BOTTOM_MENU_DIR_URL . 'assets/js/customizer.js', array( 'jquery', 'customize-controls' ), false, true );
116
117 // select2
118 wp_enqueue_script( 'select2', WP_BOTTOM_MENU_DIR_URL . 'assets/vendors/select2/select2.min.js', [], false, false );
119 wp_enqueue_style( 'select2', WP_BOTTOM_MENU_DIR_URL . 'assets/vendors/select2/select2.min.css', array(), WP_BOTTOM_MENU_VERSION, 'all' );
120 wp_add_inline_script( 'wp-bottom-menu-customize', '
121 jQuery( document ).ready(function() {
122 jQuery(".wp-bottom-menu-select2").select2({
123 placeholder: "Select an option"
124 });
125 });
126 ');
127 } );
128
129 // Load WooCommerce Fragments
130 if ( class_exists( 'WooCommerce' ) ){
131 add_filter( 'woocommerce_add_to_cart_fragments', array($this, 'wp_bottom_menu_add_to_cart_fragment'), 10, 1 );
132 }
133
134 // Register Nav Menus
135 add_action( 'after_setup_theme', function() {
136 register_nav_menus( array(
137 'wpbm_custom' => __( 'WP Bottom Menu', 'wp-bottom-menu' ),
138 ) );
139 } );
140 }
141
142 function include_files(){
143
144 require_once( WP_BOTTOM_MENU_DIR_PATH . 'inc/customizer/customizer-repeater/functions.php' );
145 require_once( WP_BOTTOM_MENU_DIR_PATH . 'inc/customizer/customizer.php' );
146 require_once( WP_BOTTOM_MENU_DIR_PATH . 'inc/customizer/condition.php' );
147
148 }
149
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 // enqueue scripts
192 function enqueue_scripts() {
193
194 // check the display condition
195 if ( $this->display_condition() ){
196
197 wp_enqueue_style( 'wp-bottom-menu', WP_BOTTOM_MENU_DIR_URL . 'assets/css/style.css', array(), WP_BOTTOM_MENU_VERSION, 'all' );
198 wp_enqueue_script( 'wp-bottom-menu', WP_BOTTOM_MENU_DIR_URL . 'assets/js/main.js', array(), WP_BOTTOM_MENU_VERSION, true );
199
200 if ( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome' ){
201 wp_enqueue_style( 'font-awesome', WP_BOTTOM_MENU_DIR_URL . 'inc/customizer/customizer-repeater/css/font-awesome.min.css', array(), CUSTOMIZER_REPEATER_VERSION );
202 }
203 if ( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome2' ){
204 wp_enqueue_style( 'font-awesome-wpbm', WP_BOTTOM_MENU_DIR_URL . 'assets/vendors/fontawesome/all.min.css', array(), '6.1.1' );
205 }
206
207 wp_localize_script( 'wp-bottom-menu', 'WPBM',
208 array(
209 'ajaxurl' => admin_url( 'admin-ajax.php' ),
210 'siteurl' => site_url(),
211 )
212 );
213
214 }
215
216 }
217
218 // wp bottom menu
219 function wp_bottom_menu() {
220
221 // check the display condition
222 if ( !$this->display_condition() ){
223 return;
224 }
225
226 ?>
227 <div class="wp-bottom-menu" id="wp-bottom-menu">
228
229 <?php
230 $customizer_repeater_wpbm = get_option('customizer_repeater_wpbm', json_encode( array(
231 array("choice" => "wpbm-homepage" ,"subtitle" => "fa-home", "title" => "Home", "id" => "customizer_repeater_1" ),
232 array("choice" => "wpbm-woo-account" ,"subtitle" => "fa-user", "title" => "Account", "id" => "customizer_repeater_2" ),
233 array("choice" => "wpbm-woo-cart" ,"subtitle" => "fa-shopping-cart", "title" => "Cart", "id" => "customizer_repeater_3" ),
234 array("choice" => "wpbm-woo-search" ,"subtitle" => "fa-search", "title" => "Search", "id" => "customizer_repeater_4" ),
235 ) ) );
236 /*This returns a json so we have to decode it*/
237
238 $customizer_repeater_wpbm_decoded = json_decode($customizer_repeater_wpbm);
239 $wpbm_woo_search = $wpbm_post_search = $wpbm_custom_search = false;
240 $search_icon = 'fa-search';
241 $wpbm_link_target = get_option( 'wpbottommenu_target' ) ? 'target=_blank' : '';
242 foreach($customizer_repeater_wpbm_decoded as $repeater_item){
243
244 if ( $repeater_item->choice == "wpbm-woo-search" || $repeater_item->choice == "wpbm-post-search" || $repeater_item->choice == "wpbm-custom-search" ):
245 if( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome' ){
246 $search_icon = 'fa ' . $repeater_item->subtitle;
247 } elseif ( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome2' || get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'svg' ) {
248 $search_icon = $repeater_item->subtitle;
249 }
250 ?>
251 <a href="javascript:void(0);" title="<?php echo esc_attr( $repeater_item->title ); ?>" class="wp-bottom-menu-item wp-bottom-menu-search-form-trigger">
252 <?php elseif ( $repeater_item->choice == "wpbm-menu" ): ?>
253 <a href="javascript:void(0);" title="<?php echo esc_attr( $repeater_item->title ); ?>" class="wp-bottom-menu-item wp-bottom-menu-nav-trigger">
254 <?php else: ?>
255 <?php
256 $wpbm_item_url = '';
257 $classes = array('wp-bottom-menu-item');
258 switch($repeater_item->choice){
259 case "wpbm-homepage":
260 $wpbm_item_url = esc_url( home_url() );
261 if ( is_front_page() ){
262 array_push( $classes, 'active' );
263 }
264 break;
265 case "wpbm-woo-cart":
266 if ( class_exists( 'WooCommerce' ) ) {
267 $wpbm_item_url = esc_url( wc_get_page_permalink( 'cart' ) );
268 } else {
269 $wpbm_item_url = '#';
270 }
271 break;
272 case "wpbm-woo-account":
273 if ( class_exists( 'WooCommerce' ) ) {
274 $wpbm_item_url = esc_url( wc_get_page_permalink( 'myaccount' ) );
275 } else {
276 $wpbm_item_url = '#';
277 }
278 break;
279 case "wpbm-page-back":
280 $wpbm_item_url = 'javascript:void(0)';
281 array_push( $classes, 'wpbm-page-back' );
282 break;
283 default:
284 $wpbm_item_url = esc_url( $repeater_item->link );
285 }
286
287 if ( url_to_postid($wpbm_item_url) === get_the_ID() ){
288 array_push( $classes, 'active' );
289 } elseif ( class_exists('WooCommerce') && is_shop() && url_to_postid($wpbm_item_url) === 0 ) {
290 if ( $wpbm_item_url !== home_url() ) {
291 array_push( $classes, 'active' );
292 }
293 }
294
295 ?>
296 <a href="<?php echo $wpbm_item_url; ?>" class="<?php echo esc_attr( join( ' ', $classes ) ); ?>" <?php echo esc_attr( $wpbm_link_target ); ?>>
297 <?php endif; ?>
298
299 <div class="wp-bottom-menu-icon-wrapper">
300 <?php if( get_option( 'wpbottommenu_show_cart_count', false ) ): ?>
301 <?php if ( class_exists( 'WooCommerce' ) && $repeater_item->choice == "wpbm-woo-cart" ) : ?>
302 <div class="wp-bottom-menu-cart-count"><?php echo esc_html( WC()->cart->get_cart_contents_count() ); ?></div>
303 <?php endif; ?>
304 <?php endif; ?>
305
306 <?php if( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome' ): ?>
307 <i class="wp-bottom-menu-item-icons fa <?php echo esc_attr( $repeater_item->subtitle ); ?>"></i>
308 <?php elseif( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome2' ): ?>
309 <i class="wp-bottom-menu-item-icons <?php echo esc_attr( $repeater_item->subtitle ); ?>"></i>
310 <?php else: ?>
311 <?php echo html_entity_decode( $repeater_item->subtitle ); ?>
312 <?php endif; ?>
313 </div>
314 <?php if( !get_option( 'wpbottommenu_disable_title', false ) ): ?>
315 <?php if( get_option( 'wpbottommenu_show_cart_total', false ) && $repeater_item->choice == "wpbm-woo-cart" && class_exists( 'WooCommerce' ) ): ?>
316 <span class="wp-bottom-menu-cart-total"><?php WC()->cart->get_cart_total(); ?></span>
317 <?php elseif( get_option( 'wpbottommenu_show_account_name' ) && $repeater_item->choice == "wpbm-woo-account" && class_exists( 'WooCommerce' ) ): ?>
318 <?php echo wp_get_current_user()->first_name ? wp_get_current_user()->first_name : wp_get_current_user()->user_login; ?>
319 <?php else: ?>
320 <span><?php echo $repeater_item->title; ?></span>
321 <?php endif; ?>
322 <?php endif; ?>
323
324 </a>
325 <?php
326
327 if ( $repeater_item->choice == "wpbm-woo-search" && !$wpbm_woo_search )
328 $wpbm_woo_search = true;
329
330 if ( $repeater_item->choice == "wpbm-post-search" && !$wpbm_post_search )
331 $wpbm_post_search = true;
332
333 if ( $repeater_item->choice == "wpbm-custom-search" && !$wpbm_custom_search )
334 $wpbm_custom_search = true;
335
336 }
337 ?>
338 </div>
339
340 <?php if ( $repeater_item->choice == "wpbm-menu" ) : ?>
341
342 <div class="wp-bottom-menu-nav-wrapper">
343 <a href="javascript:void(0)" class="wpbm-nav-close">&times;</a>
344 <?php
345
346 wp_nav_menu( array(
347 'menu' => 'wpbm_custom',
348 'container' => 'ul',
349 'menu_id' => 'wpbm-nav',
350 'menu_class' => 'wpbm-nav-items',
351 ) );
352
353 ?>
354 </div>
355
356 <?php endif;
357
358 if ( $wpbm_woo_search || $wpbm_post_search || $wpbm_custom_search ): ?>
359 <div class="wp-bottom-menu-search-form-wrapper" id="wp-bottom-menu-search-form-wrapper">
360 <form role="search" method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>" class="wp-bottom-menu-search-form">
361 <?php if ( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'svg' ) : ?>
362 <?php echo html_entity_decode( $search_icon ); ?>
363 <?php else : ?>
364 <i class="<?php echo esc_attr( $search_icon ); ?>"></i>
365 <?php endif; ?>
366 <?php if ( $wpbm_woo_search && class_exists( 'WooCommerce' ) ) { ?>
367 <input type="hidden" name="post_type" value="product" />
368 <?php } elseif ( $wpbm_post_search ) { ?>
369 <input type="hidden" name="post_type" value="post" />
370 <?php } else {
371 $search_cpt = get_option( 'wpbottommenu_search_cpt', 'all' );
372 if ( $search_cpt === 'all' || empty( $search_cpt ) ){
373 ?><input type="hidden" name="post_type" value="all" /><?php
374 } else {
375 $search_cpt = explode(',', $search_cpt);
376 foreach( $search_cpt as $cpt ){
377 if ( !empty( $cpt ) ){
378 ?><input type="hidden" name="post_type[]" value="<?php echo esc_attr( $cpt ); ?>" /><?php
379 }
380 }
381 }
382 } ?>
383 <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" />
384 </form>
385 </div>
386 <?php endif;
387
388 }
389
390 function display_condition(){
391
392 $condition = new \WPBottomMenu_Condition();
393 return $condition->get_condition();
394
395 }
396
397 // woocommerce cart fragment
398 function wp_bottom_menu_add_to_cart_fragment( $fragments ) {
399 $fragments['div.wp-bottom-menu-cart-count'] = '<div class="wp-bottom-menu-cart-count">' . WC()->cart->get_cart_contents_count() . '</div>';
400 $fragments['span.wp-bottom-menu-cart-total'] = '<span class="wp-bottom-menu-cart-total">' . WC()->cart->get_cart_total() . '</span>';
401 return $fragments;
402 }
403
404 // plugin action links
405 function wp_bottom_menu_action_links( $links_array, $plugin_file_name ){
406 if( strpos( $plugin_file_name, basename(__FILE__) ) ) {
407 array_unshift( $links_array, '<a href="' . admin_url( 'customize.php?autofocus[panel]=wpbottommenu_panel' ) . '">Settings</a>' );
408 }
409 return $links_array;
410 }
411
412 } // class
413 WPBottomMenu::instance();
414
415
416 function wp_bottom_menu_plugin_activate() {
417 flush_rewrite_rules();
418 }
419 register_activation_hook( __FILE__, 'wp_bottom_menu_plugin_activate' );
420
421 function wp_bottom_menu_plugin_deactivate() {
422 /* If you want all settings to be deleted when the plugin is deactive, activate this field.
423
424 delete_option(' customizer_repeater_wpbm' );
425 delete_option( 'wpbottommenu_display_px' );
426 delete_option( 'wpbottommenu_display_always' );
427 delete_option( 'wpbottommenu_fontsize' );
428 delete_option( 'wpbottommenu_iconsize' );
429 delete_option( 'wpbottommenu_textcolor' );
430 delete_option( 'wpbottommenu_htextcolor' );
431 delete_option( 'wpbottommenu_iconcolor' );
432 delete_option( 'wpbottommenu_hiconcolor' );
433 delete_option( 'wpbottommenu_bgcolor' );
434 delete_option( 'wpbottommenu_zindex' );
435 delete_option( 'wpbottommenu_disable_title' );
436 delete_option( 'wpbottommenu_iconset' );
437 delete_option( 'wpbottommenu_placeholder_text' );
438 delete_option( 'wpbottommenu_show_cart_count' );
439 delete_option( 'wpbottommenu_show_cart_total' );
440 delete_option( 'wpbottommenu_cart_count_bgcolor' );
441 delete_option( 'wpbottommenu_hide_pages' );
442 delete_option( 'wpbottommenu_wrapper_padding' );
443 */
444 flush_rewrite_rules();
445 }
446 register_deactivation_hook( __FILE__, 'wp_bottom_menu_plugin_deactivate' );