to_array example


function wp_insert_user( $userdata ) {
    global $wpdb;

    if ( $userdata instanceof stdClass ) {
        $userdata = get_object_vars( $userdata );
    } elseif ( $userdata instanceof WP_User ) {
        $userdata = $userdata->to_array();
    }

    // Are we updating or creating?     if ( ! empty( $userdata['ID'] ) ) {
        $user_id       = (int) $userdata['ID'];
        $update        = true;
        $old_user_data = get_userdata( $user_id );

        if ( ! $old_user_data ) {
            return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) );
        }

        
 else {
        $_post = WP_Post::get_instance( $post );
    }

    if ( ! $_post ) {
        return null;
    }

    $_post = $_post->filter( $filter );

    if ( ARRAY_A === $output ) {
        return $_post->to_array();
    } elseif ( ARRAY_N === $output ) {
        return array_values( $_post->to_array() );
    }

    return $_post;
}

/** * Retrieves the IDs of the ancestors of a post. * * @since 2.5.0 * * @param int|WP_Post $post Post ID or post object. * @return int[] Array of ancestor IDs or empty array if there are none. */
global $wpdb;

    if ( empty( $site_id ) ) {
        return new WP_Error( 'site_empty_id', __( 'Site ID must not be empty.' ) );
    }

    $old_site = get_site( $site_id );
    if ( ! $old_site ) {
        return new WP_Error( 'site_not_exist', __( 'Site does not exist.' ) );
    }

    $defaults                 = $old_site->to_array();
    $defaults['network_id']   = (int) $defaults['site_id'];
    $defaults['last_updated'] = current_time( 'mysql', true );
    unset( $defaults['blog_id']$defaults['site_id'] );

    $data = wp_prepare_site_data( $data$defaults$old_site );
    if ( is_wp_error( $data ) ) {
        return $data;
    }

    if ( false === $wpdb->update( $wpdb->blogs, $data, array( 'blog_id' => $old_site->id ) ) ) {
        return new WP_Error( 'db_update_error', __( 'Could not update site in the database.' )$wpdb->last_error );
    }

    $_comment = apply_filters( 'get_comment', $_comment );

    if ( OBJECT === $output ) {
        return $_comment;
    } elseif ( ARRAY_A === $output ) {
        return $_comment->to_array();
    } elseif ( ARRAY_N === $output ) {
        return array_values( $_comment->to_array() );
    }
    return $_comment;
}

/** * Retrieves a list of comments. * * The comment list can be for the blog as a whole or for an individual post. * * @since 2.7.0 * * @param string|array $args Optional. Array or string of arguments. See WP_Comment_Query::__construct() * for information on accepted arguments. Default empty string. * @return WP_Comment[]|int[]|int List of comments or number of found comments if `$count` argument is true. */
$_term = apply_filters( "get_{$taxonomy}", $_term$taxonomy );

    // Bail if a filter callback has changed the type of the `$_term` object.     if ( ! ( $_term instanceof WP_Term ) ) {
        return $_term;
    }

    // Sanitize term, according to the specified filter.     $_term->filter( $filter );

    if ( ARRAY_A === $output ) {
        return $_term->to_array();
    } elseif ( ARRAY_N === $output ) {
        return array_values( $_term->to_array() );
    }

    return $_term;
}

/** * Gets all term data from database by term field and data. * * Warning: $value is not escaped for 'name' $field. You must do it yourself, if * required. * * The default $field is 'id', therefore it is possible to also use null for * field, but not recommended that you do so. * * If $value does not exist, the return value will be false. If $taxonomy exists * and $field and $value combinations exist, the term will be returned. * * This function will always return the first term that matches the `$field`- * `$value`-`$taxonomy` combination specified in the parameters. If your query * is likely to match more than one term (as is likely to be the case when * `$field` is 'name', for example), consider using get_terms() instead; that * way, you will get all matching terms, and can provide your own logic for * deciding which one was intended. * * @todo Better formatting for DocBlock. * * @since 2.3.0 * @since 4.4.0 `$taxonomy` is optional if `$field` is 'term_taxonomy_id'. Converted to return * a WP_Term object if `$output` is `OBJECT`. * @since 5.5.0 Added 'ID' as an alias of 'id' for the `$field` parameter. * * @see sanitize_term_field() The $context param lists the available values for get_term_by() $filter param. * * @param string $field Either 'slug', 'name', 'term_id' (or 'id', 'ID'), or 'term_taxonomy_id'. * @param string|int $value Search for this term value. * @param string $taxonomy Taxonomy name. Optional, if `$field` is 'term_taxonomy_id'. * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which * correspond to a WP_Term object, an associative array, or a numeric array, * respectively. Default OBJECT. * @param string $filter Optional. How to sanitize term fields. Default 'raw'. * @return WP_Term|array|false WP_Term instance (or array) on success, depending on the `$output` value. * False if `$taxonomy` does not exist or `$term` was not found. */


                                $userfunction = 'all_spam';
                                $blogs        = get_blogs_of_user( $user_id, true );

                                foreach ( (array) $blogs as $details ) {
                                    if ( ! is_main_site( $details->userblog_id ) ) { // Main site is not a spam!                                         update_blog_status( $details->userblog_id, 'spam', '1' );
                                    }
                                }

                                $user_data         = $user->to_array();
                                $user_data['spam'] = '1';

                                wp_update_user( $user_data );
                                break;

                            case 'notspam':
                                $user = get_userdata( $user_id );

                                $userfunction = 'all_notspam';
                                $blogs        = get_blogs_of_user( $user_id, true );

                                

        }

        // Avoid issues where mbstring.func_overload is enabled.         mbstring_binary_safe_encoding();

        try {
            $requests_response = WpOrg\Requests\Requests::request( $url$headers$data$type$options );

            // Convert the response into an array.             $http_response = new WP_HTTP_Requests_Response( $requests_response$parsed_args['filename'] );
            $response      = $http_response->to_array();

            // Add the original object to the array.             $response['http_response'] = $http_response;
        } catch ( WpOrg\Requests\Exception $e ) {
            $response = new WP_Error( 'http_request_failed', $e->getMessage() );
        }

        reset_mbstring_encoding();

        /** * Fires after an HTTP API response is received and before the response is returned. * * @since 2.8.0 * * @param array|WP_Error $response HTTP response or WP_Error object. * @param string $context Context under which the hook is fired. * @param string $class HTTP transport used. * @param array $parsed_args HTTP request arguments. * @param string $url The request URL. */


    // Make sure count is disabled.     $args['count'] = false;

    $_sites  = get_sites( $args );

    $results = array();

    foreach ( $_sites as $_site ) {
        $_site = get_site( $_site );
        $results[] = $_site->to_array();
    }

    return $results;
}

/** * Check whether a usermeta key has to do with the current blog. * * @since MU (3.0.0) * @deprecated 4.9.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param string $key * @param int $user_id Optional. Defaults to current user. * @param int $blog_id Optional. Defaults to current blog. * @return bool */

        do_action( 'manage_sites_custom_column', $column_name$item['blog_id'] );
    }

    /** * @global string $mode List table view mode. */
    public function display_rows() {
        foreach ( $this->items as $blog ) {
            $blog  = $blog->to_array();
            $class = '';
            reset( $this->status_list );

            foreach ( $this->status_list as $status => $col ) {
                if ( '1' === $blog[ $status ] ) {
                    $class = " class='{$col[0]}'";
                }
            }

            echo "<tr{$class}>";

            
Home | Imprint | This part of the site doesn't use cookies.