+ /**
+ * AJAX handler for adding custom background context to an attachment.
+ *
+ * Triggered when the user adds a new background image from the
+ * Media Manager.
+ *
+ * @since 4.1.0
+ */
+ 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();
+ }
+
+ /**
+ *
+ * @since 3.4.0
+ * @deprecated 3.5.0
+ *
+ * @param array $form_fields
+ * @return array $form_fields
+ */
+ public function attachment_fields_to_edit( $form_fields ) {
+ return $form_fields;
+ }
+
+ /**
+ *
+ * @since 3.4.0
+ * @deprecated 3.5.0
+ *
+ * @param array $tabs
+ * @return array $tabs
+ */
+ public function filter_upload_tabs( $tabs ) {
+ return $tabs;
+ }
+
+ /**
+ *
+ * @since 3.4.0
+ * @deprecated 3.5.0
+ */
+ public function wp_set_background_image() {
+ if ( ! current_user_can('edit_theme_options') || ! isset( $_POST['attachment_id'] ) ) exit;
+ $attachment_id = absint($_POST['attachment_id']);
+ /** This filter is documented in wp-admin/includes/media.php */
+ $sizes = array_keys(apply_filters( 'image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')) ));
+ $size = 'thumbnail';
+ if ( in_array( $_POST['size'], $sizes ) )
+ $size = esc_attr( $_POST['size'] );
+
+ update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) );
+ $url = wp_get_attachment_image_src( $attachment_id, $size );
+ $thumbnail = wp_get_attachment_image_src( $attachment_id, 'thumbnail' );
+ set_theme_mod( 'background_image', esc_url_raw( $url[0] ) );
+ set_theme_mod( 'background_image_thumb', esc_url_raw( $thumbnail[0] ) );
+ exit;
+ }