sanitize_widget_js_instance example

$widget_numbers[]               = 1;
                        $max_widget_numbers[ $id_base ] = max( ...$widget_numbers );
                    } else {
                        $max_widget_numbers[ $id_base ] = 1;
                    }
                }
                $max_widget_numbers[ $id_base ] += 1;

                $widget_id  = sprintf( '%s-%d', $id_base$max_widget_numbers[ $id_base ] );
                $setting_id = sprintf( 'widget_%s[%d]', $id_base$max_widget_numbers[ $id_base ] );

                $setting_value = $this->widgets->sanitize_widget_js_instance( $instance );
                if ( empty( $changeset_data[ $setting_id ] ) || ! empty( $changeset_data[ $setting_id ]['starter_content'] ) ) {
                    $this->set_post_value( $setting_id$setting_value );
                    $this->pending_starter_content_settings_ids[] = $setting_id;
                }
                $sidebar_widget_ids[] = $widget_id;
            }

            $setting_id = sprintf( 'sidebars_widgets[%s]', $sidebar_id );
            if ( empty( $changeset_data[ $setting_id ] ) || ! empty( $changeset_data[ $setting_id ]['starter_content'] ) ) {
                $this->set_post_value( $setting_id$sidebar_widget_ids );
                $this->pending_starter_content_settings_ids[] = $setting_id;
            }
if ( preg_match( $this->setting_id_patterns['sidebar_widgets']$id$matches ) ) {
            $args['sanitize_callback']    = array( $this, 'sanitize_sidebar_widgets' );
            $args['sanitize_js_callback'] = array( $this, 'sanitize_sidebar_widgets_js_instance' );
            $args['transport']            = current_theme_supports( 'customize-selective-refresh-widgets' ) ? 'postMessage' : 'refresh';
        } elseif ( preg_match( $this->setting_id_patterns['widget_instance']$id$matches ) ) {
            $id_base                      = $matches['id_base'];
            $args['sanitize_callback']    = function( $value ) use ( $id_base ) {
                return $this->sanitize_widget_instance( $value$id_base );
            };
            $args['sanitize_js_callback'] = function( $value ) use ( $id_base ) {
                return $this->sanitize_widget_js_instance( $value$id_base );
            };
            $args['transport']            = $this->is_widget_selective_refreshable( $matches['id_base'] ) ? 'postMessage' : 'refresh';
        }

        $args = array_merge( $args$overrides );

        /** * Filters the common arguments supplied when constructing a Customizer setting. * * @since 3.9.0 * * @see WP_Customize_Setting * * @param array $args Array of Customizer setting arguments. * @param string $id Widget setting ID. */
$nav_menu_widget_setting = $this->manager->get_setting( $setting_id );
                if ( ! $nav_menu_widget_setting || ! preg_match( '/^widget_nav_menu\[/', $nav_menu_widget_setting->id ) ) {
                    continue;
                }

                $widget_instance = $nav_menu_widget_setting->post_value(); // Note that this calls WP_Customize_Widgets::sanitize_widget_instance().                 if ( empty( $widget_instance['nav_menu'] ) || (int) $widget_instance['nav_menu'] !== $this->previous_term_id ) {
                    continue;
                }

                $widget_instance['nav_menu'] = $this->term_id;
                $updated_widget_instance     = $this->manager->widgets->sanitize_widget_js_instance( $widget_instance );
                $this->manager->set_post_value( $nav_menu_widget_setting->id, $updated_widget_instance );
                $nav_menu_widget_setting->save();

                $this->_widget_nav_menu_updates[ $nav_menu_widget_setting->id ] = $updated_widget_instance;
            }
        }
    }

    /** * Updates a nav_menu_options array. * * @since 4.3.0 * * @see WP_Customize_Nav_Menu_Setting::filter_nav_menu_options() * @see WP_Customize_Nav_Menu_Setting::update() * * @param array $nav_menu_options Array as returned by get_option( 'nav_menu_options' ). * @param int $menu_id The term ID for the given menu. * @param bool $auto_add Whether to auto-add or not. * @return array (Maybe) modified nav_menu_options array. */
Home | Imprint | This part of the site doesn't use cookies.