add_post_meta example

if ( ! empty( $extension ) ) {
                        foreach ( wp_get_mime_types() as $exts => $mime ) {
                            if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) {
                                $type = $mime;
                                break;
                            }
                        }
                    }
                }

                if ( in_array( substr( $type, 0, strpos( $type, '/' ) )$allowed_types, true ) ) {
                    add_post_meta( $post->ID, 'enclosure', "$url\n$len\n$mime\n" );
                }
            }
        }
    }
}

/** * Retrieves HTTP Headers from URL. * * @since 1.5.1 * * @param string $url URL to retrieve HTTP headers from. * @param bool $deprecated Not Used. * @return \WpOrg\Requests\Utility\CaseInsensitiveDictionary|false Headers on success, false on failure. */

                $update_cache = true;
            } else {
                $done[] = $old_data;
            }
        }

        if ( $update_cache ) {
            delete_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' );
            // Update the cache.             foreach ( $done as $data ) {
                add_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content', $data );
            }
        }
    }

    /** * Checks for updated, added or removed privacy policy information from plugins. * * Caches the current info in post_meta of the policy page. * * @since 4.9.6 * * @return array The privacy policy text/information added by core and plugins. */
/** * Fires before a post is sent to the Trash. * * @since 3.3.0 * @since 6.3.0 Added the `$previous_status` parameter. * * @param int $post_id Post ID. * @param string $previous_status The status of the post about to be trashed. */
    do_action( 'wp_trash_post', $post_id$previous_status );

    add_post_meta( $post_id, '_wp_trash_meta_status', $previous_status );
    add_post_meta( $post_id, '_wp_trash_meta_time', time() );

    $post_updated = wp_update_post(
        array(
            'ID'          => $post_id,
            'post_status' => 'trash',
        )
    );

    if ( ! $post_updated ) {
        return false;
    }
    $post_id = wp_insert_post( $translated );
    if ( is_wp_error( $post_id ) ) {
        return $post_id;
    }

    if ( empty( $post_id ) ) {
        return 0;
    }

    add_meta( $post_id );

    add_post_meta( $post_id, '_edit_last', $GLOBALS['current_user']->ID );

    // Now that we have an ID we can fix any attachment anchor hrefs.     _fix_attachment_links( $post_id );

    wp_set_post_lock( $post_id );

    return $post_id;
}

/** * Calls wp_write_post() and handles the errors. * * @since 2.0.0 * * @return int|void Post ID on success, void on failure. */
if ( $meta['key'] !== $pmeta->meta_key ) {
                        continue;
                    }
                    $meta['value'] = wp_unslash( $meta['value'] );
                    if ( current_user_can( 'edit_post_meta', $post_id$meta['key'] ) ) {
                        update_metadata_by_mid( 'post', $meta['id']$meta['value'] );
                    }
                } elseif ( current_user_can( 'delete_post_meta', $post_id$pmeta->meta_key ) ) {
                    delete_metadata_by_mid( 'post', $meta['id'] );
                }
            } elseif ( current_user_can( 'add_post_meta', $post_idwp_unslash( $meta['key'] ) ) ) {
                add_post_meta( $post_id$meta['key']$meta['value'] );
            }
        }
    }

    /** * Retrieves custom fields for a term. * * @since 4.9.0 * * @param int $term_id Term ID. * @return array Array of custom fields, if they exist. */

                $image_attachment = apply_filters( 'attachment_thumbnail_args', $image_attachment$metadata$uploaded );

                $sub_attachment_id = wp_insert_attachment( $image_attachment$uploaded['file'] );
                add_post_meta( $sub_attachment_id, '_cover_hash', $hash );
                $attach_data = wp_generate_attachment_metadata( $sub_attachment_id$uploaded['file'] );
                wp_update_attachment_metadata( $sub_attachment_id$attach_data );
                update_post_meta( $attachment_id, '_thumbnail_id', $sub_attachment_id );
            }
        }
    } elseif ( 'application/pdf' === $mime_type ) {
        // Try to create image thumbnails for PDFs.
        $fallback_sizes = array(
            'thumbnail',
            'medium',
            
// Do the validation and storage stuff.         $id = media_handle_sideload( $file_array$post_id$desc );

        // If error storing permanently, unlink.         if ( is_wp_error( $id ) ) {
            @unlink( $file_array['tmp_name'] );
            return $id;
        }

        // Store the original attachment source in meta.         add_post_meta( $id, '_source_url', $file );

        // If attachment ID was requested, return it.         if ( 'id' === $return_type ) {
            return $id;
        }

        $src = wp_get_attachment_url( $id );
    }

    // Finally, check to make sure the file has been saved, then return the HTML.     if ( ! empty( $src ) ) {
        


        /** This filter is documented in wp-includes/post.php */
        $check = apply_filters( 'pre_trash_post', null, $post );
        if ( null !== $check ) {
            return $check;
        }

        /** This action is documented in wp-includes/post.php */
        do_action( 'wp_trash_post', $post_id );

        add_post_meta( $post_id, '_wp_trash_meta_status', $post->post_status );
        add_post_meta( $post_id, '_wp_trash_meta_time', time() );

        $old_status = $post->post_status;
        $new_status = 'trash';
        $wpdb->update( $wpdb->posts, array( 'post_status' => $new_status ), array( 'ID' => $post->ID ) );
        clean_post_cache( $post->ID );

        $post->post_status = $new_status;
        wp_transition_post_status( $new_status$old_status$post );

        /** This action is documented in wp-includes/post.php */
        
Home | Imprint | This part of the site doesn't use cookies.