: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
delete_post_meta( $menu_item_db_id, '_themify_mega_menu_item' );
delete_post_meta( $menu_item_db_id, '_themify_mega_menu_column' );
delete_post_meta( $menu_item_db_id, '_themify_dropdown_columns' );
if( $_POST['menu-item-tf-mega'][ $menu_item_db_id ] != '' ) {
if ( $_POST['menu-item-tf-mega'][ $menu_item_db_id ] === 'mega' ) {
update_post_meta( $menu_item_db_id, '_themify_mega_menu_item', 1 );
} elseif( $_POST['menu-item-tf-mega'][ $menu_item_db_id ] === 'columns' ) {
update_post_meta( $menu_item_db_id, '_themify_mega_menu_column', 1 );
} elseif ( $_POST['menu-item-tf-mega'][ $menu_item_db_id ] === 'drop' && isset( $_POST['menu-item-tf-dropdown_columns'][ $menu_item_db_id ] ) ) {
update_post_meta( $menu_item_db_id, '_themify_dropdown_columns', $_POST['menu-item-tf-dropdown_columns'][ $menu_item_db_id ] );
foreach ( $meta_keys as $meta_key => $param_key ) {
$new_meta_value = isset( $_POST[$param_key] , $_POST[$param_key][$menu_item_db_id] ) ? $_POST[$param_key][$menu_item_db_id] : false;
update_post_meta( $menu_item_db_id, $meta_key, $new_meta_value );
delete_post_meta( $menu_item_db_id, $meta_key );
add_action( 'wp_update_nav_menu_item', 'themify_update_mega_menu_option', 10, 3 );
class Themify_Widgets_Menu {
private static $instance = null;
public $meta_key = '_themify_menu_widget';
* Creates or returns an instance of this class.
* @return A single instance of this class.
public static function get_instance() {
return null == self::$instance ? self::$instance = new self : self::$instance;
private function __construct() {
require_once( ABSPATH . 'wp-admin/includes/widgets.php' );
add_action( 'admin_init', array( $this, 'add_menu_meta_box' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'nav_menu_script' ), 12 );
add_action( 'admin_footer-nav-menus.php', array( $this, 'admin_footer' ) );
add_action( 'wp_nav_menu_item_custom_fields', array( $this, 'wp_nav_menu_item_custom_fields' ), 99, 4 );
add_action( 'wp_update_nav_menu_item', array( $this, 'wp_update_nav_menu_item' ), 10, 3 );
function add_menu_meta_box() {
'themify-menu-widgets-meta',
__( 'Widgets', 'themify' ),
array( $this, 'widgets_menu_meta_box' ),
function widgets_menu_meta_box() {
global $wp_widget_factory;
<div id="themify-widget-section" class="posttypediv">
<label for="themify-menu-widgets"><?php _e( 'Widgets', 'themify' ); ?>:</label>
<select id="themify-menu-widgets" class="widefat">
<?php foreach( $wp_widget_factory->widgets as $widget ) : ?>
<option value="<?php echo get_class( $widget ); ?>"><?php echo $widget->name; ?> </option>
<p class="button-controls">
<span class="add-to-menu">
<input type="submit" class="button-secondary submit-add-to-menu right" value="<?php _e( 'Add to Menu', 'themify' ); ?>" name="add-post-type-menu-item" id="themify-widget-menu-submit">
function wp_nav_menu_item_custom_fields( $item_id, $item, $depth, $args ) {
if( $this->is_menu_widget( $item ) ) :
global $wp_widget_factory;
$class = $this->get_widget_menu_class( $item );
/* Check widget availability */
if ( ! isset( $wp_widget_factory->widgets[ $class ] ) )
<input type="hidden" class="themify-widget-menu-type" value="widget" />
<div class="themify-widget-options" style="clear: both;">
<div class="widget-inside">
<div class="widget-content">
<?php echo $this->get_widget_form( $class, $item_id, $item ); ?>
<input type="hidden" class="id_base" name="id_base" value="<?php echo esc_attr( $wp_widget_factory->widgets[$class]->id_base ) ?>" />
<input type="hidden" class="widget-id" name="widget-id" value="<?php echo time() ?>" />
function wp_update_nav_menu_item( $menu_id, $menu_item_db_id, $args ) {
if ( isset( $_POST['menu-item-widget-options'],$_POST['menu-item-widget-options'][ $menu_item_db_id ] ) ) {
global $wp_widget_factory;
$new_instance = $_POST['menu-item-widget-options'][ $menu_item_db_id ];
/* the widget class is stored in the menu item URL field */
$widget_class = ltrim( $_POST['menu-item-url'][ $menu_item_db_id ], '#' );
if ( isset( $wp_widget_factory->widgets[ $widget_class ] ) ) {
$old_instance = get_post_meta( $menu_item_db_id, $this->meta_key, true );
if ( ! is_array( $old_instance ) )
$instance = $wp_widget_factory->widgets[ $widget_class ]->update( $new_instance, $old_instance );
$instance = apply_filters( 'widget_update_callback', $instance, $new_instance, $old_instance, $wp_widget_factory->widgets[ $widget_class ] );
$this->save_meta( $this->meta_key, $instance, $menu_item_db_id );
function nav_menu_script() {
$screen = get_current_screen();
if( 'nav-menus' !== $screen->base )
themify_enque_script( 'themify-widgets-menu-admin',THEMIFY_URI . '/megamenu/js/admin.js',THEMIFY_VERSION, array( 'jquery' ));
themify_enque_style( 'themify-widgets-menu-admin', THEMIFY_URI . '/megamenu/css/admin.css',null,THEMIFY_VERSION );
do_action( 'themify_widgets_menu_enqueue_admin_scripts' );
remove_action( 'admin_enqueue_scripts', array( $this, 'nav_menu_script' ), 12 );
* Fire enqueue events for Wigets Manager in Menus screen.
* Disabled if using "Google Listings and Ads" plugin, since it throws a fatal error if its script is registered multiple times.
if ( defined( 'WC_GLA_VERSION' ) ) {
do_action( 'sidebar_admin_setup' );
do_action( 'admin_enqueue_scripts', 'widgets.php' );
do_action( 'admin_print_styles-widgets.php' );
do_action( 'admin_print_scripts-widgets.php' );
function admin_footer() {
do_action( 'admin_footer-widgets.php' );
* Returns an array of all registered widget classes
function get_widget_types() {
global $wp_widget_factory;
return array_keys( (array) $wp_widget_factory->widgets );
* Checks if the menu item is of "widget" type and returns the widget's base class name
* @return mixed string name of the base widget class, false otherwise
function get_widget_menu_class( $item ) {
$type = ltrim( $item->url, '#' );
return in_array( $type, $this->get_widget_types(),true )?$type:false;
function is_menu_widget( $item ) {
return $this->get_widget_menu_class( $item )?true:false;
* Generates the widget form required for widget menu types
function get_widget_form( $widget, $item_id, $item ) {
global $wp_widget_factory;
$options = $this->get_widget_options( $item_id );
$wp_widget_factory->widgets[$widget]->form( $options );
do_action_ref_array( 'in_widget_form', array( $wp_widget_factory->widgets[$widget], null, $options ) );
$base_name = 'widget-' . $wp_widget_factory->widgets[$widget]->id_base . '\[' . $wp_widget_factory->widgets[$widget]->number . '\]';
return preg_replace( "/{$base_name}/", 'menu-item-widget-options['. $item_id .']', $form );
* Returns saved options for a widget menu type
function get_widget_options( $item_id ) {
$options = get_post_meta( $item_id, $this->meta_key, true );
if( ! is_array( $options ) ) {
* Helper method that performs proper action on a metadata based on user input
public function save_meta( $meta_key, $new_meta_value, $post_id = null ) {
$meta_value = get_post_meta( $post_id, $meta_key, true );
if ( $new_meta_value && '' == $meta_value )
add_post_meta( $post_id, $meta_key, $new_meta_value, true );
elseif ( $new_meta_value && $new_meta_value != $meta_value )
update_post_meta( $post_id, $meta_key, $new_meta_value );
elseif ( '' == $new_meta_value && $meta_value )
delete_post_meta( $post_id, $meta_key, $meta_value );
* Renders a widget using the provided options
function render_widget( $widget, $instance, $args = array() ) {
the_widget( $widget, $instance, apply_filters( 'themify_widget_menu_args', $args ) );
Themify_Widgets_Menu::get_instance();
* Allow Layout Part post type in navigation menus
function themify_allow_layout_parts_in_nav_menus( $args, $name ) {
if ( 'tbuilder_layout_part' === $name ) {
$args['show_in_nav_menus'] = true;
// add_filter( 'register_post_type_args', 'themify_allow_layout_parts_in_nav_menus', 10, 2 );