update_post_meta example

array(
                'post_status'               => 'auto-draft',
                'exclude_restore_dismissed' => true,
                'posts_per_page'            => -1,
            )
        );
        $dismissed                 = 0;
        foreach ( $changeset_autodraft_posts as $autosave_autodraft_post ) {
            if ( $autosave_autodraft_post->ID === $this->changeset_post_id() ) {
                continue;
            }
            if ( update_post_meta( $autosave_autodraft_post->ID, '_customize_restore_dismissed', true ) ) {
                $dismissed++;
            }
        }
        return $dismissed;
    }

    /** * Gets the changeset post ID for the loaded changeset. * * @since 4.7.0 * * @return int|null Post ID on success or null if there is no post yet saved. */

        $attr['discover'] = apply_filters( 'embed_oembed_discover', true );

        // Use oEmbed to get the HTML.         $html = wp_oembed_get( $url$attr );

        if ( $post_id ) {
            if ( $html ) {
                update_post_meta( $post_id$cachekey$html );
                update_post_meta( $post_id$cachekey_timetime() );
            } elseif ( ! $cache ) {
                update_post_meta( $post_id$cachekey, '{{unknown}}' );
            }
        } else {
            $has_kses = false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' );

            if ( $has_kses ) {
                // Prevent KSES from corrupting JSON in post_content.                 kses_remove_filters();
            }

            
'post_type'      => 'attachment',
                'post_mime_type' => $metadata['image']['mime'],
                'post_status'    => 'inherit',
                'posts_per_page' => 1,
                'meta_key'       => '_cover_hash',
                'meta_value'     => $hash,
            )
        );
        $exists = reset( $posts );

        if ( ! empty( $exists ) ) {
            update_post_meta( $attachment_id, '_thumbnail_id', $exists );
        } else {
            $ext = '.jpg';
            switch ( $metadata['image']['mime'] ) {
                case 'image/gif':
                    $ext = '.gif';
                    break;
                case 'image/png':
                    $ext = '.png';
                    break;
                case 'image/webp':
                    $ext = '.webp';
                    
'post_content'   => $url,
            'post_mime_type' => $type,
            'guid'           => $url,
            'context'        => 'custom-background',
        );

        // Save the data.         $id = wp_insert_attachment( $attachment$file );

        // Add the metadata.         wp_update_attachment_metadata( $idwp_generate_attachment_metadata( $id$file ) );
        update_post_meta( $id, '_wp_attachment_is_custom_background', get_option( 'stylesheet' ) );

        set_theme_mod( 'background_image', sanitize_url( $url ) );

        $thumbnail = wp_get_attachment_image_src( $id, 'thumbnail' );
        set_theme_mod( 'background_image_thumb', sanitize_url( $thumbnail[0] ) );

        /** This action is documented in wp-admin/includes/class-custom-image-header.php */
        do_action( 'wp_create_file_in_uploads', $file$id ); // For replication.         $this->updated = true;
    }

    

    $file = apply_filters( 'update_attached_file', $file$attachment_id );

    $file = _wp_relative_upload_path( $file );
    if ( $file ) {
        return update_post_meta( $attachment_id, '_wp_attached_file', $file );
    } else {
        return delete_post_meta( $attachment_id, '_wp_attached_file' );
    }
}

/** * Returns relative path to an uploaded file. * * The path is relative to the current upload dir. * * @since 2.9.0 * @access private * * @param string $path Full path to the file. * @return string Relative path on success, unchanged path on failure. */
function _wp_privacy_account_request_confirmed( $request_id ) {
    $request = wp_get_user_request( $request_id );

    if ( ! $request ) {
        return;
    }

    if ( ! in_array( $request->status, array( 'request-pending', 'request-failed' ), true ) ) {
        return;
    }

    update_post_meta( $request_id, '_wp_user_request_confirmed_timestamp', time() );
    wp_update_post(
        array(
            'ID'          => $request_id,
            'post_status' => 'request-confirmed',
        )
    );
}

/** * Notifies the site administrator via email when a request is confirmed. * * Without this, the admin would have to manually check the site to see if any * action was needed on their part yet. * * @since 4.9.6 * * @param int $request_id The ID of the request. */
$translated = _wp_get_allowed_postdata( $post_data );

    // Post formats.     if ( isset( $post_data['post_format'] ) ) {
        set_post_format( $post_id$post_data['post_format'] );
    }

    $format_meta_urls = array( 'url', 'link_url', 'quote_source_url' );
    foreach ( $format_meta_urls as $format_meta_url ) {
        $keyed = '_format_' . $format_meta_url;
        if ( isset( $post_data[ $keyed ] ) ) {
            update_post_meta( $post_id$keyedwp_slash( sanitize_url( wp_unslash( $post_data[ $keyed ] ) ) ) );
        }
    }

    $format_keys = array( 'quote', 'quote_source_name', 'image', 'gallery', 'audio_embed', 'video_embed' );

    foreach ( $format_keys as $key ) {
        $keyed = '_format_' . $key;
        if ( isset( $post_data[ $keyed ] ) ) {
            if ( current_user_can( 'unfiltered_html' ) ) {
                update_post_meta( $post_id$keyed$post_data[ $keyed ] );
            } else {
                

function _wp_privacy_completed_request( $request_id ) {
    // Get the request.     $request_id = absint( $request_id );
    $request    = wp_get_user_request( $request_id );

    if ( ! $request ) {
        return new WP_Error( 'privacy_request_error', __( 'Invalid personal data request.' ) );
    }

    update_post_meta( $request_id, '_wp_user_request_completed_timestamp', time() );

    $result = wp_update_post(
        array(
            'ID'          => $request_id,
            'post_status' => 'request-completed',
        )
    );

    return $result;
}



                        $parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );

                        if ( ! is_wp_error( $parent_object ) ) {
                            $parent_data                        = (array) $parent_object;
                            $menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent'];

                            // Reset invalid `menu_item_parent`.                             $menu_item_data = _wp_reset_invalid_menu_item_parent( $menu_item_data );

                            update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
                        }

                        // Make menu item a child of its next sibling.                     } else {
                        $next_item_data['menu_order'] = $next_item_data['menu_order'] - 1;
                        $menu_item_data['menu_order'] = $menu_item_data['menu_order'] + 1;

                        $menu_item_data['menu_item_parent'] = $next_item_data['ID'];

                        // Reset invalid `menu_item_parent`.                         $menu_item_data = _wp_reset_invalid_menu_item_parent( $menu_item_data );

                        

            $post = apply_filters( 'attachment_fields_to_save', $post$attachment );

            if ( isset( $attachment['image_alt'] ) ) {
                $image_alt = wp_unslash( $attachment['image_alt'] );

                if ( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) !== $image_alt ) {
                    $image_alt = wp_strip_all_tags( $image_alt, true );

                    // update_post_meta() expects slashed.                     update_post_meta( $attachment_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
                }
            }

            if ( isset( $post['errors'] ) ) {
                $errors[ $attachment_id ] = $post['errors'];
                unset( $post['errors'] );
            }

            if ( $post != $_post ) {
                wp_update_post( $post );
            }

            

function wp_restore_footnotes_from_revision( $post_id$revision_id ) {
    $footnotes = get_post_meta( $revision_id, 'footnotes', true );

    if ( $footnotes ) {
        update_post_meta( $post_id, 'footnotes', wp_slash( $footnotes ) );
    } else {
        delete_post_meta( $post_id, 'footnotes' );
    }
}
add_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision', 10, 2 );

/** * Adds the footnotes field to the revision. * * @since 6.3.0 * * @param array $fields The revision fields. * @return array The revision fields. */
if ( is_wp_error( $insert ) ) {
            return $insert;
        }

        $schema = $this->get_item_schema();

        // Extract by name.         $attachment_id = $insert['attachment_id'];
        $file          = $insert['file'];

        if ( isset( $request['alt_text'] ) ) {
            update_post_meta( $attachment_id, '_wp_attachment_image_alt', sanitize_text_field( $request['alt_text'] ) );
        }

        if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
            $meta_update = $this->meta->update_value( $request['meta']$attachment_id );

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

        $attachment    = get_post( $attachment_id );
        

    public function handle_template( $template$post_id$validate = false ) {

        if ( $validate && ! array_key_exists( $templatewp_get_theme()->get_page_templates( get_post( $post_id ) ) ) ) {
            $template = '';
        }

        update_post_meta( $post_id, '_wp_page_template', $template );
    }

    /** * Updates the post's terms from a REST request. * * @since 4.7.0 * * @param int $post_id The post ID to update the terms form. * @param WP_REST_Request $request The request object with post and terms data. * @return null|WP_Error WP_Error on an error assigning any of the terms, otherwise null. */
    
$choice['url'] = sanitize_url( $choice['url'] );

            $header_image_data = (object) array(
                'attachment_id' => $choice['attachment_id'],
                'url'           => $choice['url'],
                'thumbnail_url' => $choice['url'],
                'height'        => $choice['height'],
                'width'         => $choice['width'],
            );

            update_post_meta( $choice['attachment_id'], '_wp_attachment_is_custom_header', get_stylesheet() );

            set_theme_mod( 'header_image', $choice['url'] );
            set_theme_mod( 'header_image_data', $header_image_data );

            return;
        }

        if ( in_array( $choice, array( 'remove-header', 'random-default-image', 'random-uploaded-image' ), true ) ) {
            set_theme_mod( 'header_image', $choice );
            remove_theme_mod( 'header_image_data' );

            
$update['ID'] = $revision['post_parent'];

    $update = wp_slash( $update ); // Since data is from DB.
    $post_id = wp_update_post( $update );

    if ( ! $post_id || is_wp_error( $post_id ) ) {
        return $post_id;
    }

    // Update last edit user.     update_post_meta( $post_id, '_edit_last', get_current_user_id() );

    /** * Fires after a post revision has been restored. * * @since 2.6.0 * * @param int $post_id Post ID. * @param int $revision_id Post revision ID. */
    do_action( 'wp_restore_post_revision', $post_id$revision['ID'] );

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