Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

wp_xmlrpc_server::_toggle_sticky() WordPress Method

The wp_xmlrpc_server::_toggle_sticky() method is used to toggle the "sticky" status of a post. When a post is sticky, it will appear at the top of the blog's homepage, regardless of its publish date. This is useful for highlighting important posts.

wp_xmlrpc_server::_toggle_sticky( array $post_data, bool $update = false ) #

Encapsulate the logic for sticking a post and determining if the user has permission to do so


Parameters

$post_data

(array)(Required)

$update

(bool)(Optional)

Default value: false


Top ↑

Return

(void|IXR_Error)


Top ↑

Source

File: wp-includes/class-wp-xmlrpc-server.php

	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'] );
			}
		}
	}


Top ↑

Changelog

Changelog
VersionDescription
4.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More