Custom_Background::ajax_background_add() WordPress Method

The Custom_Background::ajax_background_add() method allows you to add a new background image via ajax. This is useful if you want to add a new background image without having to reload the page.

Custom_Background::ajax_background_add() #

Ajax handler for adding custom background context to an attachment.


Description

Triggers when the user adds a new background image from the Media Manager.


Top ↑

Source

File: wp-admin/includes/class-custom-background.php

	public function ajax_background_add() {
		check_ajax_referer( 'background-add', 'nonce' );

		if ( ! current_user_can( 'edit_theme_options' ) ) {
			wp_send_json_error();
		}

		$attachment_id = absint( $_POST['attachment_id'] );
		if ( $attachment_id < 1 ) {
			wp_send_json_error();
		}

		update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_stylesheet() );

		wp_send_json_success();
	}


Top ↑

Changelog

Changelog
VersionDescription
4.1.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.