first commit

This commit is contained in:
2024-07-15 11:28:08 +02:00
commit f52d538ea5
21891 changed files with 6161164 additions and 0 deletions

View File

@@ -0,0 +1,293 @@
<?php
/**
* Class description
*
* @package package_name
* @author Cherry Team
* @license GPL-2.0+
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Menu_Assets' ) ) {
/**
* Define Jet_Menu_Assets class
*/
class Jet_Menu_Assets {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Constructor for the class
*/
public function init() {
add_action( 'admin_enqueue_scripts', array( $this, 'admin_assets' ), 99 );
add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'editor_styles' ) );
add_action( 'admin_footer', array( $this, 'admin_templates' ) );
// Register public assets.
add_action( 'wp_enqueue_scripts', array( $this, 'register_public_assets' ) );
// Enqueue public assets.
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_public_assets' ), 10 );
add_action( 'elementor/frontend/before_enqueue_scripts', array( $this, 'enqueue_elementor_widget_scripts' ) );
}
/**
* Load admin assets
*
* @param string $hook Current page hook.
* @return void
*/
public function admin_assets( $hook ) {
wp_register_script(
'jet-sticky-sidebar',
jet_menu()->plugin_url( 'assets/admin/js/jquery.sticky-sidebar.min.js' ),
array( 'jquery' ),
'3.2.0',
true
);
wp_register_script(
'jet-menu-admin',
jet_menu()->plugin_url( 'assets/admin/js/admin.js' ),
array( 'jet-sticky-sidebar', 'wp-util' ),
jet_menu()->get_version(),
true
);
wp_localize_script( 'jet-menu-admin', 'jetMenuAdminSettings', apply_filters(
'jet-menu/assets/admin/localize',
array(
'tabs' => jet_menu_settings_item()->get_tabs(),
'strings' => array(
'leaveEditor' => esc_html__( 'Do you want to leave the editor? Changes you made may not be saved.', 'jet-menu' ),
'saveLabel' => esc_html__( 'Save', 'jet-menu' ),
'triggerLabel' => esc_html__( 'JetMenu', 'jet-menu' ),
),
'optionPageMessages' => array(
'saveMessage' => esc_html__( 'Options have been saved', 'jet-menu' ),
'restoreMessage' => esc_html__( 'Settings have been restored, page will be reloaded', 'jet-menu' ),
'emptyImportFile' => esc_html__( 'Please select options file to import.', 'jet-menu' ),
'incorrectImportFile' => esc_html__( 'Options file must be only in .json format.', 'jet-menu' ),
'redirectUrl' => menu_page_url( 'jet-menu-options', false ),
'resetMessage' => esc_html__( 'All menu options will be reseted to defaults. Please export current options to prevent data lost. Are you sure you want to continue?', 'jet-menu' ),
),
'importUrl' => add_query_arg( array( 'jet-action' => 'import-options' ), esc_url( admin_url( 'admin.php' ) ) ),
'resetUrl' => add_query_arg( array( 'jet-action' => 'reset-options' ), esc_url( admin_url( 'admin.php' ) ) ),
)
) );
wp_register_style(
'jet-menu-admin',
jet_menu()->plugin_url( 'assets/admin/css/admin.css' ),
array(),
jet_menu()->get_version()
);
wp_register_style(
'font-awesome',
jet_menu()->plugin_url( 'assets/public/css/font-awesome.min.css' ),
array(),
'4.7.0'
);
wp_enqueue_script( 'jet-menu-admin' );
wp_enqueue_style( 'jet-menu-admin' );
wp_enqueue_style( 'font-awesome' );
}
/**
* Load editor styles
*
* @return void
*/
public function editor_styles() {
if ( ! isset( $_REQUEST['context'] ) || 'jet-menu' !== $_REQUEST['context'] ) {
return;
}
wp_enqueue_style(
'jet-menu-editor',
jet_menu()->plugin_url( 'assets/admin/css/editor.css' ),
array(),
jet_menu()->get_version()
);
}
/**
* Load public assets
*
* @param string $hook Current page hook.
* @return void
*/
public function register_public_assets() {
wp_register_style(
'font-awesome',
jet_menu()->plugin_url( 'assets/public/css/font-awesome.min.css' ),
array(),
'4.7.0'
);
wp_register_style(
'jet-menu-public',
jet_menu()->plugin_url( 'assets/public/css/public.css' ),
array( 'font-awesome' ),
jet_menu()->get_version()
);
wp_register_script(
'jet-menu-plugin',
jet_menu()->plugin_url( 'assets/public/js/jet-menu-plugin.js' ),
array( 'jquery' ),
jet_menu()->get_version(),
true
);
wp_register_script(
'jet-menu-public',
jet_menu()->plugin_url( 'assets/public/js/jet-menu-public-script.js' ),
array( 'jquery', 'jet-menu-plugin' ),
jet_menu()->get_version(),
true
);
$default_mobile_breakpoint = jet_menu_option_page()->get_default_mobile_breakpoint();
wp_localize_script( 'jet-menu-public', 'jetMenuPublicSettings', apply_filters(
'jet-menu/assets/public/localize',
array(
'menuSettings' => array(
'jetMenuRollUp' => jet_menu_option_page()->get_option( 'jet-menu-roll-up', 'false' ),
'jetMenuMouseleaveDelay' => jet_menu_option_page()->get_option( 'jet-menu-mouseleave-delay', 500 ),
'jetMenuMegaWidthType' => jet_menu_option_page()->get_option( 'jet-mega-menu-width-type', 'container' ),
'jetMenuMegaWidthSelector' => jet_menu_option_page()->get_option( 'jet-mega-menu-selector-width-type', '' ),
'jetMenuMegaOpenSubType' => jet_menu_option_page()->get_option( 'jet-menu-open-sub-type', 'hover' ),
'jetMenuMobileBreakpoint' => jet_menu_option_page()->get_option( 'jet-menu-mobile-breakpoint', $default_mobile_breakpoint ),
),
)
) );
}
/**
* Enqueue public assets.
*
* @since 1.0.0
*/
public function enqueue_public_assets() {
wp_enqueue_style( 'jet-menu-public' );
wp_enqueue_script( 'jet-menu-public' );
}
/**
* Enqueue plugin scripts only with elementor scripts
*
* @return void
*/
public function enqueue_elementor_widget_scripts() {
wp_enqueue_script(
'jet-menu-widgets-scripts',
jet_menu()->plugin_url( 'assets/public/js/jet-menu-widgets-scripts.js' ),
array( 'jquery', 'elementor-frontend' ),
jet_menu()->get_version(),
true
);
}
/**
* Print admin templates
*
* @return void
*/
public function admin_templates() {
$screen = get_current_screen();
if ( 'nav-menus' !== $screen->base ) {
return;
}
$templates = array(
'menu-trigger' => 'admin/html/menu-trigger.html',
'popup-wrapper' => 'admin/html/popup-wrapper.html',
'popup-tabs' => 'admin/html/popup-tabs.html',
'editor-frame' => 'admin/html/editor-frame.html',
);
$this->print_templates_array( $templates );
}
/**
* Print templates array
*
* @param array $templates List of templates to print.
* @return [type] [description]
*/
public function print_templates_array( $templates = array() ) {
if ( empty( $templates ) ) {
return;
}
foreach ( $templates as $id => $file ) {
$file = jet_menu()->get_template( $file );
if ( ! file_exists( $file ) ) {
continue;
}
ob_start();
include $file;
$content = ob_get_clean();
printf( '<script type="text/html" id="tmpl-%1$s">%2$s</script>', $id, $content );
}
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Menu_Assets
*
* @return object
*/
function jet_menu_assets() {
return Jet_Menu_Assets::get_instance();
}

View File

@@ -0,0 +1,261 @@
<?php
/**
* CSS files manager
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Menu_CSS_File' ) ) {
/**
* Define Jet_Menu_CSS_File class
*/
class Jet_Menu_CSS_File {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
private $menu_dir = null;
private $menu_url = null;
private $enqueued = array();
private $presets_to_save = array();
/**
* Constructor for the class
*/
public function init() {
$enbaled = jet_menu_option_page()->get_option( 'jet-menu-cache-css', 'true' );
if ( 'true' !== $enbaled ) {
return;
}
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_menu_css' ) );
add_action( 'jet-menu/options-page/save', array( $this, 'remove_css_file' ) );
add_action( 'jet-menu/presets/created', array( $this, 'remove_css_file' ) );
add_action( 'jet-menu/presets/updated', array( $this, 'remove_css_file' ) );
add_action( 'jet-menu/presets/loaded', array( $this, 'remove_css_file' ) );
add_action( 'jet-menu/presets/deleted', array( $this, 'remove_css_file' ) );
add_action( 'jet-menu/item-settings/save', array( $this, 'remove_css_file' ) );
add_filter( 'cherry_dynamic_css_collector_localize_object', array( $this, 'maybe_create_css_file' ) );
}
/**
* Maybe create menu CSS file
*
* @param [type] $data [description]
* @return [type] [description]
*/
public function maybe_create_css_file( $data ) {
foreach ( $this->presets_to_save as $preset ) {
if ( ! empty( $data['css'] ) && ! $this->menu_css_exists( $preset ) ) {
file_put_contents( $this->menu_css_path( $preset ), htmlspecialchars_decode( $data['css'] ) );
}
}
return $data;
}
public function add_preset_to_save( $preset = 0 ) {
if ( ! $preset ) {
$preset = 'general';
}
if ( ! in_array( $preset, $this->presets_to_save ) ) {
$this->presets_to_save[] = $preset;
}
}
/**
* Remove CSS file on options save
*
* @return [type] [description]
*/
public function remove_css_file() {
foreach ( glob( $this->menu_dir() . '*.css' ) as $file ) {
$slug = basename( $file, '.css' );
$preset = str_replace( 'jet-menu-', '', $slug );
if ( $this->menu_css_exists( $preset ) ) {
unlink( $this->menu_css_path( $preset ) );
}
}
}
/**
* Enqueue menu CSS
* @return [type] [description]
*/
public function enqueue_menu_css() {
if ( ! $this->ensure_menu_dir() ) {
return;
}
foreach ( glob( $this->menu_dir() . '*.css' ) as $file ) {
$slug = basename( $file, '.css' );
$preset = str_replace( 'jet-menu-', '', $slug );
if ( $this->menu_css_exists( $preset ) ) {
wp_enqueue_style(
$slug,
$this->menu_css_url( $preset ),
array(),
filemtime( $this->menu_css_path( $preset ) )
);
$this->enqueued[] = $preset;
}
}
}
/**
* Check if menu CSS file exists
*
* @return [type] [description]
*/
public function menu_css_exists( $preset = 'general' ) {
return file_exists( $this->menu_css_path( $preset ) );
}
/**
* Return path to menu CSS file
*
* @return [type] [description]
*/
public function menu_css_path( $preset = 'general' ) {
return $this->menu_dir() . 'jet-menu-' . $preset . '.css';
}
/**
* Return url to menu CSS file
*
* @return [type] [description]
*/
public function menu_css_url( $preset = 'general' ) {
return $this->menu_url() . 'jet-menu-' . $preset . '.css';
}
/**
* Check if passed preset is already enqueued
*
* @param integer|string $preset Preset to check
* @return boolean
*/
public function is_enqueued( $preset = 0 ) {
if ( ! $preset ) {
$preset = 'general';
}
return in_array( $preset, $this->enqueued );
}
/**
* Returns menu CSS directory URL
*
* @return [type] [description]
*/
public function menu_url() {
if ( null !== $this->menu_url ) {
return $this->menu_url;
}
$upload_dir = wp_upload_dir();
$upload_base_dir = $upload_dir['baseurl'];
$this->menu_url = trailingslashit( $upload_base_dir ) . 'jet-menu/';
if ( is_ssl() ) {
$this->menu_url = set_url_scheme( $this->menu_url );
}
return $this->menu_url;
}
/**
* Returns menu CSS directory path
*
* @return [type] [description]
*/
public function menu_dir() {
if ( null !== $this->menu_dir ) {
return $this->menu_dir;
}
$upload_dir = wp_upload_dir();
$upload_base_dir = $upload_dir['basedir'];
$this->menu_dir = trailingslashit( $upload_base_dir ) . 'jet-menu/';
return $this->menu_dir;
}
/**
* Ensure that CSS directory exists and try to create if not.
*
* @return bool
*/
public function ensure_menu_dir() {
if ( file_exists( $this->menu_dir() ) ) {
return true;
} else {
return mkdir( $this->menu_dir() );
}
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Menu_CSS_File
*
* @return object
*/
function jet_menu_css_file() {
return Jet_Menu_CSS_File::get_instance();
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,135 @@
<?php
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Menu_Integration' ) ) {
/**
* Define Jet_Menu_Integration class
*/
class Jet_Menu_Integration {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Initalize integration hooks
*
* @return void
*/
public function init() {
add_action( 'elementor/init', array( $this, 'register_category' ) );
add_action( 'elementor/widgets/widgets_registered', array( $this, 'register_addons' ), 10 );
add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'editor_styles' ) );
}
/**
* Enqueue editor styles
*
* @return void
*/
public function editor_styles() {
wp_enqueue_style(
'jet-menu-font',
jet_menu()->plugin_url( 'assets/public/lib/jetmenu-font/css/jetmenu.css' ),
array(),
jet_menu()->get_version()
);
}
/**
* Register plugin addons
*
* @param object $widgets_manager Elementor widgets manager instance.
* @return void
*/
public function register_addons( $widgets_manager ) {
foreach ( glob( jet_menu()->plugin_path( 'includes/widgets/' ) . '*.php' ) as $file ) {
$this->register_addon( $file, $widgets_manager );
}
}
/**
* Register addon by file name
*
* @param string $file File name.
* @param object $widgets_manager Widgets manager instance.
* @return void
*/
public function register_addon( $file, $widgets_manager ) {
$base = basename( str_replace( '.php', '', $file ) );
$class = ucwords( str_replace( '-', ' ', $base ) );
$class = str_replace( ' ', '_', $class );
$class = sprintf( 'Elementor\%s', $class );
require $file;
if ( class_exists( $class ) ) {
$widgets_manager->register_widget_type( new $class );
}
}
/**
* Register cherry category for elementor if not exists
*
* @return void
*/
public function register_category() {
$elements_manager = Elementor\Plugin::instance()->elements_manager;
$existing = $elements_manager->get_categories();
$cherry_cat = 'cherry';
if ( array_key_exists( $cherry_cat, $existing ) ) {
return;
}
$elements_manager->add_category(
$cherry_cat,
array(
'title' => esc_html__( 'JetElements', 'jet-menu' ),
'icon' => 'font',
),
1
);
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance( $shortcodes = array() ) {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self( $shortcodes );
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Menu_Integration
*
* @return object
*/
function jet_menu_integration() {
return Jet_Menu_Integration::get_instance();
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,454 @@
<?php
/**
* Option page Class
*/
// If class `Popups_Options_Page` doesn't exists yet.
if ( ! class_exists( 'Jet_Menu_Options_Presets' ) ) {
/**
* Jet_Menu_Options_Presets class.
*/
class Jet_Menu_Options_Presets {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Post type name.
*
* @var string
*/
public $post_type = 'jet_options_preset';
public $settings_key = 'jet_preset_settings';
public $title_key = 'jet_preset_name';
/**
* Preset list
*
* @var null
*/
public $presets = null;
/**
* Attach hooks
*/
public function init() {
add_action( 'init', array( $this, 'register_post_type' ) );
add_filter( 'jet-menu/options-page/tabs', array( $this, 'register_presets_tab' ) );
add_filter( 'jet-menu/assets/admin/localize', array( $this, 'localize_presets_msg' ) );
add_filter( 'jet-menu/nav-settings/registered', array( $this, 'add_menu_settings' ) );
add_action( 'jet-menu/options-page/before-render', array( $this, 'register_presets_settings' ), 10, 2 );
add_action( 'jet-menu/widgets/mega-menu/controls', array( $this, 'add_widget_settings' ) );
add_action( 'wp_ajax_jet_menu_create_preset', array( $this, 'create_preset' ) );
add_action( 'wp_ajax_jet_menu_update_preset', array( $this, 'update_preset' ) );
add_action( 'wp_ajax_jet_menu_load_preset', array( $this, 'load_preset' ) );
add_action( 'wp_ajax_jet_menu_delete_preset', array( $this, 'delete_preset' ) );
}
/**
* Add widget settings
*
* @param object $widget Widget instance.
*/
public function add_widget_settings( $widget ) {
$presets = $this->get_presets();
if ( empty( $presets ) ) {
return;
}
$presets = array( '0' => esc_html__( 'Not Selected', 'jet-menu' ) ) + $presets;
$widget->add_control(
'preset',
array(
'label' => esc_html__( 'Menu Preset', 'jet-menu' ),
'type' => Elementor\Controls_Manager::SELECT,
'default' => '',
'options' => $presets,
)
);
}
/**
* Register post type
*
* @return void
*/
public function register_post_type() {
register_post_type( $this->post_type, array(
'public' => false,
'has_archive' => false,
'rewrite' => false,
'can_export' => true,
) );
}
/**
* Create preset callback.
*
* @return void
*/
public function create_preset() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array(
'message' => esc_html__( 'You are not allowed to do this', 'jet-menu' ),
) );
}
$name = isset( $_POST['name'] ) ? esc_attr( $_POST['name'] ) : false;
$settings = isset( $_POST['settings'] ) ? $_POST['settings'] : false;
if ( ! $settings ) {
wp_send_json_error( array(
'message' => esc_html__( 'Settings not provided', 'jet-menu' ),
) );
}
if ( ! $name ) {
wp_send_json_error( array(
'message' => esc_html__( 'Please, specify preset name', 'jet-menu' ),
) );
}
$post_title = 'jet_preset_' . md5( $name );
if ( post_exists( $post_title ) ) {
wp_send_json_error( array(
'message' => esc_html__( 'Preset with the same name already exists, please change it', 'jet-menu' ),
) );
}
$preset_id = wp_insert_post( array(
'post_type' => $this->post_type,
'post_status' => 'publish',
'post_title' => $post_title,
'meta_input' => array(
$this->title_key => esc_attr( $name ),
$this->settings_key => $settings,
),
) );
do_action( 'jet-menu/presets/created' );
wp_send_json_success( array(
'preset' => array(
'id' => $preset_id,
'name' => esc_attr( $name ),
),
) );
}
/**
* Update preset callback.
*
* @return void
*/
public function update_preset() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array(
'message' => esc_html__( 'You are not allowed to do this', 'jet-menu' ),
) );
}
$preset = isset( $_POST['preset'] ) ? absint( $_POST['preset'] ) : false;
$settings = isset( $_POST['settings'] ) ? $_POST['settings'] : false;
if ( ! $preset ) {
wp_send_json_error( array(
'message' => esc_html__( 'Preset ID not defined', 'jet-menu' ),
) );
}
update_post_meta( $preset, $this->settings_key, $settings );
do_action( 'jet-menu/presets/updated' );
wp_send_json_success( array() );
}
/**
* Load preset callback.
*
* @return void
*/
public function load_preset() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array(
'message' => esc_html__( 'You are not allowed to do this', 'jet-menu' ),
) );
}
$preset = isset( $_POST['preset'] ) ? absint( $_POST['preset'] ) : false;
if ( ! $preset ) {
wp_send_json_error( array(
'message' => esc_html__( 'Preset ID not defined', 'jet-menu' ),
) );
}
$preset_settings = get_post_meta( $preset, $this->settings_key, true );
update_option( jet_menu_option_page()->options_slug(), $preset_settings );
do_action( 'jet-menu/presets/loaded' );
wp_send_json_success( array() );
}
/**
* Delete preset callback
*
* @return void
*/
public function delete_preset() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array(
'message' => esc_html__( 'You are not allowed to do this', 'jet-menu' ),
) );
}
$preset = isset( $_POST['preset'] ) ? absint( $_POST['preset'] ) : false;
if ( ! $preset ) {
wp_send_json_error( array(
'message' => esc_html__( 'Preset ID not defined', 'jet-menu' ),
) );
}
wp_delete_post( $preset, true );
do_action( 'jet-menu/presets/deleted' );
wp_send_json_success( array() );
}
/**
* Register prests tab.
*
* @param array $tabs Existing tabs.
* @return array
*/
public function register_presets_tab( $tabs ) {
$tabs['presets_tab'] = array(
'parent' => 'tab_vertical',
'title' => esc_html__( 'Presets Manager', 'jet-menu' ),
);
return $tabs;
}
/**
* Localized presets managers
*
* @return array
*/
public function localize_presets_msg( $data ) {
$strings = array();
$strings['preset'] = array(
'nameError' => esc_html__( 'Please, specify preset name', 'jet-menu' ),
'loadError' => esc_html__( 'Please, select preset to load', 'jet-menu' ),
'updateError' => esc_html__( 'Please, select preset to update', 'jet-menu' ),
'deleteError' => esc_html__( 'Please, select preset to delete', 'jet-menu' ),
'created' => esc_html__( 'New preset was created. Page will be reloaded', 'jet-menu' ),
'updated' => esc_html__( 'Preset updated', 'jet-menu' ),
'loaded' => esc_html__( 'Preset loaded. Page will be reloaded to apply changes', 'jet-menu' ),
'deleted' => esc_html__( 'Preset deleted. Page will be reloaded to apply changes', 'jet-menu' ),
'confirmUpdate' => esc_html__( 'Are you sure you want to rewrite existig preset?', 'jet-menu' ),
'confirmDelete' => esc_html__( 'Are you sure you want to delete this preset?', 'jet-menu' ),
'confirmLoad' => esc_html__( 'Are you sure you want to load this preset? All unsaved options will be lost.', 'jet-menu' ),
);
$data['optionPageMessages'] = array_merge( $data['optionPageMessages'], $strings );
$data['menuPageUrl'] = add_query_arg(
array( 'page' => jet_menu()->plugin_slug ),
esc_url( admin_url( 'admin.php' ) )
);
return $data;
}
/**
* Register presets settings
*
* @param object $builder Builder instance.
* @param object $options_page Options page instance.
* @return void
*/
public function register_presets_settings( $builder, $options_page ) {
ob_start();
include jet_menu()->get_template( 'admin/presets-controls.php' );
$controls = ob_get_clean();
$builder->register_control(
array(
'jet-presets-controls' => array(
'type' => 'html',
'parent' => 'presets_tab',
'class' => 'jet-menu-presets',
'html' => $controls,
),
)
);
}
/**
* Add menu settings.
*
* @param array $settings Settings array.
*/
public function add_menu_settings( $settings ) {
$presets = $this->get_presets();
if ( empty( $presets ) ) {
return $settings;
}
$presets = array( '0' => esc_html__( 'Not Selected', 'jet-menu' ) ) + $presets;
$settings['preset'] = array(
'type' => 'select',
'id' => 'jet-preset',
'name' => 'preset',
'value' => '',
'options' => $presets,
'label' => esc_html__( 'Select menu preset', 'jet-menu' ),
);
return $settings;
}
/**
* Get presets list
*
* @return array
*/
public function get_presets() {
if ( null !== $this->presets ) {
return $this->presets;
}
$presets = get_posts( array(
'post_type' => $this->post_type,
'post_status' => 'publish',
'posts_per_page' => -1,
) );
if ( empty( $presets ) ) {
$this->presets = array();
return $this->presets;
}
$result = array();
foreach ( $presets as $preset ) {
$result[ $preset->ID ] = get_post_meta( $preset->ID, $this->title_key, true );
}
$this->presets = $result;
return $this->presets;
}
/**
* Presets select HTML for manager options
*
* @param string $slug Slug for JS processing.
* @param string $placeholder Placeholder.
* @return void
*/
public function preset_select( $slug = 'jet-load-preset', $placeholder = '' ) {
$presets = $this->get_presets();
echo '<select class="cherry-ui-select ' . $slug . '">';
echo '<option value="" selected disabled>' . $placeholder . '</option>';
foreach ( $presets as $key => $name ) {
printf( '<option value="%1$s">%2$s</option>', $key, $name );
}
echo '</select>';
}
/**
* Preset action button
*
* @param string $action Button ID.
* @param string $label Button label.
* @return void
*/
public function preset_action( $action = '', $label = '' ) {
echo '<button type="button" class="cherry5-ui-button cherry5-ui-button-normal-style ui-button" id="' . $action . '">';
echo '<span class="text">' . $label . '</span>';
echo '<span class="loader-wrapper"><span class="loader"></span></span>';
echo '<span class="dashicons dashicons-yes icon"></span>';
echo '</button>';
echo '<div class="jet-preset-msg"></div>';
}
/**
* Returns the instance.
*
* @since 1.0.0
* @access public
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
if ( ! function_exists( 'jet_menu_options_presets' ) ) {
/**
* Returns instanse of the plugin class.
*
* @since 1.0.0
* @return object
*/
function jet_menu_options_presets() {
return Jet_Menu_Options_Presets::get_instance();
}
}

View File

@@ -0,0 +1,249 @@
<?php
/**
* Class description
*
* @package package_name
* @author Cherry Team
* @license GPL-2.0+
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Menu_Post_Type' ) ) {
/**
* Define Jet_Menu_Post_Type class
*/
class Jet_Menu_Post_Type {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
protected $post_type = 'jet-menu';
protected $meta_key = 'jet-menu-item';
/**
* Constructor for the class
*/
public function init() {
$this->register_post_type();
$this->edit_redirect();
add_filter( 'option_elementor_cpt_support', array( $this, 'set_option_support' ) );
add_filter( 'default_option_elementor_cpt_support', array( $this, 'set_option_support' ) );
add_filter( 'jet-menu/assets/admin/localize', array( $this, 'localize_edit_url' ) );
add_action( 'template_include', array( $this, 'set_post_type_template' ), 9999 );
}
/**
* Returns post type slug
*
* @return string
*/
public function slug() {
return $this->post_type;
}
/**
* Returns Mega Menu meta key
*
* @return string
*/
public function meta_key() {
return $this->meta_key;
}
/**
* Add elementor support for mega menu items.
*/
public function set_option_support( $value ) {
if ( empty( $value ) ) {
$value = array();
}
return array_merge( $value, array( $this->slug() ) );
}
/**
* Add edit URL to JS settings
*
* @param array $settings Default settings.
* @return aray
*/
public function localize_edit_url( $settings ) {
$settings['editURL'] = add_query_arg(
array(
'jet-open-editor' => 1,
'item' => '%id%',
'menu' => '%menuid%',
),
esc_url( admin_url( '/' ) )
);
return $settings;
}
/**
* Register post type
*
* @return void
*/
public function register_post_type() {
$labels = array(
'name' => esc_html__( 'Mega Menu Items', 'jet-menu' ),
'singular_name' => esc_html__( 'Mega Menu Item', 'jet-menu' ),
'add_new' => esc_html__( 'Add New Mega Menu Item', 'jet-menu' ),
'add_new_item' => esc_html__( 'Add New Mega Menu Item', 'jet-menu' ),
'edit_item' => esc_html__( 'Edit Mega Menu Item', 'jet-menu' ),
'menu_name' => esc_html__( 'Mega Menu Items', 'jet-menu' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'description' => 'description',
'taxonomies' => array(),
'public' => true,
'show_ui' => true,
'show_in_menu' => false,
'show_in_admin_bar' => true,
'menu_position' => null,
'menu_icon' => null,
'show_in_nav_menus' => false,
'publicly_queryable' => true,
'exclude_from_search' => true,
'has_archive' => false,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post',
'supports' => array( 'title', 'editor' ),
);
register_post_type( $this->slug(), $args );
}
/**
* Edit redirect
*
* @return void
*/
public function edit_redirect() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
if ( empty( $_REQUEST['jet-open-editor'] ) ) {
return;
}
if ( empty( $_REQUEST['item'] ) ) {
return;
}
if ( empty( $_REQUEST['menu'] ) ) {
return;
}
$menu_id = intval( $_REQUEST['menu'] );
$menu_item_id = intval( $_REQUEST['item'] );
$mega_menu_id = get_post_meta( $menu_item_id, $this->meta_key(), true );
if ( ! $mega_menu_id ) {
$mega_menu_id = wp_insert_post( array(
'post_title' => 'mega-item-' . $menu_item_id,
'post_status' => 'publish',
'post_type' => $this->slug(),
) );
update_post_meta( $menu_item_id, $this->meta_key(), $mega_menu_id );
}
$edit_link = add_query_arg(
array(
'post' => $mega_menu_id,
'action' => 'elementor',
'context' => 'jet-menu',
'parent_menu' => $menu_id,
),
admin_url( 'post.php' )
);
wp_redirect( $edit_link );
die();
}
/**
* Returns related mega menu post
*
* @param int $menu_id Menu ID
* @return [type] [description]
*/
public function get_related_menu_post( $menu_id ) {
return get_post_meta( $menu_id, $this->meta_key(), true );
}
/**
* Set blank template for editor
*/
public function set_post_type_template( $template ) {
$found = false;
if ( is_singular( $this->slug() ) ) {
$found = true;
$template = jet_menu()->plugin_path( 'templates/blank.php' );
}
if ( $found ) {
do_action( 'jet-menu/template-include/found' );
}
return $template;
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Menu_Post_Type
*
* @return object
*/
function jet_menu_post_type() {
return Jet_Menu_Post_Type::get_instance();
}

View File

@@ -0,0 +1,860 @@
<?php
/**
* Class description
*
* @package package_name
* @author Cherry Team
* @license GPL-2.0+
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Menu_Public_Manager' ) ) {
/**
* Define Jet_Menu_Public_Manager class
*/
class Jet_Menu_Public_Manager {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Constructor for the class
*/
public function init() {
add_filter( 'wp_nav_menu_args', array( $this, 'set_menu_args' ), 99999 );
add_filter( 'walker_nav_menu_start_el', array( $this, 'fix_double_desc' ), 0, 4 );
add_action( 'jet-menu/blank-page/after-content', array( $this, 'set_menu_canvas_bg' ) );
}
/**
* Add background from options from menu canvas
*/
public function set_menu_canvas_bg() {
jet_menu_dynmic_css()->add_single_bg_styles( 'jet-menu-sub-panel-mega', 'body' );
}
/**
* Fix double decription bug.
*
* @param string $item_output The menu item output.
* @param WP_Post $item Menu item object.
* @param int $depth Depth of the menu.
* @param array $args wp_nav_menu() arguments.
* @return string
*/
public function fix_double_desc( $item_output, $item, $depth, $args ) {
$item->description = '';
return $item_output;
}
/**
* Set mega menu arguments
*
* @param [type] $args [description]
*/
public function set_menu_args( $args ) {
if ( ! isset( $args['theme_location'] ) ) {
return $args;
}
$location = $args['theme_location'];
$menu_id = $this->get_menu_id( $location );
if ( false === $menu_id ) {
return $args;
}
$settings = jet_menu_settings_nav()->get_settings( $menu_id );
$settings = apply_filters( 'jet-menu/public-manager/menu-settings', $settings );
$location = apply_filters( 'jet-menu/public-manager/menu-location', $location );
if ( ! isset( $settings[ $location ] ) ) {
return $args;
}
if ( ! isset( $settings[ $location ]['enabled'] ) || 'true' !== $settings[ $location ]['enabled'] ) {
return $args;
}
$preset = isset( $settings[ $location ]['preset'] ) ? absint( $settings[ $location ]['preset'] ) : 0;
if ( 0 !== $preset ) {
$preset_options = get_post_meta( $preset, jet_menu_options_presets()->settings_key, true );
jet_menu_option_page()->pre_set_options( $preset_options );
} else {
jet_menu_option_page()->pre_set_options( false );
}
$args = array_merge( $args, $this->get_mega_nav_args( $preset ) );
return $args;
}
/**
* Returns array ow Mega Mneu attributes for wp_nav_menu() function.
*
* @return array
*/
public function get_mega_nav_args( $preset = 0 ) {
global $is_iphone;
// Get animation type for mega menu instance
$animation_type = jet_menu_option_page()->get_option( 'jet-menu-animation', 'fade' );
$raw_attributes = apply_filters( 'jet-menu/set-menu-args/', array(
'class' => array(
'jet-menu',
( ! empty( $preset ) ? 'jet-preset-' . $preset : '' ),
'jet-menu--animation-type-' . $animation_type,
$is_iphone ? 'jet-menu--iphone-mode' : '',
),
) );
$attributes = '';
foreach ( $raw_attributes as $name => $value ) {
if ( is_array( $value ) ) {
$value = implode( ' ', $value );
}
$attributes .= sprintf( ' %1$s="%2$s"', esc_attr( $name ), esc_attr( $value ) );
}
$roll_up = jet_menu_option_page()->get_option( 'jet-menu-roll-up', 'false' );
$args = array(
'menu_class' => '',
'items_wrap' => '<div class="jet-menu-container"><div class="jet-menu-inner"><ul' . $attributes . '>%3$s</ul></div></div>',
'before' => '',
'after' => '',
'walker' => new Jet_Menu_Main_Walker(),
'roll_up' => filter_var( $roll_up, FILTER_VALIDATE_BOOLEAN ),
);
$this->add_dynamic_styles( $preset );
return $args;
}
/**
* Add menu dynamic styles
*/
public function add_dynamic_styles( $preset = 0 ) {
if ( jet_menu_css_file()->is_enqueued( $preset ) ) {
return;
} else {
jet_menu_css_file()->add_preset_to_save( $preset );
}
$preset_class = ( 0 !== $preset ) ? '.jet-preset-' . $preset : '';
$wrapper = sprintf( '.jet-menu%1$s', $preset_class );
jet_menu_dynmic_css()->add_fonts_styles( $wrapper );
jet_menu_dynmic_css()->add_backgrounds( $wrapper );
jet_menu_dynmic_css()->add_borders( $wrapper );
jet_menu_dynmic_css()->add_shadows( $wrapper );
jet_menu_dynmic_css()->add_positions( $wrapper );
$css_scheme = apply_filters( 'jet-menu/menu-css/scheme', array(
'jet-menu-container-alignment' => array(
'selector' => '',
'rule' => 'justify-content',
'value' => '%1$s',
'important' => true,
),
'jet-menu-mega-padding' => array(
'selector' => '',
'rule' => 'padding-%s',
'value' => '',
'important' => true,
),
'jet-menu-min-width' => array(
'selector' => '',
'rule' => 'min-width',
'value' => '%1$spx',
'important' => false,
'desktop' => true,
),
'jet-menu-mega-border-radius' => array(
'selector' => '',
'rule' => 'border-%s-radius',
'value' => '',
'important' => true,
),
'jet-menu-item-text-color' => array(
'selector' => '.jet-menu-item .top-level-link',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-item-desc-color' => array(
'selector' => '.jet-menu-item .jet-menu-item-desc.top-level-desc',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-item-padding' => array(
'selector' => '.jet-menu-item .top-level-link',
'rule' => 'padding-%s',
'value' => '',
'important' => false,
),
'jet-menu-item-margin' => array(
'selector' => '.jet-menu-item .top-level-link',
'rule' => 'margin-%s',
'value' => '',
'important' => false,
),
'jet-menu-item-border-radius' => array(
'selector' => '.jet-menu-item .top-level-link',
'rule' => 'border-%s-radius',
'value' => '',
'important' => false,
),
'jet-menu-top-badge-text-color' => array(
'selector' => '.jet-menu-item .top-level-link .jet-menu-badge__inner',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-top-badge-padding' => array(
'selector' => '.jet-menu-item .top-level-link .jet-menu-badge__inner',
'rule' => 'padding-%s',
'value' => '',
'important' => false,
),
'jet-menu-top-badge-margin' => array(
'selector' => '.jet-menu-item .top-level-link .jet-menu-badge',
'rule' => 'margin-%s',
'value' => '',
'important' => false,
),
'jet-menu-top-badge-border-radius' => array(
'selector' => '.jet-menu-item .top-level-link .jet-menu-badge__inner',
'rule' => 'border-%s-radius',
'value' => '',
'important' => false,
),
'jet-menu-sub-badge-text-color' => array(
'selector' => '.jet-menu-item .sub-level-link .jet-menu-badge__inner',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-sub-badge-padding' => array(
'selector' => '.jet-menu-item .sub-level-link .jet-menu-badge__inner',
'rule' => 'padding-%s',
'value' => '',
'important' => false,
),
'jet-menu-sub-badge-margin' => array(
'selector' => '.jet-menu-item .sub-level-link .jet-menu-badge__inner',
'rule' => 'margin-%s',
'value' => '',
'important' => false,
),
'jet-menu-sub-badge-border-radius' => array(
'selector' => '.jet-menu-item .sub-level-link .jet-menu-badge__inner',
'rule' => 'border-%s-radius',
'value' => '',
'important' => false,
),
'jet-menu-item-text-color-hover' => array(
'selector' => '.jet-menu-item:hover > .top-level-link',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-item-desc-color-hover' => array(
'selector' => '.jet-menu-item:hover > .top-level-link .jet-menu-item-desc.top-level-desc',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-item-padding-hover' => array(
'selector' => '.jet-menu-item:hover > .top-level-link',
'rule' => 'padding-%s',
'value' => '',
'important' => false,
),
'jet-menu-item-margin-hover' => array(
'selector' => '.jet-menu-item:hover > .top-level-link',
'rule' => 'margin-%s',
'value' => '',
'important' => false,
),
'jet-menu-item-border-radius-hover' => array(
'selector' => '.jet-menu-item:hover > .top-level-link',
'rule' => 'border-%s-radius',
'value' => '',
'important' => false,
),
'jet-menu-item-text-color-active' => array(
'selector' => '.jet-menu-item.jet-current-menu-item .top-level-link',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-item-desc-color-active' => array(
'selector' => '.jet-menu-item.jet-current-menu-item .jet-menu-item-desc.top-level-desc',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-item-padding-active' => array(
'selector' => '.jet-menu-item.jet-current-menu-item .top-level-link',
'rule' => 'padding-%s',
'value' => '',
'important' => false,
),
'jet-menu-item-margin-active' => array(
'selector' => '.jet-menu-item.jet-current-menu-item .top-level-link',
'rule' => 'margin-%s',
'value' => '',
'important' => false,
),
'jet-menu-item-border-radius-active' => array(
'selector' => '.jet-menu-item.jet-current-menu-item .top-level-link',
'rule' => 'border-%s-radius',
'value' => '',
'important' => false,
),
'jet-menu-sub-panel-width-simple' => array(
'selector' => 'ul.jet-sub-menu',
'rule' => 'min-width',
'value' => '%1$spx',
'important' => false,
),
'jet-menu-sub-panel-padding-simple' => array(
'selector' => 'ul.jet-sub-menu',
'rule' => 'padding-%s',
'value' => '',
'important' => false,
),
'jet-menu-sub-panel-margin-simple' => array(
'selector' => 'ul.jet-sub-menu',
'rule' => 'margin-%s',
'value' => '',
'important' => false,
),
'jet-menu-sub-panel-border-radius-simple' => array(
'selector' => 'ul.jet-sub-menu',
'rule' => 'border-%s-radius',
'value' => '',
'important' => false,
),
'jet-menu-sub-panel-padding-mega' => array(
'selector' => 'div.jet-sub-mega-menu',
'rule' => 'padding-%s',
'value' => '',
'important' => false,
),
'jet-menu-sub-panel-margin-mega' => array(
'selector' => 'div.jet-sub-mega-menu',
'rule' => 'margin-%s',
'value' => '',
'important' => false,
),
'jet-menu-sub-panel-border-radius-mega' => array(
'selector' => 'div.jet-sub-mega-menu',
'rule' => 'border-%s-radius',
'value' => '',
'important' => false,
),
'jet-menu-sub-text-color' => array(
'selector' => 'li.jet-sub-menu-item .sub-level-link',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-sub-desc-color' => array(
'selector' => '.jet-menu-item-desc.sub-level-desc',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-sub-padding' => array(
'selector' => 'li.jet-sub-menu-item .sub-level-link',
'rule' => 'padding-%s',
'value' => '',
'important' => false,
),
'jet-menu-sub-margin' => array(
'selector' => 'li.jet-sub-menu-item .sub-level-link',
'rule' => 'margin-%s',
'value' => '',
'important' => false,
),
'jet-menu-sub-border-radius' => array(
'selector' => 'li.jet-sub-menu-item .sub-level-link',
'rule' => 'border-%s-radius',
'value' => '',
'important' => false,
),
'jet-menu-sub-text-color-hover' => array(
'selector' => 'li.jet-sub-menu-item:hover > .sub-level-link',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-sub-desc-color-hover' => array(
'selector' => 'li.jet-sub-menu-item:hover > .sub-level-link .jet-menu-item-desc.sub-level-desc',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-sub-padding-hover' => array(
'selector' => 'li.jet-sub-menu-item:hover > .sub-level-link',
'rule' => 'padding-%s',
'value' => '',
'important' => false,
),
'jet-menu-sub-margin-hover' => array(
'selector' => 'li.jet-sub-menu-item:hover > .sub-level-link',
'rule' => 'margin-%s',
'value' => '',
'important' => false,
),
'jet-menu-sub-border-radius-hover' => array(
'selector' => 'li.jet-sub-menu-item:hover > .sub-level-link',
'rule' => 'border-%s-radius',
'value' => '',
'important' => false,
),
'jet-menu-sub-text-color-active' => array(
'selector' => 'li.jet-sub-menu-item.jet-current-menu-item .sub-level-link',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-sub-desc-color-active' => array(
'selector' => 'li.jet-sub-menu-item.jet-current-menu-item .jet-menu-item-desc.sub-level-desc',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-sub-padding-active' => array(
'selector' => 'li.jet-sub-menu-item.jet-current-menu-item .sub-level-link',
'rule' => 'padding-%s',
'value' => '',
'important' => false,
),
'jet-menu-sub-margin-active' => array(
'selector' => 'li.jet-sub-menu-item.jet-current-menu-item .sub-level-link',
'rule' => 'margin-%s',
'value' => '',
'important' => false,
),
'jet-menu-sub-border-radius-active' => array(
'selector' => 'li.jet-sub-menu-item.jet-current-menu-item .sub-level-link',
'rule' => 'border-%s-radius',
'value' => '',
'important' => false,
),
'jet-menu-top-icon-color' => array(
'selector' => '.jet-menu-item .top-level-link .jet-menu-icon',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-top-icon-color-hover' => array(
'selector' => '.jet-menu-item:hover > .top-level-link .jet-menu-icon',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-top-icon-color-active' => array(
'selector' => '.jet-menu-item.jet-current-menu-item .top-level-link .jet-menu-icon',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-sub-icon-color' => array(
'selector' => '.jet-menu-item .sub-level-link .jet-menu-icon',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-sub-icon-color-hover' => array(
'selector' => '.jet-menu-item:hover > .sub-level-link .jet-menu-icon',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-sub-icon-color-active' => array(
'selector' => 'li.jet-sub-menu-item.jet-current-menu-item .sub-level-link .jet-menu-icon',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-top-arrow-color' => array(
'selector' => '.jet-menu-item .top-level-link .jet-dropdown-arrow',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-top-arrow-color-hover' => array(
'selector' => '.jet-menu-item:hover > .top-level-link .jet-dropdown-arrow',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-top-arrow-color-active' => array(
'selector' => '.jet-menu-item.jet-current-menu-item .top-level-link .jet-dropdown-arrow',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-sub-arrow-color' => array(
'selector' => '.jet-menu-item .sub-level-link .jet-dropdown-arrow',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-sub-arrow-color-hover' => array(
'selector' => '.jet-menu-item:hover > .sub-level-link .jet-dropdown-arrow',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-sub-arrow-color-active' => array(
'selector' => 'li.jet-sub-menu-item.jet-current-menu-item .sub-level-link .jet-dropdown-arrow',
'rule' => 'color',
'value' => '%1$s',
'important' => false,
),
'jet-menu-top-icon-order' => array(
'selector' => '.jet-menu-item .top-level-link .jet-menu-icon',
'rule' => 'order',
'value' => '%1$s',
'important' => false,
),
'jet-menu-sub-icon-order' => array(
'selector' => '.jet-menu-item .sub-level-link .jet-menu-icon',
'rule' => 'order',
'value' => '%1$s',
'important' => false,
),
'jet-menu-top-badge-order' => array(
'selector' => '.jet-menu-item .top-level-link .jet-menu-badge',
'rule' => 'order',
'value' => '%1$s',
'important' => false,
),
'jet-menu-sub-badge-order' => array(
'selector' => '.jet-menu-item .sub-level-link .jet-menu-badge',
'rule' => 'order',
'value' => '%1$s',
'important' => false,
),
'jet-menu-top-arrow-order' => array(
'selector' => '.jet-menu-item .top-level-link .jet-dropdown-arrow',
'rule' => 'order',
'value' => '%1$s',
'important' => false,
),
'jet-menu-sub-arrow-order' => array(
'selector' => '.jet-menu-item .sub-level-link .jet-dropdown-arrow',
'rule' => 'order',
'value' => '%1$s',
'important' => false,
),
'jet-menu-top-icon-size' => array(
'selector' => '.jet-menu-item .top-level-link .jet-menu-icon',
'rule' => 'font-size',
'value' => '%spx',
'important' => false,
),
'jet-menu-top-icon-margin' => array(
'selector' => '.jet-menu-item .top-level-link .jet-menu-icon',
'rule' => 'margin-%s',
'value' => '',
'important' => false,
),
'jet-menu-sub-icon-size' => array(
'selector' => '.jet-menu-item .sub-level-link .jet-menu-icon',
'rule' => 'font-size',
'value' => '%spx',
'important' => false,
),
'jet-menu-sub-icon-margin' => array(
'selector' => '.jet-menu-item .sub-level-link .jet-menu-icon',
'rule' => 'margin-%s',
'value' => '',
'important' => false,
),
'jet-menu-top-arrow-size' => array(
'selector' => '.jet-menu-item .top-level-link .jet-dropdown-arrow',
'rule' => 'font-size',
'value' => '%spx',
'important' => false,
),
'jet-menu-top-arrow-margin' => array(
'selector' => '.jet-menu-item .top-level-link .jet-dropdown-arrow',
'rule' => 'margin-%s',
'value' => '',
'important' => false,
),
'jet-menu-sub-arrow-size' => array(
'selector' => '.jet-menu-item .sub-level-link .jet-dropdown-arrow',
'rule' => 'font-size',
'value' => '%spx',
'important' => false,
),
'jet-menu-sub-arrow-margin' => array(
'selector' => '.jet-menu-item .sub-level-link .jet-dropdown-arrow',
'rule' => 'margin-%s',
'value' => '',
'important' => false,
),
'jet-menu-mobile-toggle-color' => array(
'selector' => '.jet-menu-container .jet-mobile-menu-toggle-button',
'rule' => 'color',
'value' => '%s',
'important' => false,
'mobile' => true,
),
'jet-menu-mobile-toggle-bg' => array(
'selector' => '.jet-menu-container .jet-mobile-menu-toggle-button',
'rule' => 'background-color',
'value' => '%s',
'important' => false,
'mobile' => true,
),
'jet-menu-mobile-container-bg' => array(
'selector' => '.jet-menu-container .jet-menu-inner',
'rule' => 'background-color',
'value' => '%s',
'important' => false,
'mobile' => true,
),
'jet-menu-mobile-cover-bg' => array(
'selector' => '.jet-mobile-menu-cover',
'rule' => 'background-color',
'value' => '%s',
'important' => false,
'mobile' => true,
),
) );
foreach ( $css_scheme as $setting => $data ) {
$value = jet_menu_option_page()->get_option( $setting );
if ( empty( $value ) ) {
continue;
}
$_wrapper = $wrapper;
if ( isset( $data['mobile'] ) && true === $data['mobile'] ) {
$_wrapper = '.jet-mobile-menu-active';
}
if ( isset( $data['desktop'] ) && true === $data['desktop'] ) {
$_wrapper = '.jet-desktop-menu-active ' . $_wrapper;
}
if ( is_array( $value ) && isset( $value['units'] ) ) {
jet_menu_dynmic_css()->add_dimensions_css(
array(
'selector' => sprintf( '%1$s %2$s', $_wrapper, $data['selector'] ),
'rule' => $data['rule'],
'values' => $value,
'important' => $data['important'],
)
);
continue;
}
$important = ( true === $data['important'] ) ? ' !important' : '';
jet_menu()->dynamic_css()->add_style(
sprintf( '%1$s %2$s', $_wrapper, $data['selector'] ),
array(
$data['rule'] => sprintf( $data['value'], esc_attr( $value ) ) . $important,
)
);
}
$items_map = array(
'first' => array(
'top-left' => 'top',
'bottom-left' => 'left',
),
'last' => array(
'top-right' => 'right',
'bottom-right' => 'bottom',
),
);
foreach ( $items_map as $item => $data ) {
$parent_radius = jet_menu_option_page()->get_option( 'jet-menu-mega-border-radius' );
if ( ! $parent_radius ) {
continue;
}
$is_enabled = jet_menu_option_page()->get_option( 'jet-menu-inherit-' . $item . '-radius' );
if ( 'true' !== $is_enabled ) {
continue;
}
$styles = array();
foreach ( $data as $rule => $val ) {
if ( ! $parent_radius ) {
continue;
}
$styles[ 'border-' . $rule . '-radius' ] = $parent_radius[ $val ] . $parent_radius['units'];
}
if ( ! empty( $styles ) ) {
$selector = '%1$s > .jet-menu-item:%2$s-child > .top-level-link';
if ( 'last' === $item ) {
$selectors = array(
'%1$s > .jet-regular-item.jet-has-roll-up:nth-last-child(2) .top-level-link',
'%1$s > .jet-regular-item.jet-no-roll-up:nth-last-child(1) .top-level-link',
'%1$s > .jet-responsive-menu-available-items:last-child .top-level-link',
);
$selector = join( ',', $selectors );
}
jet_menu()->dynamic_css()->add_style(
sprintf( $selector, $wrapper, $item ),
$styles
);
}
}
// extra options
$max_width = jet_menu_option_page()->get_option( 'jet-menu-item-max-width', 0 );
if ( 0 !== absint( $max_width ) ) {
jet_menu()->dynamic_css()->add_style(
sprintf( '.jet-desktop-menu-active %1$s > .jet-menu-item', $wrapper ),
array(
'max-width' => absint( $max_width ) . '%',
)
);
}
jet_menu()->dynamic_css()->add_style(
sprintf( '%1$s .jet-menu-badge', $wrapper ),
array(
'display' => 'block',
)
);
$menu_align = jet_menu_option_page()->get_option( 'jet-menu-container-alignment' );
if ( 'stretch' === $menu_align ) {
jet_menu()->dynamic_css()->add_style(
sprintf( '.jet-desktop-menu-active %1$s > .jet-menu-item', $wrapper ),
array(
'flex-grow' => 1,
)
);
jet_menu()->dynamic_css()->add_style(
sprintf( '.jet-desktop-menu-active %1$s > .jet-menu-item > a', $wrapper ),
array(
'justify-content' => 'center',
)
);
}
}
/**
* Get menu ID for current location
*
* @param [type] $location [description]
* @return [type] [description]
*/
public function get_menu_id( $location = null ) {
$locations = get_nav_menu_locations();
return isset( $locations[ $location ] ) ? $locations[ $location ] : false;
}
/**
* Save in object chache trigger that defines we output menu in Elementor
*
* @return void
*/
public function set_elementor_mode() {
wp_cache_set( 'jet-menu-in-elementor', true );
}
/**
* Reset trigger that defines we output menu in Elementor
*
* @return void
*/
public function reset_elementor_mode() {
wp_cache_delete( 'jet-menu-in-elementor' );
}
/**
* Check if current menu inside Elementor
*
* @return boolean
*/
public function is_elementor_mode() {
return wp_cache_get( 'jet-menu-in-elementor' );
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Menu_Public_Manager
*
* @return object
*/
function jet_menu_public_manager() {
return Jet_Menu_Public_Manager::get_instance();
}

View File

@@ -0,0 +1,587 @@
<?php
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Menu_Settings_Item' ) ) {
/**
* Define Jet_Menu_Settings_Item class
*/
class Jet_Menu_Settings_Item {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Templates stack
*
* @var array
*/
protected $templates = array();
protected $meta_key = 'jet_menu_settings';
/**
* Constructor for the class
*/
public function init() {
foreach ( $this->get_tabs() as $tab ) {
if ( ! empty( $tab['template'] ) && ! empty( $tab['templateFile'] ) ) {
$this->templates[ $tab['template'] ] = $tab['templateFile'];
}
if ( ! empty( $tab['data'] ) ) {
}
if ( empty( $tab['action'] ) || empty( $tab['callback'] ) ) {
continue;
}
if ( ! is_callable( $tab['callback'] ) ) {
continue;
}
add_action( 'wp_ajax_' . $tab['action'], $tab['callback'] );
}
add_action( 'admin_footer', array( $this, 'print_tabs_templates' ) );
add_action( 'wp_ajax_jet_save_menu', array( $this, 'save_menu_settings' ) );
}
/**
* Print tabs templates
*
* @return void
*/
public function print_tabs_templates() {
$screen = get_current_screen();
if ( 'nav-menus' !== $screen->base ) {
return;
}
jet_menu_assets()->print_templates_array( $this->templates );
}
/**
* Returns list of available settings tabs
*
* @return array
*/
public function get_tabs() {
return apply_filters( 'jet-menu/settings/tabs', array(
'content' => array(
'label' => esc_html__( 'Content', 'jet-menu' ),
'template' => false,
'templateFile' => false,
'action' => 'jet_menu_tab_content',
'callback' => array( $this, 'get_tab_content' ),
'data' => array(),
'depthFrom' => 0,
'depthTo' => 1,
),
'settings' => array(
'label' => esc_html__( 'Settings', 'jet-menu' ),
'template' => false,
'templateFile' => false,
'action' => 'jet_menu_tab_settings',
'callback' => array( $this, 'get_tab_settings' ),
'data' => array(),
'depthFrom' => 0,
'depthTo' => 1,
),
'icon' => array(
'label' => esc_html__( 'Icon', 'jet-menu' ),
'template' => false,
'templateFile' => false,
'action' => 'jet_menu_tab_icon',
'callback' => array( $this, 'get_tab_icon' ),
'data' => array(),
'depthFrom' => 0,
'depthTo' => 100,
),
'badges' => array(
'label' => esc_html__( 'Badges', 'jet-menu' ),
'template' => false,
'templateFile' => false,
'action' => 'jet_menu_tab_badges',
'callback' => array( $this, 'get_tab_badges' ),
'data' => array(),
'depthFrom' => 0,
'depthTo' => 100,
),
'misc' => array(
'label' => esc_html__( 'Misc', 'jet-menu' ),
'template' => false,
'templateFile' => false,
'action' => 'jet_menu_tab_misc',
'callback' => array( $this, 'get_tab_misc' ),
'data' => array(),
'depthFrom' => 0,
'depthTo' => 100,
),
'vertical_menu' => array(
'label' => esc_html__( 'Vertical Menu', 'jet-menu' ),
'template' => false,
'templateFile' => false,
'action' => 'jet_menu_tab_vertical_menu',
'callback' => array( $this, 'get_tab_vertical_menu' ),
'data' => array(),
'depthFrom' => 0,
'depthTo' => 1,
),
) );
}
/**
* Get content tab
*
* @return [type] [description]
*/
public function get_tab_content() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array(
'message' => esc_html__( 'You are not allowed to do this', 'jet-menu' ),
) );
}
$menu_id = $this->get_requested_menu_id();
$settings = $this->get_settings( $menu_id );
$builder = jet_menu()->get_core()->init_module( 'cherry-ui-elements', array() );
$template = jet_menu()->get_template( 'admin/tab-content.php' );
$instance = $builder->get_ui_element_instance( 'switcher', array(
'type' => 'switcher',
'id' => 'enabled_' . $menu_id,
'name' => 'enabled',
'value' => isset( $settings['enabled'] ) ? $settings['enabled'] : '',
'toggle' => array(
'true_toggle' => esc_html__( 'Yes', 'jet-menu' ),
'false_toggle' => esc_html__( 'No', 'jet-menu' ),
),
'label' => esc_html__( 'Mega Submenu Enabled', 'jet-menu' ),
) );
$enabled = $instance->render();
ob_start();
include $template;
$content = ob_get_clean();
wp_send_json_success( array(
'content' => $content,
) );
}
/**
* Settings tab icon
*
* @return [type] [description]
*/
public function get_tab_icon() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array(
'message' => esc_html__( 'You are not allowed to do this', 'jet-menu' ),
) );
}
$menu_id = $this->get_requested_menu_id();
$elements = array(
'menu_icon' => array(
'type' => 'iconpicker',
'id' => 'menu_icon',
'name' => 'menu_icon',
'label' => esc_html__( 'Menu icon', 'jet-menu' ),
'auto_parse' => true,
'value' => '',
'icon_data' => array(
'icon_set' => 'jetMenuIcons',
'icon_css' => jet_menu()->plugin_url( 'assets/public/css/font-awesome.min.css' ),
'icon_base' => 'fa',
'icon_prefix' => '',
'icons' => false,
),
),
'icon_color' => array(
'type' => 'colorpicker',
'id' => 'icon_color',
'name' => 'icon_color',
'alpha' => true,
'value' => '',
'label' => esc_html__( 'Icon color', 'jet-menu' ),
),
);
wp_send_json_success( array(
'content' => $this->render_ui_elements( $elements, $menu_id ),
) );
}
/**
* Settings tab badges
*
* @return [type] [description]
*/
public function get_tab_badges() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array(
'message' => esc_html__( 'You are not allowed to do this', 'jet-menu' ),
) );
}
$menu_id = $this->get_requested_menu_id();
$elements = array(
'menu_badge' => array(
'type' => 'text',
'id' => 'menu_badge',
'name' => 'menu_badge',
'label' => esc_html__( 'Menu badge', 'jet-menu' ),
'value' => '',
),
'badge_color' => array(
'type' => 'colorpicker',
'id' => 'badge_color',
'name' => 'badge_color',
'alpha' => true,
'value' => '',
'label' => esc_html__( 'Badge color', 'jet-menu' ),
),
'badge_bg_color' => array(
'type' => 'colorpicker',
'id' => 'badge_bg_color',
'name' => 'badge_bg_color',
'alpha' => true,
'value' => '',
'label' => esc_html__( 'Badge background color', 'jet-menu' ),
),
);
wp_send_json_success( array(
'content' => $this->render_ui_elements( $elements, $menu_id ),
) );
}
/**
* Settings tab misc
*
* @return [type] [description]
*/
public function get_tab_misc() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array(
'message' => esc_html__( 'You are not allowed to do this', 'jet-menu' ),
) );
}
$menu_id = $this->get_requested_menu_id();
$elements = array(
'hide_item_text' => array(
'type' => 'switcher',
'id' => 'hide_item_text',
'name' => 'hide_item_text',
'label' => esc_html__( 'Hide item navigation label', 'jet-menu' ),
'value' => '',
'toggle' => array(
'true_toggle' => 'On',
'false_toggle' => 'Off',
),
),
'item_padding' => array(
'type' => 'dimensions',
'id' => 'item_padding',
'name' => 'item_padding',
'label' => esc_html__( 'Set custom padding for this item', 'jet-menu' ),
'range' => array(
'px' => array(
'min' => 0,
'max' => 100,
'step' => 1,
),
),
'value' => '',
),
);
wp_send_json_success( array(
'content' => $this->render_ui_elements( $elements, $menu_id ),
) );
}
/**
* Settings tab vertical menu
*
* @return [type] [description]
*/
public function get_tab_vertical_menu() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array(
'message' => esc_html__( 'You are not allowed to do this', 'jet-menu' ),
) );
}
$menu_id = $this->get_requested_menu_id();
$elements = array(
'mega_menu_width' => array(
'type' => 'slider',
'id' => 'mega_menu_width',
'name' => 'mega_menu_width',
'value' => '',
'max_value' => 2000,
'min_value' => 200,
'step_value' => 1,
'label' => esc_html__( 'Set custom mega menu width for this item (px)', 'jet-menu' ),
),
'vertical_mega_menu_position' => array(
'type' => 'radio',
'id' => 'vertical_mega_menu_position',
'name' => 'vertical_mega_menu_position',
'value' => 'default',
'options' => array(
'default' => array(
'label' => esc_html__( 'Relative the menu item', 'jet-menu' ),
),
'top' => array(
'label' => esc_html__( 'Relative the menu container', 'jet-menu' ),
),
),
'label' => esc_html__( 'Vertical mega menu position', 'jet-menu' ),
),
);
wp_send_json_success( array(
'content' => $this->render_ui_elements( $elements, $menu_id ),
) );
}
/**
* Settings tab custom settings
*
* @return [type] [description]
*/
public function get_tab_settings() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array(
'message' => esc_html__( 'You are not allowed to do this', 'jet-menu' ),
) );
}
$menu_id = $this->get_requested_menu_id();
$elements = array(
'custom_mega_menu_position' => array(
'type' => 'radio',
'id' => 'custom_mega_menu_position',
'name' => 'custom_mega_menu_position',
'value' => 'default',
'options' => array(
'default' => array(
'label' => esc_html__( 'Default', 'jet-menu' ),
),
'relative-item' => array(
'label' => esc_html__( 'Relative the menu item', 'jet-menu' ),
),
),
'label' => esc_html__( 'Mega menu position', 'jet-menu' ),
),
'custom_mega_menu_width' => array(
'type' => 'slider',
'id' => 'custom_mega_menu_width',
'name' => 'custom_mega_menu_width',
'value' => '',
'max_value' => 2000,
'min_value' => 200,
'step_value' => 1,
'label' => esc_html__( 'Set custom mega menu width for this item (px)', 'jet-menu' ),
),
);
wp_send_json_success( array(
'content' => $this->render_ui_elements( $elements, $menu_id ),
) );
}
/**
* Save menu settings
*
* @return void
*/
public function save_menu_settings() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array(
'message' => esc_html__( 'You are not allowed to do this', 'jet-menu' ),
) );
}
$menu_id = $this->get_requested_menu_id();
$settings = $_POST;
unset( $settings['menu_id'] );
unset( $settings['action'] );
$sanitized_settings = array();
foreach ( $settings as $key => $value ) {
$sanitized_settings[ $key ] = $this->sanitize_field( $key, $value );
}
$old_settings = $this->get_settings( $menu_id );
if ( ! $old_settings ) {
$old_settings = array();
}
$new_settings = array_merge( $old_settings, $sanitized_settings );
$this->set_item_settings( $menu_id, $new_settings );
do_action( 'jet-menu/item-settings/save' );
wp_send_json_success( array(
'message' => esc_html__( 'Success!', 'jet-menu' ),
) );
}
/**
* Sanitize field
*
* @param [type] $key [description]
* @param [type] $value [description]
* @return [type] [description]
*/
public function sanitize_field( $key, $value ) {
$default = 'esc_attr';
$specific_callbacks = apply_filters( 'jet-menu/settings/tabs/sanitize-callbacks', array(
'icon_size' => 'absint',
'menu_badge' => 'wp_kses_post',
'item_padding' => array( $this, 'sanitize_dimensions' ),
) );
$callback = isset( $specific_callbacks[ $key ] ) ? $specific_callbacks[ $key ] : $default;
return call_user_func( $callback, $value );
}
/**
* Sanitize dimensions
*
* @param [type] $value [description]
* @return [type] [description]
*/
public function sanitize_dimensions( $value ) {
return $value;
}
/**
* Get menu ID from request data
*
* @return [type] [description]
*/
public function get_requested_menu_id() {
$menu_id = isset( $_REQUEST['menu_id'] ) ? absint( $_REQUEST['menu_id'] ) : false;
if ( ! $menu_id ) {
wp_send_json_error( array(
'message' => esc_html__( 'Incorrect input data', 'jet-menu' ),
) );
}
return $menu_id;
}
/**
* Render UI eements
*
* @return [type] [description]
*/
public function render_ui_elements( $elements = array(), $menu_id = null ) {
$builder = jet_menu()->get_core()->init_module( 'cherry-ui-elements', array() );
$content = '';
$settings = $this->get_settings( $menu_id );
add_filter( 'cherry_ui_add_data_to_element', '__return_true' );
foreach ( $elements as $key => $field ) {
$field['value'] = isset( $settings[ $key ] ) ? $settings[ $key ] : $field['value'];
$instance = $builder->get_ui_element_instance( $field['type'], $field );
$content .= $instance->render();
}
return $content;
}
/**
* Returns menu item settings
*
* @param [type] $id [description]
* @return [type] [description]
*/
public function get_settings( $id ) {
return get_post_meta( $id, $this->meta_key, true );
}
/**
* Update menu item settings
*
* @param integer $id [description]
* @param array $settings [description]
*/
public function set_item_settings( $id = 0, $settings = array() ) {
update_post_meta( $id, $this->meta_key, $settings );
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Menu_Settings_Item
*
* @return object
*/
function jet_menu_settings_item() {
return Jet_Menu_Settings_Item::get_instance();
}

View File

@@ -0,0 +1,333 @@
<?php
/**
* Class description
*
* @package package_name
* @author Cherry Team
* @license GPL-2.0+
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Menu_Settings_Nav' ) ) {
/**
* Define Jet_Menu_Settings_Nav class
*/
class Jet_Menu_Settings_Nav {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Holder for current menu ID
* @var integer
*/
protected $current_menu_id = null;
/**
* Jet Menu settings page
*
* @var string
*/
protected $meta_key = 'jet_menu_settings';
/**
* Constructor for the class
*/
public function init() {
add_action( 'admin_head-nav-menus.php', array( $this, 'register_nav_meta_box' ), 9 );
add_filter( 'jet-menu/assets/admin/localize', array( $this, 'add_current_menu_id_to_localize' ) );
add_action( 'wp_ajax_jet_save_settings', array( $this, 'save_menu_settings' ) );
add_filter( 'get_user_option_metaboxhidden_nav-menus', array( $this, 'force_metabox_visibile' ), 10 );
}
/**
* Save menu settings
*
* @return void
*/
public function save_menu_settings() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array(
'message' => esc_html__( 'You are not allowed to do this', 'jet-menu' ),
) );
}
$menu_id = isset( $_POST['current_menu'] ) ? absint( $_POST['current_menu'] ) : false;
if ( ! $menu_id ) {
wp_send_json_error( array(
'message' => esc_html__( 'Incorrect input data', 'jet-menu' ),
) );
}
$settings = $_POST;
unset( $settings['current_menu'] );
unset( $settings['action'] );
$old_settings = $this->get_settings( $menu_id );
if ( ! $old_settings ) {
$old_settings = array();
}
$new_settings = array_merge( $old_settings, $settings );
$this->update_settings( $menu_id, $new_settings );
wp_send_json_success( array(
'message' => esc_html__( 'Success!', 'jet-menu' ),
) );
}
/**
* Get settings from DB
*
* @param [type] $menu_id [description]
* @return [type] [description]
*/
public function get_settings( $menu_id ) {
return get_term_meta( $menu_id, $this->meta_key, true );
}
/**
* Update menu item settings
*
* @param integer $id [description]
* @param array $settings [description]
*/
public function update_settings( $menu_id = 0, $settings = array() ) {
update_term_meta( $menu_id, $this->meta_key, $settings );
}
/**
* Register nav menus page metabox with mega menu settings.
*
* @return void
*/
public function register_nav_meta_box() {
global $pagenow;
if ( 'nav-menus.php' !== $pagenow ) {
return;
}
add_meta_box(
'jet-menu-settings',
esc_html__( 'JetMenu Settings', 'jet-menu' ),
array( $this, 'render_metabox' ),
'nav-menus',
'side',
'high'
);
}
/**
* Force nav menu metabox with JetMenu settings to be allways visible.
*
* @param array $result
* @return array
*/
public function force_metabox_visibile( $result ) {
if ( ! is_array( $result ) ) {
return $result;
}
if ( in_array( 'jet-menu-settings', $result ) ) {
$result = array_diff( $result, array( 'jet-menu-settings' ) );
}
return $result;
}
/**
* Add curretn menu ID to localized data
*
* @param array
* @return array
*/
public function add_current_menu_id_to_localize( $data ) {
$data['currentMenuId'] = $this->get_selected_menu_id();
return $data;
}
/**
* Render nav menus metabox
*
* @return void
*/
public function render_metabox() {
$menu_id = $this->get_selected_menu_id();
$tagged_menu_locations = $this->get_tagged_theme_locations_for_menu_id( $menu_id );
$theme_locations = get_registered_nav_menus();
$saved_settings = $this->get_settings( $menu_id );
if ( ! count( $theme_locations ) ) {
$this->no_locations_message();
} else if ( ! count ( $tagged_menu_locations ) ) {
$this->empty_location_message();
} else {
$wrapper = jet_menu()->get_template( 'admin/settings-nav.php' );
$settings_list = jet_menu()->get_template( 'admin/settings-nav-list.php' );
$settings_stack = $this->get_registered_nav_settings();
include $wrapper;
}
}
/**
* Returns list of registered navigation settings
*
* @return [type] [description]
*/
public function get_registered_nav_settings() {
return apply_filters( 'jet-menu/nav-settings/registered', array(
'enabled' => array(
'type' => 'switcher',
'id' => 'jet-enabled',
'name' => 'enabled',
'value' => '',
'style' => 'small',
'toggle' => array(
'true_toggle' => esc_html__( 'Yes', 'jet-menu' ),
'false_toggle' => esc_html__( 'No', 'jet-menu' ),
),
'label' => esc_html__( 'Enable JetMenu for current location', 'jet-menu' ),
),
) );
}
/**
* Notice if no menu locations registered in theme
*
* @return void
*/
public function no_locations_message() {
printf( '<p>%s</p>', esc_html__( 'This theme does not register any menu locations.', 'jet-menu' ) );
printf( '<p>%s</p>', esc_html__( 'You will need to create a new menu location to use the JetMenu on your site.', 'jet-menu' ) );
}
/**
* Notice if no menu locations registered in theme
*
* @return void
*/
public function empty_location_message() {
printf( '<p>%s</p>', esc_html__( 'Please assign this menu to a theme location to enable the JetMenu settings.', 'jet-menu' ) );
printf( '<p>%s</p>', esc_html__( 'To assign this menu to a theme location, scroll to the bottom of this page and tag the menu to a \'Display location\'.', 'jet-menu' ) );
}
/**
* Return the locations that a specific menu ID has been tagged to.
*
* @author Tom Hemsley (https://wordpress.org/plugins/megamenu/)
* @param $menu_id int
* @return array
*/
public function get_tagged_theme_locations_for_menu_id( $menu_id ) {
$locations = array();
$nav_menu_locations = get_nav_menu_locations();
foreach ( get_registered_nav_menus() as $id => $name ) {
if ( isset( $nav_menu_locations[ $id ] ) && $nav_menu_locations[$id] == $menu_id )
$locations[$id] = $name;
}
return $locations;
}
/**
* Get the current menu ID.
*
* @author Tom Hemsley (https://wordpress.org/plugins/megamenu/)
* @return int
*/
public function get_selected_menu_id() {
if ( null !== $this->current_menu_id ) {
return $this->current_menu_id;
}
$nav_menus = wp_get_nav_menus( array('orderby' => 'name') );
$menu_count = count( $nav_menus );
$nav_menu_selected_id = isset( $_REQUEST['menu'] ) ? (int) $_REQUEST['menu'] : 0;
$add_new_screen = ( isset( $_GET['menu'] ) && 0 == $_GET['menu'] ) ? true : false;
$this->current_menu_id = $nav_menu_selected_id;
// If we have one theme location, and zero menus, we take them right into editing their first menu
$page_count = wp_count_posts( 'page' );
$one_theme_location_no_menus = ( 1 == count( get_registered_nav_menus() ) && ! $add_new_screen && empty( $nav_menus ) && ! empty( $page_count->publish ) ) ? true : false;
// Get recently edited nav menu
$recently_edited = absint( get_user_option( 'nav_menu_recently_edited' ) );
if ( empty( $recently_edited ) && is_nav_menu( $this->current_menu_id ) ) {
$recently_edited = $this->current_menu_id;
}
// Use $recently_edited if none are selected
if ( empty( $this->current_menu_id ) && ! isset( $_GET['menu'] ) && is_nav_menu( $recently_edited ) ) {
$this->current_menu_id = $recently_edited;
}
// On deletion of menu, if another menu exists, show it
if ( ! $add_new_screen && 0 < $menu_count && isset( $_GET['action'] ) && 'delete' == $_GET['action'] ) {
$this->current_menu_id = $nav_menus[0]->term_id;
}
// Set $this->current_menu_id to 0 if no menus
if ( $one_theme_location_no_menus ) {
$this->current_menu_id = 0;
} elseif ( empty( $this->current_menu_id ) && ! empty( $nav_menus ) && ! $add_new_screen ) {
// if we have no selection yet, and we have menus, set to the first one in the list
$this->current_menu_id = $nav_menus[0]->term_id;
}
return $this->current_menu_id;
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Menu_Settings_Nav
*
* @return object
*/
function jet_menu_settings_nav() {
return Jet_Menu_Settings_Nav::get_instance();
}

View File

@@ -0,0 +1,190 @@
<?php
/**
* Class description
*
* @package package_name
* @author Cherry Team
* @license GPL-2.0+
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Menu_Tools' ) ) {
/**
* Define Jet_Menu_Tools class
*/
class Jet_Menu_Tools {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Render Icon HTML
*
* @param string $icon Icon slug to render.
* @return string
*/
public function get_icon_html( $icon = '' ) {
$format = apply_filters( 'jet-menu/tools/icon-format', '<i class="jet-menu-icon fa %s"></i>', $icon );
return sprintf( $format, esc_attr( $icon ) );
}
/**
* Render Icon HTML
*
* @param string $icon Icon slug to render.
* @param string $icon_base Base icon class to render.
* @return string
*/
public function get_dropdown_arrow_html( $icon = '', $icon_base = 'fa' ) {
$format = apply_filters(
'jet-menu/tools/dropdown-arrow-format',
'<i class="jet-dropdown-arrow %2$s %1$s"></i>',
$icon,
$icon_base
);
return sprintf( $format, esc_attr( $icon ), esc_attr( $icon_base ) );
}
/**
* Get menu badge HTML
*
* @param string $badge Badge HTML.
* @return string
*/
public function get_badge_html( $badge = '', $depth = 0 ) {
if ( 0 < $depth ) {
$is_hidden = jet_menu_option_page()->get_option( 'jet-menu-sub-badge-hide', 'false' );
} else {
$is_hidden = jet_menu_option_page()->get_option( 'jet-menu-top-badge-hide', 'false' );
}
$hide_on_mobile = ( 'true' === $is_hidden ) ? ' jet-hide-mobile' : '';
$format = apply_filters(
'jet-menu/tools/badge-format',
'<small class="jet-menu-badge%2$s"><span class="jet-menu-badge__inner">%1$s</span></small>',
$badge,
$depth
);
return sprintf( $format, esc_attr( $badge ), $hide_on_mobile );
}
/**
* Add menu item dynamic CSS
*
* @param integer $item_id [description]
* @param string $wrapper [description]
*/
public function add_menu_css( $item_id = 0, $wrapper = '' ) {
$settings = jet_menu_settings_item()->get_settings( $item_id );
$css_scheme = apply_filters( 'jet-menu/item-css/sheme', array(
'icon_color' => array(
'selector' => '> a .jet-menu-icon:before',
'rule' => 'color',
'value' => '%1$s !important;',
),
'badge_color' => array(
'selector' => '> a .jet-menu-badge .jet-menu-badge__inner',
'rule' => 'color',
'value' => '%1$s !important;',
),
'badge_bg_color' => array(
'selector' => '> a .jet-menu-badge .jet-menu-badge__inner',
'rule' => 'background-color',
'value' => '%1$s !important;',
),
'item_padding' => array(
'selector' => '> a',
'rule' => 'padding-%s',
'value' => '',
'desktop' => true,
),
'custom_mega_menu_width' => array(
'selector' => '> .jet-sub-mega-menu',
'rule' => 'width',
'value' => '%1$spx !important;',
),
// for Vertical Mega Menu
'mega_menu_width' => array(
'selector' => '> .jet-custom-nav__mega-sub',
'rule' => 'width',
'value' => '%1$spx !important;',
),
) );
foreach ( $css_scheme as $setting => $data ) {
if ( empty( $settings[ $setting ] ) ) {
continue;
}
$_wrapper = $wrapper;
if ( isset( $data['desktop'] ) && true === $data['desktop'] ) {
$_wrapper = 'body:not(.jet-mobile-menu-active) ' . $wrapper;
}
if ( is_array( $settings[ $setting ] ) && isset( $settings[ $setting ]['units'] ) ) {
jet_menu_dynmic_css()->add_dimensions_css(
array(
'selector' => sprintf( '%1$s %2$s', $_wrapper, $data['selector'] ),
'rule' => $data['rule'],
'values' => $settings[ $setting ],
'important' => true,
)
);
} else {
jet_menu()->dynamic_css()->add_style(
sprintf( '%1$s %2$s', $_wrapper, $data['selector'] ),
array(
$data['rule'] => sprintf( $data['value'], esc_attr( $settings[ $setting ] ) ),
)
);
}
}
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Menu_Tools
*
* @return object
*/
function jet_menu_tools() {
return Jet_Menu_Tools::get_instance();
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,85 @@
<?php
/**
* Class for the base update.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Base updater class.
*
* @since 1.0.0
*/
class Jet_Menu_Base_Update {
/**
* Api parameters.
*
* @since 1.0.0
* @access protected
* @var array
*/
protected $api = array(
'version' => '',
'slug' => '',
'api_url' => 'http://jetelements.zemez.io/updates/%s.json',
);
/**
* Init class parameters.
*
* @since 1.0.0
* @param array $attr Input attributes array.
* @return void
*/
protected function base_init( $attr = array() ) {
$this->api = array_merge( $this->api, $attr );
}
/**
* Check if update are avaliable.
*
* @since 1.0.0
* @return array
*/
protected function check_update() {
$response = $this->remote_query();
if ( ! $response ) {
return array( 'version' => false );
}
if ( version_compare( $this->api['version'], $response->version, '<' ) ) {
return array(
'version' => $response->version,
'package' => $response->package,
);
}
return array( 'version' => false );
}
/**
* Remote request to updater API.
*
* @since 1.0.0
* @return array|bool
*/
protected function remote_query() {
$response = wp_remote_get( sprintf( $this->api['api_url'], $this->api['slug'] ) );
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != '200' ) {
return false;
}
$response = json_decode( $response['body'] );
return $response;
}
}

View File

@@ -0,0 +1,143 @@
<?php
/**
* Plugin Changelog class
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Define plugin changelog class.
*
* @since 1.0.0
*/
class Jet_Menu_Plugin_Changelog {
private $transient_key = null;
protected $api = array(
'name' => '',
'slug' => '',
'version' => '',
'author' => '',
'homepage' => '',
'requires' => '4.7',
'tested' => '',
'banners' => array(),
'api_url' => 'https://crocoblock.com/wp-content/uploads/jet-changelog/%s.json',
);
/**
* Init.
*
* @since 1.0.0
* @param array $attr Input attributes array.
* @return void
*/
public function init( $attr = array() ) {
$this->api = wp_parse_args( $attr, $this->api );
$this->transient_key = $this->api['slug'] . '_plugin_info_data';
add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'delete_transients' ), 50 );
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
}
public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
if ( 'plugin_information' !== $_action ) {
return $_data;
}
if ( ! isset( $_args->slug ) || ( $_args->slug !== $this->api['slug'] ) ) {
return $_data;
}
$cache_key = $this->transient_key;
$api_request_transient = get_site_transient( $cache_key );
if ( empty( $api_request_transient ) ) {
$api_response = $this->remote_query();
if ( ! $api_response ) {
return $_data;
}
$api_request_transient = new stdClass();
$api_request_transient->name = $this->api['name'];
$api_request_transient->slug = $this->api['slug'];
$api_request_transient->author = $this->api['author'];
$api_request_transient->homepage = $this->api['homepage'];
$api_request_transient->requires = $this->api['requires'];
$api_request_transient->tested = $this->api['tested'];
$api_request_transient->banners = $this->api['banners'];
$api_request_transient->version = $api_response->current_version;
$api_request_transient->sections = array(
'changelog' => $api_response->changelog,
);
// Expires in 1 day
set_site_transient( $cache_key, $api_request_transient, DAY_IN_SECONDS );
}
$_data = $api_request_transient;
return $_data;
}
public function delete_transients( $data ) {
$plugin = $this->api['slug'] . '/' . $this->api['slug'] . '.php';
if ( isset( $data->response[ $plugin ]->new_version ) && version_compare( $this->api['version'], $data->response[ $plugin ]->new_version, '<' ) ) {
delete_site_transient( $this->transient_key );
}
return $data;
}
protected function remote_query() {
$response = wp_remote_get( sprintf( $this->api['api_url'], $this->api['slug'] ) );
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != '200' ) {
return false;
}
$response = json_decode( $response['body'] );
return $response;
}
public function plugin_row_meta( $plugin_meta, $plugin_file ) {
$plugin = $this->api['slug'] . '/' . $this->api['slug'] . '.php';
if ( $plugin === $plugin_file ) {
$plugin_meta['view-details'] = sprintf( '<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>',
esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $this->api['slug'] . '&TB_iframe=true&width=600&height=550' ) ),
esc_attr( sprintf( __( 'More information about %s', 'jet-menu' ), $this->api['name'] ) ),
esc_attr( $this->api['name'] ),
esc_html__( 'View details', 'jet-menu' )
);
}
return $plugin_meta;
}
}
if ( ! function_exists( 'jet_menu_plugin_changelog' ) ) {
function jet_menu_plugin_changelog() {
return new Jet_Menu_Plugin_Changelog();
}
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* Class for the update plugins.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
require jet_menu()->plugin_path( 'includes/updater/class-jet-menu-base-update.php' );
/**
* Define plugin updater class.
*
* @since 1.0.0
*/
class Jet_Menu_Plugin_Update extends Jet_Menu_Base_Update {
/**
* Init class parameters.
*
* @since 1.0.0
* @param array $attr Input attributes array.
* @return void
*/
public function init( $attr = array() ) {
$this->base_init( $attr );
/**
* Need for test update - set_site_transient( 'update_plugins', null );
*/
add_action( 'pre_set_site_transient_update_plugins', array( $this, 'update' ) );
}
/**
* Process update.
*
* @since 1.0.0
* @param object $data Update data.
* @return object
*/
public function update( $data ) {
$new_update = $this->check_update();
if ( $new_update['version'] ) {
$this->api['plugin'] = $this->api['slug'] . '/' . $this->api['slug'] . '.php';
$update = new stdClass();
$update->slug = $this->api['slug'];
$update->plugin = $this->api['plugin'];
$update->new_version = $new_update['version'];
$update->url = isset( $this->api['details_url'] ) ? $this->api['details_url'] : false;
$update->package = $new_update['package'];
$data->response[ $this->api['plugin'] ] = $update;
}
return $data;
}
}
if ( ! function_exists( 'jet_menu_updater' ) ) {
function jet_menu_updater() {
return new Jet_Menu_Plugin_Update();
}
}

View File

@@ -0,0 +1,470 @@
<?php
/**
* Walker class
*/
class Jet_Menu_Main_Walker extends Walker_Nav_Menu {
protected $item_type = 'simple';
private $item_settings = null;
/**
* Starts the list before the elements are added.
*
* @since 3.0.0
*
* @see Walker::start_lvl()
*
* @param string $output Passed by reference. Used to append additional content.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
*/
public function start_lvl( &$output, $depth = 0, $args = array() ) {
if ( 'mega' === $this->get_item_type() ) {
return;
}
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
$indent = str_repeat( $t, $depth );
// Default class.
$classes = array( 'jet-sub-menu' );
/**
* Filters the CSS class(es) applied to a menu list element.
*
* @since 4.8.0
*
* @param array $classes The CSS classes that are applied to the menu `<ul>` element.
* @param stdClass $args An object of `wp_nav_menu()` arguments.
* @param int $depth Depth of menu item. Used for padding.
*/
$class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) );
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
$output .= "{$n}{$indent}<ul $class_names>{$n}";
}
/**
* Ends the list of after the elements are added.
*
* @since 3.0.0
*
* @see Walker::end_lvl()
*
* @param string $output Passed by reference. Used to append additional content.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
*/
public function end_lvl( &$output, $depth = 0, $args = array() ) {
if ( 'mega' === $this->get_item_type() ) {
return;
}
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
$indent = str_repeat( $t, $depth );
$output .= "$indent</ul>{$n}";
}
/**
* Starts the element output.
*
* @since 3.0.0
* @since 4.4.0 The {@see 'nav_menu_item_args'} filter was added.
*
* @see Walker::start_el()
*
* @param string $output Passed by reference. Used to append additional content.
* @param WP_Post $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param int $id Current item ID.
*/
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
// Don't put any code before this!
$this->item_settings = null;
$this->set_item_type( $item->ID, $depth );
if ( 'mega' === $this->get_item_type() && 0 < $depth ) {
return;
}
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
$settings = $this->get_settings( $item->ID );
$indent = ( $depth ) ? str_repeat( $t, $depth ) : '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
if ( isset( $args->roll_up ) && $args->roll_up ) {
$classes[] = 'has-roll-up';
} else {
$classes[] = 'no-roll-up';
}
if ( 'mega' === $this->get_item_type() ) {
$classes[] = 'mega-menu-item';
if ( ! empty( $settings['custom_mega_menu_position'] ) && 'default' !== $settings['custom_mega_menu_position'] ) {
$classes[] = 'mega-menu-position-' . esc_attr( $settings['custom_mega_menu_position'] );
}
} else {
$classes[] = 'simple-menu-item';
}
$classes[] = 'regular-item';
if ( $this->is_mega_enabled( $item->ID ) ) {
$classes[] = 'menu-item-has-children';
}
/**
* Filters the arguments for a single nav menu item.
*
* @since 4.4.0
*
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param WP_Post $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
*/
$args = apply_filters( 'nav_menu_item_args', $args, $item, $depth );
/**
* Filters the CSS class(es) applied to a menu item's list item element.
*
* @since 3.0.0
* @since 4.1.0 The `$depth` parameter was added.
*
* @param array $classes The CSS classes that are applied to the menu item's `<li>` element.
* @param WP_Post $item The current menu item.
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param int $depth Depth of menu item. Used for padding.
*/
$classes = array_filter( $classes );
array_walk( $classes, array( $this, 'modify_menu_item_classes' ) );
$classes[] = 'jet-menu-item-' . $item->ID;
if ( 0 < $depth ) {
$classes[] = 'jet-sub-menu-item';
}
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', $classes, $item, $args, $depth ) );
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
/**
* Filters the ID applied to a menu item's list item element.
*
* @since 3.0.1
* @since 4.1.0 The `$depth` parameter was added.
*
* @param string $menu_id The ID that is applied to the menu item's `<li>` element.
* @param WP_Post $item The current menu item.
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param int $depth Depth of menu item. Used for padding.
*/
$id = apply_filters( 'nav_menu_item_id', 'jet-menu-item-'. $item->ID, $item, $args, $depth );
$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
$output .= $indent . '<li' . $id . $class_names .'>';
$link_classes = array();
$atts = array();
$atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : '';
$atts['target'] = ! empty( $item->target ) ? $item->target : '';
$atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
$atts['href'] = ! empty( $item->url ) ? $item->url : '';
$link_classes[] = ( 0 === $depth ) ? 'top-level-link' : 'sub-level-link';
if ( isset( $settings['hide_item_text'] ) && 'true' === $settings['hide_item_text'] ) {
$link_classes[] = 'label-hidden';
}
$atts['class'] = implode( ' ', $link_classes );
/**
* Filters the HTML attributes applied to a menu item's anchor element.
*
* @since 3.6.0
* @since 4.1.0 The `$depth` parameter was added.
*
* @param array $atts {
* The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
*
* @type string $title Title attribute.
* @type string $target Target attribute.
* @type string $rel The rel attribute.
* @type string $href The href attribute.
* }
* @param WP_Post $item The current menu item.
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param int $depth Depth of menu item. Used for padding.
*/
$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth );
$attributes = '';
foreach ( $atts as $attr => $value ) {
if ( ! empty( $value ) ) {
$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
$attributes .= ' ' . $attr . '="' . $value . '"';
}
}
/** This filter is documented in wp-includes/post-template.php */
$title = apply_filters( 'the_title', $item->title, $item->ID );
/**
* Filters a menu item's title.
*
* @since 4.4.0
*
* @param string $title The menu item's title.
* @param WP_Post $item The current menu item.
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param int $depth Depth of menu item. Used for padding.
*/
$title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth );
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$icon = '';
$desc = '';
$badge = '';
$arrow = '';
if ( ! empty( $settings['menu_icon'] ) ) {
$icon = jet_menu_tools()->get_icon_html( $settings['menu_icon'] );
}
if ( ! empty( $item->description ) ) {
$desc = sprintf(
'<div class="jet-menu-item-desc %2$s">%1$s</div>',
$item->description,
( 0 === $depth ) ? 'top-level-desc' : 'sub-level-desc'
);
}
$desc_allowed = jet_menu_option_page()->get_option( 'jet-show-top-menu-desc', 'true' );
$desc_allowed = filter_var( $desc_allowed, FILTER_VALIDATE_BOOLEAN );
if ( 0 === $depth && ! $desc_allowed ) {
$desc = '';
}
$sub_desc_allowed = jet_menu_option_page()->get_option( 'jet-show-sub-menu-desc', 'true' );
$sub_desc_allowed = filter_var( $sub_desc_allowed, FILTER_VALIDATE_BOOLEAN );
if ( 0 < $depth && ! $sub_desc_allowed ) {
$desc = '';
}
if ( ! empty( $settings['menu_badge'] ) ) {
$badge = jet_menu_tools()->get_badge_html( $settings['menu_badge'], $depth );
}
if ( isset( $settings['hide_item_text'] ) && 'true' === $settings['hide_item_text'] ) {
$title = '';
}
if ( 0 === $depth ) {
$level = 'top';
} else {
$level = 'sub';
}
if ( in_array( 'menu-item-has-children', $item->classes ) || $this->is_mega_enabled( $item->ID ) ) {
$default_arrow = ( 0 === $depth ) ? 'fa-angle-down' : 'fa-angle-right';
$arrow_icon = jet_menu_option_page()->get_option( 'jet-menu-' . $level . '-arrow', $default_arrow );
$arrow = jet_menu_tools()->get_dropdown_arrow_html( $arrow_icon );
}
$title = sprintf(
'<div class="jet-menu-item-wrapper">%1$s<div class="jet-menu-title">%2$s%3$s</div>%4$s%5$s</div>',
$icon,
$title,
$desc,
$badge,
$arrow
);
$item_output .= $args->link_before . $title . $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$is_elementor = ( isset( $_GET['elementor-preview'] ) ) ? true : false;
$mega_item = get_post_meta( $item->ID, jet_menu_post_type()->meta_key(), true );
if ( $this->is_mega_enabled( $item->ID ) && ! $is_elementor ) {
$content = '';
do_action( 'jet-menu/mega-sub-menu/before-render', $item->ID );
if ( class_exists( 'Elementor\Plugin' ) ) {
$elementor = Elementor\Plugin::instance();
$content = $elementor->frontend->get_builder_content_for_display( $mega_item );
}
do_action( 'jet-menu/mega-sub-menu/after-render', $item->ID );
$item_output .= sprintf( '<div class="jet-sub-mega-menu">%s</div>', do_shortcode( $content ) );
}
jet_menu_tools()->add_menu_css( $item->ID, '.jet-menu-item-' . $item->ID );
$item_output = apply_filters( 'jet-menu/main-walker/start-el', $item_output, $item, $this, $depth, $args );
/**
* Filters a menu item's starting output.
*
* The menu item's starting output only includes `$args->before`, the opening `<a>`,
* the menu item's title, the closing `</a>`, and `$args->after`. Currently, there is
* no filter for modifying the opening and closing `<li>` for a menu item.
*
* @since 3.0.0
*
* @param string $item_output The menu item's starting HTML output.
* @param WP_Post $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
*/
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
/**
* Ends the element output, if needed.
*
* @since 3.0.0
*
* @see Walker::end_el()
*
* @param string $output Passed by reference. Used to append additional content.
* @param WP_Post $item Page data object. Not used.
* @param int $depth Depth of page. Not Used.
* @param stdClass $args An object of wp_nav_menu() arguments.
*/
public function end_el( &$output, $item, $depth = 0, $args = array() ) {
if ( 'mega' === $this->get_item_type() && 0 < $depth ) {
return;
}
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
$item_output = "</li>{$n}";
$item_output = apply_filters( 'jet-menu/main-walker/end-el', $item_output, $item, $this, $depth, $args );
$output .= $item_output;
}
/**
* Modify menu item classes list
*
* @param string &$item
* @return void
*/
public function modify_menu_item_classes( &$item, $index ) {
if ( 0 === $index && 'menu-item' !== $item ) {
return;
}
$item = 'jet-' . $item;
}
/**
* Store in WP Cache processed item type
*
* @param integer $item_id Current menu Item ID
* @param integer $depth Current menu Item depth
*/
public function set_item_type( $item_id = 0, $depth = 0 ) {
if ( 0 < $depth ) {
return;
}
$item_type = 'simple';
if ( $this->is_mega_enabled( $item_id ) ) {
$item_type = 'mega';
}
wp_cache_set( 'item-type', $item_type, 'jet-menu' );
}
/**
* Returns current item (for top level items) or parent item (for subs) type.
* @return [type] [description]
*/
public function get_item_type() {
return wp_cache_get( 'item-type', 'jet-menu' );
}
/**
* Check if mega menu enabled for passed item
*
* @param int $item_id Item ID
* @return boolean
*/
public function is_mega_enabled( $item_id = 0 ) {
$item_settings = $this->get_settings( $item_id );
$menu_post = jet_menu_post_type()->get_related_menu_post( $item_id );
return ( isset( $item_settings['enabled'] ) && 'true' == $item_settings['enabled'] && ! empty( $menu_post ) );
}
/**
* Get item settings
*
* @param integer $item_id Item ID
* @return array
*/
public function get_settings( $item_id = 0 ) {
if ( null === $this->item_settings ) {
$this->item_settings = jet_menu_settings_item()->get_settings( $item_id );
}
return $this->item_settings;
}
}

View File

@@ -0,0 +1,362 @@
<?php
/**
* Walker class
*/
class Jet_Menu_Widget_Walker extends Walker_Nav_Menu {
protected $item_type = 'simple';
private $item_settings = null;
/**
* Starts the list before the elements are added.
*
* @since 3.0.0
*
* @see Walker::start_lvl()
*
* @param string $output Passed by reference. Used to append additional content.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
*/
public function start_lvl( &$output, $depth = 0, $args = array() ) {
if ( 'mega' === $this->get_item_type() ) {
return;
}
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
$indent = str_repeat( $t, $depth );
// Default class.
$classes = array( 'jet-custom-nav__sub' );
$class_names = join( ' ', $classes );
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
$output .= "{$n}{$indent}<div $class_names>{$n}";
}
/**
* Ends the list of after the elements are added.
*
* @since 3.0.0
*
* @see Walker::end_lvl()
*
* @param string $output Passed by reference. Used to append additional content.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
*/
public function end_lvl( &$output, $depth = 0, $args = array() ) {
if ( 'mega' === $this->get_item_type() ) {
return;
}
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
$indent = str_repeat( $t, $depth );
$output .= "$indent</div>{$n}";
}
/**
* Starts the element output.
*
* @since 3.0.0
* @since 4.4.0 The {@see 'nav_menu_item_args'} filter was added.
*
* @see Walker::start_el()
*
* @param string $output Passed by reference. Used to append additional content.
* @param WP_Post $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param int $id Current item ID.
*/
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
// Don't put any code before this!
$this->item_settings = null;
$this->set_item_type( $item->ID, $depth );
if ( 'mega' === $this->get_item_type() && 0 < $depth ) {
return;
}
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
$settings = $this->get_settings( $item->ID );
$indent = ( $depth ) ? str_repeat( $t, $depth ) : '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = 'jet-custom-nav__item';
$classes[] = 'jet-custom-nav__item-' . $item->ID;
jet_menu_tools()->add_menu_css( $item->ID, '.jet-custom-nav__item-' . $item->ID );
if ( $this->is_mega_enabled( $item->ID ) ) {
$classes[] = 'menu-item-has-children';
if ( ! empty( $settings['vertical_mega_menu_position'] ) ) {
$classes[] = 'jet-custom-nav-mega-sub-position-' . esc_attr( $settings['vertical_mega_menu_position'] );
}
}
/**
* Filters the arguments for a single nav menu item.
*
* @since 4.4.0
*
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param WP_Post $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
*/
$args = apply_filters( 'nav_menu_item_args', $args, $item, $depth );
$class_names = join( ' ', array_filter( $classes ) );
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
$output .= $indent . '<div' . $class_names .'>';
$atts = array();
$atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : '';
$atts['target'] = ! empty( $item->target ) ? $item->target : '';
$atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
$atts['href'] = ! empty( $item->url ) ? $item->url : '';
$link_classes = array( 'jet-custom-nav__item-link' );
if ( isset( $settings['hide_item_text'] ) && 'true' === $settings['hide_item_text'] ) {
$link_classes[] = 'jet-custom-nav__item-link--hidden-label';
}
$atts['class'] = implode( ' ', $link_classes );
/**
* Filters the HTML attributes applied to a menu item's anchor element.
*
* @since 3.6.0
* @since 4.1.0 The `$depth` parameter was added.
*
* @param array $atts {
* The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
*
* @type string $title Title attribute.
* @type string $target Target attribute.
* @type string $rel The rel attribute.
* @type string $href The href attribute.
* }
* @param WP_Post $item The current menu item.
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param int $depth Depth of menu item. Used for padding.
*/
$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth );
$attributes = '';
foreach ( $atts as $attr => $value ) {
if ( ! empty( $value ) ) {
$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
$attributes .= ' ' . $attr . '="' . $value . '"';
}
}
/** This filter is documented in wp-includes/post-template.php */
$title = apply_filters( 'the_title', $item->title, $item->ID );
if ( isset( $settings['hide_item_text'] ) && 'true' === $settings['hide_item_text'] ) {
$title = '';
}
$desc = '';
if ( ! empty( $item->description ) ) {
$desc = sprintf(
'<span class="jet-custom-item-desc %2$s">%1$s</span>',
$item->description,
( 0 === $depth ) ? 'top-level-desc' : 'sub-level-desc'
);
}
$title = sprintf( '<span class="jet-menu-link-text">%s%s</span>', $title, $desc );
/**
* Filters a menu item's title.
*
* @since 4.4.0
*
* @param string $title The menu item's title.
* @param WP_Post $item The current menu item.
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param int $depth Depth of menu item. Used for padding.
*/
$title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth );
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
if ( ! empty( $settings['menu_icon'] ) ) {
$title = jet_menu_tools()->get_icon_html( $settings['menu_icon'] ) . $title;
}
if ( ! empty( $settings['menu_badge'] ) ) {
$title = $title . jet_menu_tools()->get_badge_html( $settings['menu_badge'], $depth );
}
if ( in_array( 'menu-item-has-children', $item->classes ) || $this->is_mega_enabled( $item->ID ) ) {
$arrow_icon = isset( $args->widget_settings['dropdown_icon'] ) ? $args->widget_settings['dropdown_icon'] : 'fa fa-chevron-right';
$title = $title . jet_menu_tools()->get_dropdown_arrow_html( $arrow_icon, null );
}
$item_output .= $args->link_before . $title . $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$is_elementor = ( isset( $_GET['elementor-preview'] ) ) ? true : false;
$mega_item = get_post_meta( $item->ID, jet_menu_post_type()->meta_key(), true );
if ( $this->is_mega_enabled( $item->ID ) && ! $is_elementor ) {
$content = '';
do_action( 'jet-menu/widgets/custom-menu/mega-sub-menu/before-render', $item->ID );
if ( class_exists( 'Elementor\Plugin' ) ) {
$elementor = Elementor\Plugin::instance();
$content = $elementor->frontend->get_builder_content_for_display( $mega_item );
}
do_action( 'jet-menu/widgets/custom-menu/mega-sub-menu/after-render', $item->ID );
$item_output .= sprintf( '<div class="jet-custom-nav__mega-sub">%s</div>', do_shortcode( $content ) );
// Fixed displaying mega and sub menu together.
$this->set_item_type( $item->ID, $depth );
}
/**
* Filters a menu item's starting output.
*
* The menu item's starting output only includes `$args->before`, the opening `<a>`,
* the menu item's title, the closing `</a>`, and `$args->after`. Currently, there is
* no filter for modifying the opening and closing `<li>` for a menu item.
*
* @since 3.0.0
*
* @param string $item_output The menu item's starting HTML output.
* @param WP_Post $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
*/
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
/**
* Ends the element output, if needed.
*
* @since 3.0.0
*
* @see Walker::end_el()
*
* @param string $output Passed by reference. Used to append additional content.
* @param WP_Post $item Page data object. Not used.
* @param int $depth Depth of page. Not Used.
* @param stdClass $args An object of wp_nav_menu() arguments.
*/
public function end_el( &$output, $item, $depth = 0, $args = array() ) {
if ( 'mega' === $this->get_item_type() && 0 < $depth ) {
return;
}
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
$output .= "</div>{$n}";
}
/**
* Store in WP Cache processed item type
*
* @param integer $item_id Current menu Item ID
* @param integer $depth Current menu Item depth
*/
public function set_item_type( $item_id = 0, $depth = 0 ) {
if ( 0 < $depth ) {
return;
}
$item_type = 'simple';
if ( $this->is_mega_enabled( $item_id ) ) {
$item_type = 'mega';
}
wp_cache_set( 'item-type', $item_type, 'jet-custom-menu' );
}
/**
* Returns current item (for top level items) or parent item (for subs) type.
* @return [type] [description]
*/
public function get_item_type() {
return wp_cache_get( 'item-type', 'jet-custom-menu' );
}
/**
* Check if mega menu enabled for passed item
*
* @param int $item_id Item ID
* @return boolean
*/
public function is_mega_enabled( $item_id = 0 ) {
$item_settings = $this->get_settings( $item_id );
$menu_post = jet_menu_post_type()->get_related_menu_post( $item_id );
return ( isset( $item_settings['enabled'] ) && 'true' == $item_settings['enabled'] && ! empty( $menu_post ) );
}
/**
* Get item settings
*
* @param integer $item_id Item ID
* @return array
*/
public function get_settings( $item_id = 0 ) {
if ( null === $this->item_settings ) {
$this->item_settings = jet_menu_settings_item()->get_settings( $item_id );
}
return $this->item_settings;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff