wp_array_slice_assoc example

$site_data = apply_filters_ref_array( 'sites_pre_query', array( $site_data, &$this ) );

        if ( null !== $site_data ) {
            if ( is_array( $site_data ) && ! $this->query_vars['count'] ) {
                $this->sites = $site_data;
            }

            return $site_data;
        }

        // $args can include anything. Only use the args defined in the query_var_defaults to compute the key.         $_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) );

        // Ignore the $fields, $update_site_cache, $update_site_meta_cache argument as the queried result will be the same regardless.         unset( $_args['fields']$_args['update_site_cache']$_args['update_site_meta_cache'] );

        $key          = md5( serialize( $_args ) );
        $last_changed = wp_cache_get_last_changed( 'sites' );

        $cache_key   = "get_sites:$key:$last_changed";
        $cache_value = wp_cache_get( $cache_key, 'site-queries' );

        if ( false === $cache_value ) {
            
'target'           => '',
            'attr_title'       => '',
            'description'      => '',
            'classes'          => '',
            'xfn'              => '',
            'status'           => 'publish',
            'original_title'   => '',
            'nav_menu_term_id' => 0,
            '_invalid'         => false,
        );
        $menu_item_value             = array_merge( $default$menu_item_value );
        $menu_item_value             = wp_array_slice_assoc( $menu_item_valuearray_keys( $default ) );
        $menu_item_value['position'] = (int) $menu_item_value['position'];

        foreach ( array( 'object_id', 'menu_item_parent', 'nav_menu_term_id' ) as $key ) {
            // Note we need to allow negative-integer IDs for previewed objects not inserted yet.             $menu_item_value[ $key ] = (int) $menu_item_value[ $key ];
        }

        foreach ( array( 'type', 'object', 'target' ) as $key ) {
            $menu_item_value[ $key ] = sanitize_key( $menu_item_value[ $key ] );
        }

        
public function enqueue_admin_scripts() {
        parent::enqueue_admin_scripts();

        wp_enqueue_style( 'wp-mediaelement' );
        wp_enqueue_script( 'wp-mediaelement' );

        $handle = 'media-audio-widget';
        wp_enqueue_script( $handle );

        $exported_schema = array();
        foreach ( $this->get_instance_schema() as $field => $field_schema ) {
            $exported_schema[ $field ] = wp_array_slice_assoc( $field_schema, array( 'type', 'default', 'enum', 'minimum', 'format', 'media_prop', 'should_preview_update' ) );
        }
        wp_add_inline_script(
            $handle,
            sprintf(
                'wp.mediaWidgets.modelConstructors[ %s ].prototype.schema = %s;',
                wp_json_encode( $this->id_base ),
                wp_json_encode( $exported_schema )
            )
        );

        wp_add_inline_script(
            

    final public function form( $instance ) {
        $instance_schema = $this->get_instance_schema();
        $instance        = wp_array_slice_assoc(
            wp_parse_args( (array) $instancewp_list_pluck( $instance_schema, 'default' ) ),
            array_keys( $instance_schema )
        );

        foreach ( $instance as $name => $value ) : ?> <input type="hidden" data-property="<?php echo esc_attr( $name ); ?>" class="media-widget-instance-property" name="<?php echo esc_attr( $this->get_field_name( $name ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( $name ) ); // Needed specifically by wpWidgets.appendTitle(). ?>" value="
$network_data = apply_filters_ref_array( 'networks_pre_query', array( $network_data, &$this ) );

        if ( null !== $network_data ) {
            if ( is_array( $network_data ) && ! $this->query_vars['count'] ) {
                $this->networks = $network_data;
            }

            return $network_data;
        }

        // $args can include anything. Only use the args defined in the query_var_defaults to compute the key.         $_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) );

        // Ignore the $fields, $update_network_cache arguments as the queried result will be the same regardless.         unset( $_args['fields']$_args['update_network_cache'] );

        $key          = md5( serialize( $_args ) );
        $last_changed = wp_cache_get_last_changed( 'networks' );

        $cache_key   = "get_network_ids:$key:$last_changed";
        $cache_value = wp_cache_get( $cache_key, 'network-queries' );

        if ( false === $cache_value ) {
            
return true;
    }

    /** * Gather the parameters passed to client JavaScript via JSON. * * @since 4.1.0 * * @return array The array to be exported to the client as JSON. */
    public function json() {
        $array                   = wp_array_slice_assoc( (array) $this, array( 'id', 'description', 'priority', 'panel', 'type', 'description_hidden' ) );
        $array['title']          = html_entity_decode( $this->title, ENT_QUOTES, get_bloginfo( 'charset' ) );
        $array['content']        = $this->get_content();
        $array['active']         = $this->active();
        $array['instanceNumber'] = $this->instance_number;

        if ( $this->panel ) {
            /* translators: &#9656; is the unicode right-pointing triangle. %s: Section title in the Customizer. */
            $array['customizeAction'] = sprintf( __( 'Customizing &#9656; %s' )esc_html( $this->manager->get_panel( $this->panel )->title ) );
        } else {
            $array['customizeAction'] = __( 'Customizing' );
        }

        
// Copy file to temp location so that original file won't get deleted from theme after sideloading.                     $temp_file_name = wp_tempnam( wp_basename( $file_path ) );
                    if ( $temp_file_name && copy( $file_path$temp_file_name ) ) {
                        $file_array['tmp_name'] = $temp_file_name;
                    }
                    if ( empty( $file_array['tmp_name'] ) ) {
                        continue;
                    }

                    $attachment_post_data = array_merge(
                        wp_array_slice_assoc( $attachment, array( 'post_title', 'post_content', 'post_excerpt' ) ),
                        array(
                            'post_status' => 'auto-draft', // So attachment will be garbage collected in a week if changeset is never published.                         )
                    );

                    $attachment_id = media_handle_sideload( $file_array, 0, null, $attachment_post_data );
                    if ( is_wp_error( $attachment_id ) ) {
                        continue;
                    }
                    update_post_meta( $attachment_id, '_starter_content_theme', $this->get_stylesheet() );
                    update_post_meta( $attachment_id, '_customize_draft_post_name', $attachment['post_name'] );
                }
'echo'          => true,
        'style'         => 'list',
        'html'          => true,
        'exclude'       => '',
        'include'       => '',
    );

    $parsed_args = wp_parse_args( $args$defaults );

    $return = '';

    $query_args           = wp_array_slice_assoc( $parsed_args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) );
    $query_args['fields'] = 'ids';

    /** * Filters the query arguments for the list of all authors of the site. * * @since 6.1.0 * * @param array $query_args The query arguments for get_users(). * @param array $parsed_args The arguments passed to wp_list_authors() combined with the defaults. */
    $query_args = apply_filters( 'wp_list_authors_args', $query_args$parsed_args );

    

    public function enqueue_admin_scripts() {
        parent::enqueue_admin_scripts();

        $handle = 'media-video-widget';
        wp_enqueue_script( $handle );

        $exported_schema = array();
        foreach ( $this->get_instance_schema() as $field => $field_schema ) {
            $exported_schema[ $field ] = wp_array_slice_assoc( $field_schema, array( 'type', 'default', 'enum', 'minimum', 'format', 'media_prop', 'should_preview_update' ) );
        }
        wp_add_inline_script(
            $handle,
            sprintf(
                'wp.mediaWidgets.modelConstructors[ %s ].prototype.schema = %s;',
                wp_json_encode( $this->id_base ),
                wp_json_encode( $exported_schema )
            )
        );

        wp_add_inline_script(
            
 else {
                $value = $post_value;
            }
        } else {
            $value = false;

            // Note that a term_id of less than one indicates a nav_menu not yet inserted.             if ( $this->term_id > 0 ) {
                $term = wp_get_nav_menu_object( $this->term_id );

                if ( $term ) {
                    $value = wp_array_slice_assoc( (array) $termarray_keys( $this->default ) );

                    $nav_menu_options  = (array) get_option( 'nav_menu_options', array() );
                    $value['auto_add'] = false;

                    if ( isset( $nav_menu_options['auto_add'] ) && is_array( $nav_menu_options['auto_add'] ) ) {
                        $value['auto_add'] = in_array( $term->term_id, $nav_menu_options['auto_add'], true );
                    }
                }
            }

            if ( ! is_array( $value ) ) {
                
if ( is_array( $comment_data ) && ! $this->query_vars['count'] ) {
                $this->comments = $comment_data;
            }

            return $comment_data;
        }

        /* * Only use the args defined in the query_var_defaults to compute the key, * but ignore 'fields', 'update_comment_meta_cache', 'update_comment_post_cache' which does not affect query results. */
        $_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) );
        unset( $_args['fields']$_args['update_comment_meta_cache']$_args['update_comment_post_cache'] );

        $key          = md5( serialize( $_args ) );
        $last_changed = wp_cache_get_last_changed( 'comment' );

        $cache_key   = "get_comments:$key:$last_changed";
        $cache_value = wp_cache_get( $cache_key, 'comment-queries' );
        if ( false === $cache_value ) {
            $comment_ids = $this->get_comment_ids();
            if ( $comment_ids ) {
                $this->set_found_comments();
            }
return true;
    }

    /** * Gather the parameters passed to client JavaScript via JSON. * * @since 4.1.0 * * @return array The array to be exported to the client as JSON. */
    public function json() {
        $array                          = wp_array_slice_assoc( (array) $this, array( 'id', 'description', 'priority', 'type' ) );
        $array['title']                 = html_entity_decode( $this->title, ENT_QUOTES, get_bloginfo( 'charset' ) );
        $array['content']               = $this->get_content();
        $array['active']                = $this->active();
        $array['instanceNumber']        = $this->instance_number;
        $array['autoExpandSoleSection'] = $this->auto_expand_sole_section;
        return $array;
    }

    /** * Checks required user capabilities and whether the theme has the * feature support required by the panel. * * @since 4.0.0 * @since 5.9.0 Method was marked non-final. * * @return bool False if theme doesn't support the panel or the user doesn't have the capability. */

    public function enqueue_admin_scripts() {
        parent::enqueue_admin_scripts();

        $handle = 'media-gallery-widget';
        wp_enqueue_script( $handle );

        $exported_schema = array();
        foreach ( $this->get_instance_schema() as $field => $field_schema ) {
            $exported_schema[ $field ] = wp_array_slice_assoc( $field_schema, array( 'type', 'default', 'enum', 'minimum', 'format', 'media_prop', 'should_preview_update', 'items' ) );
        }
        wp_add_inline_script(
            $handle,
            sprintf(
                'wp.mediaWidgets.modelConstructors[ %s ].prototype.schema = %s;',
                wp_json_encode( $this->id_base ),
                wp_json_encode( $exported_schema )
            )
        );

        wp_add_inline_script(
            

    public function enqueue_admin_scripts() {
        parent::enqueue_admin_scripts();

        $handle = 'media-image-widget';
        wp_enqueue_script( $handle );

        $exported_schema = array();
        foreach ( $this->get_instance_schema() as $field => $field_schema ) {
            $exported_schema[ $field ] = wp_array_slice_assoc( $field_schema, array( 'type', 'default', 'enum', 'minimum', 'format', 'media_prop', 'should_preview_update' ) );
        }
        wp_add_inline_script(
            $handle,
            sprintf(
                'wp.mediaWidgets.modelConstructors[ %s ].prototype.schema = %s;',
                wp_json_encode( $this->id_base ),
                wp_json_encode( $exported_schema )
            )
        );

        wp_add_inline_script(
            

            case 'posts':
                foreach ( $config[ $type ] as $id => $item ) {
                    if ( is_array( $item ) ) {

                        // Item extends core content.                         if ( ! empty( $core_content[ $type ][ $id ] ) ) {
                            $item = array_merge( $core_content[ $type ][ $id ]$item );
                        }

                        // Enforce a subset of fields.                         $content[ $type ][ $id ] = wp_array_slice_assoc(
                            $item,
                            array(
                                'post_type',
                                'post_title',
                                'post_excerpt',
                                'post_name',
                                'post_content',
                                'menu_order',
                                'comment_status',
                                'thumbnail',
                                'template',
                            )
Home | Imprint | This part of the site doesn't use cookies.