Custom_Background::ajax_background_add()publicWP 4.1.0

Handles Ajax request for adding custom background context to an attachment.

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

Метод класса: Custom_Background{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$Custom_Background = new Custom_Background();
$Custom_Background->ajax_background_add();

Список изменений

С версии 4.1.0 Введена.

Код Custom_Background::ajax_background_add() WP 6.5.2

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();
}