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

372 lines 15.3 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.0
6 * Author: J4
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.0' );
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
135 function include_files(){
136
137 require_once( WP_BOTTOM_MENU_DIR_PATH . 'inc/customizer/customizer-repeater/functions.php' );
138 require_once( WP_BOTTOM_MENU_DIR_PATH . 'inc/customizer/customizer.php' );
139 require_once( WP_BOTTOM_MENU_DIR_PATH . 'inc/customizer/condition.php' );
140
141 }
142
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 // enqueue scripts
185 function enqueue_scripts() {
186
187 // check the display condition
188 if ( $this->display_condition() ){
189
190 wp_enqueue_style( 'wp-bottom-menu', WP_BOTTOM_MENU_DIR_URL . 'assets/css/style.css', array(), WP_BOTTOM_MENU_VERSION, 'all' );
191 wp_enqueue_script( 'wp-bottom-menu', WP_BOTTOM_MENU_DIR_URL . 'assets/js/main.js', array(), WP_BOTTOM_MENU_VERSION, true );
192
193 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 );
195 }
196 if ( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome2' ){
197 wp_enqueue_style( 'font-awesome-wpbm', WP_BOTTOM_MENU_DIR_URL . 'assets/vendors/fontawesome/all.min.css', array(), '6.1.1' );
198 }
199
200 }
201
202 }
203
204 // wp bottom menu
205 function wp_bottom_menu() {
206
207 // check the display condition
208 if ( !$this->display_condition() ){
209 return;
210 }
211
212 ?>
213 <div class="wp-bottom-menu" id="wp-bottom-menu">
214
215 <?php
216 $customizer_repeater_wpbm = get_option('customizer_repeater_wpbm', json_encode( array(
217 array("choice" => "wpbm-homepage" ,"subtitle" => "fa-home", "title" => "Home", "id" => "customizer_repeater_1" ),
218 array("choice" => "wpbm-woo-account" ,"subtitle" => "fa-user", "title" => "Account", "id" => "customizer_repeater_2" ),
219 array("choice" => "wpbm-woo-cart" ,"subtitle" => "fa-shopping-cart", "title" => "Cart", "id" => "customizer_repeater_3" ),
220 array("choice" => "wpbm-woo-search" ,"subtitle" => "fa-search", "title" => "Search", "id" => "customizer_repeater_4" ),
221 ) ) );
222 /*This returns a json so we have to decode it*/
223
224 $customizer_repeater_wpbm_decoded = json_decode($customizer_repeater_wpbm);
225 $wpbm_woo_search = false;
226 $wpbm_post_search = false;
227 $wpbm_link_target = get_option( 'wpbottommenu_target' ) ? 'target=_blank' : '';
228 foreach($customizer_repeater_wpbm_decoded as $repeater_item){
229
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">
232 <?php else: ?>
233 <?php
234 $wpbm_item_url = $wpbm_item_active = '';
235 switch($repeater_item->choice){
236 case "wpbm-homepage":
237 $wpbm_item_url = esc_url( home_url() );
238 if ( is_front_page() ){
239 $wpbm_item_active = 'active';
240 }
241 break;
242 case "wpbm-woo-cart":
243 if ( class_exists( 'WooCommerce' ) ) {
244 $wpbm_item_url = esc_url( wc_get_page_permalink( 'cart' ) );
245 } else {
246 $wpbm_item_url = '#';
247 }
248 break;
249 case "wpbm-woo-account":
250 if ( class_exists( 'WooCommerce' ) ) {
251 $wpbm_item_url = esc_url( wc_get_page_permalink( 'myaccount' ) );
252 } else {
253 $wpbm_item_url = '#';
254 }
255 break;
256 default:
257 $wpbm_item_url = esc_url( $repeater_item->link );
258 }
259
260 if ( url_to_postid($wpbm_item_url) === get_the_ID() ){
261 $wpbm_item_active = 'active';
262 }
263
264 ?>
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 ); ?>>
266 <?php endif; ?>
267
268 <div class="wp-bottom-menu-icon-wrapper">
269 <?php if( get_option( 'wpbottommenu_show_cart_count', false ) ): ?>
270 <?php if ( class_exists( 'WooCommerce' ) && $repeater_item->choice == "wpbm-woo-cart" ) : ?>
271 <div class="wp-bottom-menu-cart-count"><?php echo esc_html( WC()->cart->get_cart_contents_count() ); ?></div>
272 <?php endif; ?>
273 <?php endif; ?>
274
275 <?php if( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome' ): ?>
276 <i class="wp-bottom-menu-item-icons fa <?php echo esc_attr( $repeater_item->subtitle ); ?>"></i>
277 <?php elseif( get_option( 'wpbottommenu_iconset', 'fontawesome' ) == 'fontawesome2' ): ?>
278 <i class="wp-bottom-menu-item-icons <?php echo esc_attr( $repeater_item->subtitle ); ?>"></i>
279 <?php else: ?>
280 <?php echo html_entity_decode( $repeater_item->subtitle ); ?>
281 <?php endif; ?>
282 </div>
283 <?php if( !get_option( 'wpbottommenu_disable_title', false ) ): ?>
284 <?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>
288 <?php endif; ?>
289 <?php endif; ?>
290
291 </a>
292 <?php
293
294 if ( $repeater_item->choice == "wpbm-woo-search" && !$wpbm_woo_search )
295 $wpbm_woo_search = true;
296
297 if ( $repeater_item->choice == "wpbm-post-search" && !$wpbm_post_search )
298 $wpbm_post_search = true;
299
300 }
301 ?>
302 </div>
303
304 <?php if ( $wpbm_woo_search || $wpbm_post_search ): ?>
305 <div class="wp-bottom-menu-search-form-wrapper" id="wp-bottom-menu-search-form-wrapper">
306 <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"); ?>" />
309 <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 </form>
311 </div>
312 <?php endif;
313
314 }
315
316 function display_condition(){
317
318 $condition = new \WPBottomMenu_Condition();
319 return $condition->get_condition();
320
321 }
322
323 // woocommerce cart fragment
324 function wp_bottom_menu_add_to_cart_fragment( $fragments ) {
325 $fragments['div.wp-bottom-menu-cart-count'] = '<div class="wp-bottom-menu-cart-count">' . WC()->cart->get_cart_contents_count() . '</div>';
326 $fragments['span.wp-bottom-menu-cart-total'] = '<span class="wp-bottom-menu-cart-total">' . WC()->cart->get_cart_total() . '</span>';
327 return $fragments;
328 }
329
330 // plugin action links
331 function wp_bottom_menu_action_links( $links_array, $plugin_file_name ){
332 if( strpos( $plugin_file_name, basename(__FILE__) ) ) {
333 array_unshift( $links_array, '<a href="' . admin_url( 'customize.php?autofocus[panel]=wpbottommenu_panel' ) . '">Settings</a>' );
334 }
335 return $links_array;
336 }
337
338 } // class
339 WPBottomMenu::instance();
340
341
342 function wp_bottom_menu_plugin_activate() {
343 flush_rewrite_rules();
344 }
345 register_activation_hook( __FILE__, 'wp_bottom_menu_plugin_activate' );
346
347 function wp_bottom_menu_plugin_deactivate() {
348 /* If you want all settings to be deleted when the plugin is deactive, activate this field.
349
350 delete_option(' customizer_repeater_wpbm' );
351 delete_option( 'wpbottommenu_display_px' );
352 delete_option( 'wpbottommenu_display_always' );
353 delete_option( 'wpbottommenu_fontsize' );
354 delete_option( 'wpbottommenu_iconsize' );
355 delete_option( 'wpbottommenu_textcolor' );
356 delete_option( 'wpbottommenu_htextcolor' );
357 delete_option( 'wpbottommenu_iconcolor' );
358 delete_option( 'wpbottommenu_hiconcolor' );
359 delete_option( 'wpbottommenu_bgcolor' );
360 delete_option( 'wpbottommenu_zindex' );
361 delete_option( 'wpbottommenu_disable_title' );
362 delete_option( 'wpbottommenu_iconset' );
363 delete_option( 'wpbottommenu_placeholder_text' );
364 delete_option( 'wpbottommenu_show_cart_count' );
365 delete_option( 'wpbottommenu_show_cart_total' );
366 delete_option( 'wpbottommenu_cart_count_bgcolor' );
367 delete_option( 'wpbottommenu_hide_pages' );
368 delete_option( 'wpbottommenu_wrapper_padding' );
369 */
370 flush_rewrite_rules();
371 }
372 register_deactivation_hook( __FILE__, 'wp_bottom_menu_plugin_deactivate' );