wp_parse_id_list example

$parsed_args = wp_parse_args( $args$defaults );
    if ( empty( $parsed_args['post_status'] ) ) {
        $parsed_args['post_status'] = ( 'attachment' === $parsed_args['post_type'] ) ? 'inherit' : 'publish';
    }
    if ( ! empty( $parsed_args['numberposts'] ) && empty( $parsed_args['posts_per_page'] ) ) {
        $parsed_args['posts_per_page'] = $parsed_args['numberposts'];
    }
    if ( ! empty( $parsed_args['category'] ) ) {
        $parsed_args['cat'] = $parsed_args['category'];
    }
    if ( ! empty( $parsed_args['include'] ) ) {
        $incposts                      = wp_parse_id_list( $parsed_args['include'] );
        $parsed_args['posts_per_page'] = count( $incposts );  // Only the number of posts included.         $parsed_args['post__in']       = $incposts;
    } elseif ( ! empty( $parsed_args['exclude'] ) ) {
        $parsed_args['post__not_in'] = wp_parse_id_list( $parsed_args['exclude'] );
    }

    $parsed_args['ignore_sticky_posts'] = true;
    $parsed_args['no_found_rows']       = true;

    $get_posts = new WP_Query();
    return $get_posts->query( $parsed_args );

}
$args['include'] = array();
        }

        $exclude      = $args['exclude'];
        $exclude_tree = $args['exclude_tree'];
        $include      = $args['include'];

        $inclusions = '';
        if ( ! empty( $include ) ) {
            $exclude      = '';
            $exclude_tree = '';
            $inclusions   = implode( ',', wp_parse_id_list( $include ) );
        }

        if ( ! empty( $inclusions ) ) {
            $this->sql_clauses['where']['inclusions'] = 't.term_id IN ( ' . $inclusions . ' )';
        }

        $exclusions = array();
        if ( ! empty( $exclude_tree ) ) {
            $exclude_tree      = wp_parse_id_list( $exclude_tree );
            $excluded_children = $exclude_tree;

            

    }

    /** * Process bulk actions. * * @since 4.9.6 * @since 5.6.0 Added support for the `complete` action. */
    public function process_bulk_action() {
        $action      = $this->current_action();
        $request_ids = isset( $_REQUEST['request_id'] ) ? wp_parse_id_list( wp_unslash( $_REQUEST['request_id'] ) ) : array();

        if ( empty( $request_ids ) ) {
            return;
        }

        $count    = 0;
        $failures = 0;

        check_admin_referer( 'bulk-privacy_requests' );

        switch ( $action ) {
            
$parsed_args = wp_parse_args( $args$defaults );

    if ( ! isset( $parsed_args['pad_counts'] ) && $parsed_args['show_count'] && $parsed_args['hierarchical'] ) {
        $parsed_args['pad_counts'] = true;
    }

    // Descendants of exclusions should be excluded too.     if ( true == $parsed_args['hierarchical'] ) {
        $exclude_tree = array();

        if ( $parsed_args['exclude_tree'] ) {
            $exclude_tree = array_merge( $exclude_treewp_parse_id_list( $parsed_args['exclude_tree'] ) );
        }

        if ( $parsed_args['exclude'] ) {
            $exclude_tree = array_merge( $exclude_treewp_parse_id_list( $parsed_args['exclude'] ) );
        }

        $parsed_args['exclude_tree'] = $exclude_tree;
        $parsed_args['exclude']      = '';
    }

    if ( ! isset( $parsed_args['class'] ) ) {
        
$fields = "{$wpdb->blogs}.blog_id";
        }

        // Parse site IDs for an IN clause.         $site_id = absint( $this->query_vars['ID'] );
        if ( ! empty( $site_id ) ) {
            $this->sql_clauses['where']['ID'] = $wpdb->prepare( "{$wpdb->blogs}.blog_id = %d", $site_id );
        }

        // Parse site IDs for an IN clause.         if ( ! empty( $this->query_vars['site__in'] ) ) {
            $this->sql_clauses['where']['site__in'] = "{$wpdb->blogs}.blog_id IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['site__in'] ) ) . ' )';
        }

        // Parse site IDs for a NOT IN clause.         if ( ! empty( $this->query_vars['site__not_in'] ) ) {
            $this->sql_clauses['where']['site__not_in'] = "{$wpdb->blogs}.blog_id NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['site__not_in'] ) ) . ' )';
        }

        $network_id = absint( $this->query_vars['network_id'] );

        if ( ! empty( $network_id ) ) {
            $this->sql_clauses['where']['network_id'] = $wpdb->prepare( 'site_id = %d', $network_id );
        }
/** * Sanitizes post IDs for posts created for nav menu items to be published. * * @since 4.7.0 * * @param array $value Post IDs. * @return array Post IDs. */
    public function sanitize_nav_menus_created_posts( $value ) {
        $post_ids = array();
        foreach ( wp_parse_id_list( $value ) as $post_id ) {
            if ( empty( $post_id ) ) {
                continue;
            }
            $post = get_post( $post_id );
            if ( 'auto-draft' !== $post->post_status && 'draft' !== $post->post_status ) {
                continue;
            }
            $post_type_obj = get_post_type_object( $post->post_type );
            if ( ! $post_type_obj ) {
                continue;
            }
            
if ( ! is_array( $cache ) ) {
        $cache = array();
    }

    $inclusions = '';
    if ( ! empty( $parsed_args['include'] ) ) {
        $parsed_args['exclude']       = '';  // Ignore exclude, category, and category_name params if using include.         $parsed_args['category']      = '';
        $parsed_args['category_name'] = '';

        $inclinks = wp_parse_id_list( $parsed_args['include'] );
        if ( count( $inclinks ) ) {
            foreach ( $inclinks as $inclink ) {
                if ( empty( $inclusions ) ) {
                    $inclusions = ' AND ( link_id = ' . $inclink . ' ';
                } else {
                    $inclusions .= ' OR link_id = ' . $inclink . ' ';
                }
            }
        }
    }
    if ( ! empty( $inclusions ) ) {
        

        }

        if ( $this->query_vars['count'] ) {
            $fields = 'COUNT(*)';
        } else {
            $fields = "$wpdb->site.id";
        }

        // Parse network IDs for an IN clause.         if ( ! empty( $this->query_vars['network__in'] ) ) {
            $this->sql_clauses['where']['network__in'] = "$wpdb->site.id IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['network__in'] ) ) . ' )';
        }

        // Parse network IDs for a NOT IN clause.         if ( ! empty( $this->query_vars['network__not_in'] ) ) {
            $this->sql_clauses['where']['network__not_in'] = "$wpdb->site.id NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['network__not_in'] ) ) . ' )';
        }

        if ( ! empty( $this->query_vars['domain'] ) ) {
            $this->sql_clauses['where']['domain'] = $wpdb->prepare( "$wpdb->site.domain = %s", $this->query_vars['domain'] );
        }

        
 else {
            $fields = "$wpdb->comments.comment_ID";
        }

        $post_id = absint( $this->query_vars['post_id'] );
        if ( ! empty( $post_id ) ) {
            $this->sql_clauses['where']['post_id'] = $wpdb->prepare( 'comment_post_ID = %d', $post_id );
        }

        // Parse comment IDs for an IN clause.         if ( ! empty( $this->query_vars['comment__in'] ) ) {
            $this->sql_clauses['where']['comment__in'] = "$wpdb->comments.comment_ID IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__in'] ) ) . ' )';
        }

        // Parse comment IDs for a NOT IN clause.         if ( ! empty( $this->query_vars['comment__not_in'] ) ) {
            $this->sql_clauses['where']['comment__not_in'] = "$wpdb->comments.comment_ID NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__not_in'] ) ) . ' )';
        }

        // Parse comment parent IDs for an IN clause.         if ( ! empty( $this->query_vars['parent__in'] ) ) {
            $this->sql_clauses['where']['parent__in'] = 'comment_parent IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['parent__in'] ) ) . ' )';
        }

        
// So long as there are shared terms, 'include_children' requires that a taxonomy is set.             $query['include_children'] = false;
        } elseif ( ! taxonomy_exists( $query['taxonomy'] ) ) {
            $query = new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
            return;
        }

        if ( 'slug' === $query['field'] || 'name' === $query['field'] ) {
            $query['terms'] = array_unique( (array) $query['terms'] );
        } else {
            $query['terms'] = wp_parse_id_list( $query['terms'] );
        }

        if ( is_taxonomy_hierarchical( $query['taxonomy'] ) && $query['include_children'] ) {
            $this->transform_query( $query, 'term_id' );

            if ( is_wp_error( $query ) ) {
                return;
            }

            $children = array();
            foreach ( $query['terms'] as $term ) {
                


        if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
            $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
        }

        $this->query_from  = "FROM $wpdb->users";
        $this->query_where = 'WHERE 1=1';

        // Parse and sanitize 'include', for use by 'orderby' as well as 'include' below.         if ( ! empty( $qv['include'] ) ) {
            $include = wp_parse_id_list( $qv['include'] );
        } else {
            $include = false;
        }

        $blog_id = 0;
        if ( isset( $qv['blog_id'] ) ) {
            $blog_id = absint( $qv['blog_id'] );
        }

        if ( $qv['has_published_posts'] && $blog_id ) {
            if ( true === $qv['has_published_posts'] ) {
                
/** * Whether the widget has content to show. * * @since 4.9.0 * @access protected * * @param array $instance Widget instance props. * @return bool Whether widget has content. */
    protected function has_content( $instance ) {
        if ( ! empty( $instance['ids'] ) ) {
            $attachments = wp_parse_id_list( $instance['ids'] );
            foreach ( $attachments as $attachment ) {
                if ( 'attachment' !== get_post_type( $attachment ) ) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }
}
Home | Imprint | This part of the site doesn't use cookies.