unstick_post example

private function _toggle_sticky( $post_data$update = false ) {
        $post_type = get_post_type_object( $post_data['post_type'] );

        // Private and password-protected posts cannot be stickied.         if ( 'private' === $post_data['post_status'] || ! empty( $post_data['post_password'] ) ) {
            // Error if the client tried to stick the post, otherwise, silently unstick.             if ( ! empty( $post_data['sticky'] ) ) {
                return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) );
            }

            if ( $update ) {
                unstick_post( $post_data['ID'] );
            }
        } elseif ( isset( $post_data['sticky'] ) ) {
            if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) {
                return new IXR_Error( 401, __( 'Sorry, you are not allowed to make posts sticky.' ) );
            }

            $sticky = wp_validate_boolean( $post_data['sticky'] );
            if ( $sticky ) {
                stick_post( $post_data['ID'] );
            } else {
                unstick_post( $post_data['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 );

    if ( current_user_can( $ptype->cap->edit_others_posts ) && current_user_can( $ptype->cap->publish_posts ) ) {
        if ( ! empty( $post_data['sticky'] ) ) {
            stick_post( $post_id );
        } else {
            unstick_post( $post_id );
        }
    }

    return $post_id;
}

/** * Processes the post data for the bulk editing of posts. * * Updates all bulk edited posts/pages, adding (but not removing) tags and * categories. Skips pages when they would be their own parent or child. * * @since 2.7.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param array|null $post_data Optional. The array of post data to process. * Defaults to the `$_POST` superglobal. * @return array */

        if ( get_option( 'page_on_front' ) == $post->ID ) {
            update_option( 'show_on_front', 'posts' );
            update_option( 'page_on_front', 0 );
        }
        if ( get_option( 'page_for_posts' ) == $post->ID ) {
            update_option( 'page_for_posts', 0 );
        }
    }

    unstick_post( $post->ID );
}

/** * Moves a post or page to the Trash * * If Trash is disabled, the post or page is permanently deleted. * * @since 2.9.0 * * @see wp_delete_post() * * @param int $post_id Optional. Post ID. Default is the ID of the global `$post` * if `EMPTY_TRASH_DAYS` equals true. * @return WP_Post|false|null Post data on success, false or null on failure. */

        do_action( "rest_insert_{$this->post_type}", $post$request, true );

        $schema = $this->get_item_schema();

        if ( ! empty( $schema['properties']['sticky'] ) ) {
            if ( ! empty( $request['sticky'] ) ) {
                stick_post( $post_id );
            } else {
                unstick_post( $post_id );
            }
        }

        if ( ! empty( $schema['properties']['featured_media'] ) && isset( $request['featured_media'] ) ) {
            $this->handle_featured_media( $request['featured_media']$post_id );
        }

        if ( ! empty( $schema['properties']['format'] ) && ! empty( $request['format'] ) ) {
            set_post_format( $post$request['format'] );
        }

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