芝麻web文件管理V1.00
编辑当前文件:/var/www/cognitio.in/wp-content/plugins/popup-maker/includes/modules/menus.php
[ 'id' => 'disabled_menu_editor', 'name' => __( 'Disable Popups Menu Editor', 'popup-maker' ), 'desc' => sprintf( esc_html_x( 'Use this if there is a conflict with your theme or another plugin in the nav menu editor. %1$sLearn more%2$s', '%s represent opening and closing link html', 'popup-maker' ), '
', '
' ), 'type' => 'checkbox', ], ] ); } public static function nav_menu_columns( $columns = [] ) { $columns['popup_id'] = __( 'Popup', 'popup-maker' ); return $columns; } /** * Override the Admin Menu Walker * * @param $walker * * @return string */ public static function nav_menu_walker( $walker ) { global $wp_version; $bail_early = [ // WP 5.4 adds support for custom fields, no need to do this hack at all. version_compare( $wp_version, '5.4', '>=' ), // not sure about this one, was part of the original solution. doing_filter( 'plugins_loaded' ), // No need if its already loaded by another plugin. 'Walker_Nav_Menu_Edit_Custom_Fields' === $walker, ]; if ( in_array( true, $bail_early ) ) { return $walker; } // Load custom nav menu walker class for custom field compatibility. if ( ! class_exists( 'Walker_Nav_Menu_Edit_Custom_Fields' ) ) { if ( version_compare( $wp_version, '3.6', '>=' ) ) { require_once POPMAKE_DIR . '/includes/modules/menus/class-nav-menu-edit-custom-fields.php'; } else { require_once POPMAKE_DIR . '/includes/modules/menus/class-nav-menu-edit-custom-fields-deprecated.php'; } } return 'Walker_Nav_Menu_Edit_Custom_Fields'; } /** * Merge Item data into the $item object. * * @param $item * * @return mixed */ public static function merge_item_data( $item ) { if ( ! is_object( $item ) || ! isset( $item->ID ) || $item->ID <= 0 ) { return $item; } // Merge Rules. foreach ( self::get_item_options( $item->ID ) as $key => $value ) { $item->$key = $value; } if ( is_admin() ) { return $item; } if ( isset( $item->popup_id ) ) { $item->classes[] = 'popmake-' . $item->popup_id; } /** * Check menu item's classes for popmake-###. Do this after the above conditional to catch the class we add too. * Tested both using strpos followed by preg_match as well as just doing preg_match on all and this solution * was just a tiny bit faster. But, if a site has 100 menu items, that tiny difference will add up. */ foreach ( $item->classes as $class ) { if ( strpos( $class, 'popmake-' ) !== false ) { if ( 0 !== preg_match( '/popmake-(\d+)/', $class, $matches ) ) { PUM_Site_Popups::preload_popup_by_id_if_enabled( $matches[1] ); } } } return $item; } /** * @param int $item_id * * @return array */ public static function get_item_options( $item_id = 0 ) { // Fetch all rules for this menu item. $item_options = get_post_meta( $item_id, '_pum_nav_item_options', true ); return self::parse_item_options( $item_options ); } /** * @param array $options * * @return array */ public static function parse_item_options( $options = [] ) { if ( ! is_array( $options ) ) { $options = []; } return wp_parse_args( $options, [ 'popup_id' => null, ] ); } /** * Adds custom fields to the menu item editor. * * @param $item_id * @param $item * @param $depth * @param $args */ public static function fields( $item_id, $item, $depth, $args ) { wp_nonce_field( 'pum-menu-editor-nonce', 'pum-menu-editor-nonce' ); ?>
$label ) : ?>
popup_id ); ?>>
ID ] = $popup->post_title; } } } return $popup_list; } /** * Processes the saving of menu items. * * @param $menu_id * @param $item_id */ public static function save( $menu_id, $item_id ) { $popups = self::popup_list(); $allowed_popups = wp_parse_id_list( array_keys( $popups ) ); if ( ! isset( $_POST['pum-menu-editor-nonce'] ) || ! wp_verify_nonce( $_POST['pum-menu-editor-nonce'], 'pum-menu-editor-nonce' ) ) { return; } /** * Return early if there are no settings. */ if ( empty( $_POST['menu-item-pum'][ $item_id ] ) ) { delete_post_meta( $item_id, '_pum_nav_item_options' ); return; } /** * Parse options array for valid keys. */ $item_options = self::parse_item_options( $_POST['menu-item-pum'][ $item_id ] ); /** * Check for invalid values. */ if ( ! in_array( $item_options['popup_id'], $allowed_popups ) || $item_options['popup_id'] <= 0 ) { unset( $item_options['popup_id'] ); } /** * Remove empty options to save space. */ $item_options = array_filter( $item_options ); /** * Save options or delete if empty. */ if ( ! empty( $item_options ) ) { update_post_meta( $item_id, '_pum_nav_item_options', $item_options ); } else { delete_post_meta( $item_id, '_pum_nav_item_options' ); } } } PUM_Modules_Menu::init();