wp/wp-admin/includes/ajax-actions.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
   156 		array(
   156 		array(
   157 			'taxonomy'   => $taxonomy,
   157 			'taxonomy'   => $taxonomy,
   158 			'name__like' => $s,
   158 			'name__like' => $s,
   159 			'fields'     => 'names',
   159 			'fields'     => 'names',
   160 			'hide_empty' => false,
   160 			'hide_empty' => false,
       
   161 			'number'     => isset( $_GET['number'] ) ? (int) $_GET['number'] : 0,
   161 		)
   162 		)
   162 	);
   163 	);
   163 
   164 
   164 	echo implode( "\n", $results );
   165 	echo implode( "\n", $results );
   165 	wp_die();
   166 	wp_die();
  1069 	if ( $tag && ! is_wp_error( $tag ) ) {
  1070 	if ( $tag && ! is_wp_error( $tag ) ) {
  1070 		$tag = get_term( $tag['term_id'], $taxonomy );
  1071 		$tag = get_term( $tag['term_id'], $taxonomy );
  1071 	}
  1072 	}
  1072 
  1073 
  1073 	if ( ! $tag || is_wp_error( $tag ) ) {
  1074 	if ( ! $tag || is_wp_error( $tag ) ) {
  1074 		$message = __( 'An error has occurred. Please reload the page and try again.' );
  1075 		$message    = __( 'An error has occurred. Please reload the page and try again.' );
       
  1076 		$error_code = 'error';
  1075 
  1077 
  1076 		if ( is_wp_error( $tag ) && $tag->get_error_message() ) {
  1078 		if ( is_wp_error( $tag ) && $tag->get_error_message() ) {
  1077 			$message = $tag->get_error_message();
  1079 			$message = $tag->get_error_message();
       
  1080 		}
       
  1081 
       
  1082 		if ( is_wp_error( $tag ) && $tag->get_error_code() ) {
       
  1083 			$error_code = $tag->get_error_code();
  1078 		}
  1084 		}
  1079 
  1085 
  1080 		$x->add(
  1086 		$x->add(
  1081 			array(
  1087 			array(
  1082 				'what' => 'taxonomy',
  1088 				'what' => 'taxonomy',
  1083 				'data' => new WP_Error( 'error', $message ),
  1089 				'data' => new WP_Error( $error_code, $message ),
  1084 			)
  1090 			)
  1085 		);
  1091 		);
  1086 		$x->send();
  1092 		$x->send();
  1087 	}
  1093 	}
  1088 
  1094 
  1100 
  1106 
  1101 	ob_start();
  1107 	ob_start();
  1102 	$wp_list_table->single_row( $tag );
  1108 	$wp_list_table->single_row( $tag );
  1103 	$parents = ob_get_clean();
  1109 	$parents = ob_get_clean();
  1104 
  1110 
       
  1111 	require ABSPATH . 'wp-admin/includes/edit-tag-messages.php';
       
  1112 
       
  1113 	$message = '';
       
  1114 	if ( isset( $messages[ $tax->name ][1] ) ) {
       
  1115 		$message = $messages[ $tax->name ][1];
       
  1116 	} elseif ( isset( $messages['_item'][1] ) ) {
       
  1117 		$message = $messages['_item'][1];
       
  1118 	}
       
  1119 
  1105 	$x->add(
  1120 	$x->add(
  1106 		array(
  1121 		array(
  1107 			'what'         => 'taxonomy',
  1122 			'what'         => 'taxonomy',
  1108 			'supplemental' => compact( 'parents', 'noparents' ),
  1123 			'data'         => $message,
       
  1124 			'supplemental' => array(
       
  1125 				'parents'   => $parents,
       
  1126 				'noparents' => $noparents,
       
  1127 				'notice'    => $message,
       
  1128 			),
  1109 		)
  1129 		)
  1110 	);
  1130 	);
  1111 
  1131 
  1112 	$x->add(
  1132 	$x->add(
  1113 		array(
  1133 		array(
  1269 	}
  1289 	}
  1270 
  1290 
  1271 	if ( empty( $post->post_status ) ) {
  1291 	if ( empty( $post->post_status ) ) {
  1272 		wp_die( 1 );
  1292 		wp_die( 1 );
  1273 	} elseif ( in_array( $post->post_status, array( 'draft', 'pending', 'trash' ), true ) ) {
  1293 	} elseif ( in_array( $post->post_status, array( 'draft', 'pending', 'trash' ), true ) ) {
  1274 		wp_die( __( 'Error: You can’t reply to a comment on a draft post.' ) );
  1294 		wp_die( __( 'You cannot reply to a comment on a draft post.' ) );
  1275 	}
  1295 	}
  1276 
  1296 
  1277 	$user = wp_get_current_user();
  1297 	$user = wp_get_current_user();
  1278 
  1298 
  1279 	if ( $user->exists() ) {
  1299 	if ( $user->exists() ) {
  1299 	} else {
  1319 	} else {
  1300 		wp_die( __( 'Sorry, you must be logged in to reply to a comment.' ) );
  1320 		wp_die( __( 'Sorry, you must be logged in to reply to a comment.' ) );
  1301 	}
  1321 	}
  1302 
  1322 
  1303 	if ( '' === $comment_content ) {
  1323 	if ( '' === $comment_content ) {
  1304 		wp_die( __( 'Error: Please type your comment text.' ) );
  1324 		wp_die( __( 'Please type your comment text.' ) );
  1305 	}
  1325 	}
  1306 
  1326 
  1307 	$comment_parent = 0;
  1327 	$comment_parent = 0;
  1308 
  1328 
  1309 	if ( isset( $_POST['comment_ID'] ) ) {
  1329 	if ( isset( $_POST['comment_ID'] ) ) {
  1401 	if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
  1421 	if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
  1402 		wp_die( -1 );
  1422 		wp_die( -1 );
  1403 	}
  1423 	}
  1404 
  1424 
  1405 	if ( '' === $_POST['content'] ) {
  1425 	if ( '' === $_POST['content'] ) {
  1406 		wp_die( __( 'Error: Please type your comment text.' ) );
  1426 		wp_die( __( 'Please type your comment text.' ) );
  1407 	}
  1427 	}
  1408 
  1428 
  1409 	if ( isset( $_POST['status'] ) ) {
  1429 	if ( isset( $_POST['status'] ) ) {
  1410 		$_POST['comment_status'] = $_POST['status'];
  1430 		$_POST['comment_status'] = $_POST['status'];
  1411 	}
  1431 	}
  3001 		$count_query = new WP_Query();
  3021 		$count_query = new WP_Query();
  3002 		$count_query->query( $query );
  3022 		$count_query->query( $query );
  3003 		$total_posts = $count_query->found_posts;
  3023 		$total_posts = $count_query->found_posts;
  3004 	}
  3024 	}
  3005 
  3025 
  3006 	$posts_per_page = (int) $attachments_query->query['posts_per_page'];
  3026 	$posts_per_page = (int) $attachments_query->get( 'posts_per_page' );
  3007 
  3027 
  3008 	$max_pages = $posts_per_page ? ceil( $total_posts / $posts_per_page ) : 0;
  3028 	$max_pages = $posts_per_page ? ceil( $total_posts / $posts_per_page ) : 0;
  3009 
  3029 
  3010 	header( 'X-WP-Total: ' . (int) $total_posts );
  3030 	header( 'X-WP-Total: ' . (int) $total_posts );
  3011 	header( 'X-WP-TotalPages: ' . (int) $max_pages );
  3031 	header( 'X-WP-TotalPages: ' . (int) $max_pages );
  3555 	if ( is_wp_error( $api ) ) {
  3575 	if ( is_wp_error( $api ) ) {
  3556 		wp_send_json_error();
  3576 		wp_send_json_error();
  3557 	}
  3577 	}
  3558 
  3578 
  3559 	$update_php = network_admin_url( 'update.php?action=install-theme' );
  3579 	$update_php = network_admin_url( 'update.php?action=install-theme' );
       
  3580 
       
  3581 	$installed_themes = search_theme_directories();
       
  3582 
       
  3583 	if ( false === $installed_themes ) {
       
  3584 		$installed_themes = array();
       
  3585 	}
       
  3586 
       
  3587 	foreach ( $installed_themes as $theme_slug => $theme_data ) {
       
  3588 		// Ignore child themes.
       
  3589 		if ( str_contains( $theme_slug, '/' ) ) {
       
  3590 			unset( $installed_themes[ $theme_slug ] );
       
  3591 		}
       
  3592 	}
  3560 
  3593 
  3561 	foreach ( $api->themes as &$theme ) {
  3594 	foreach ( $api->themes as &$theme ) {
  3562 		$theme->install_url = add_query_arg(
  3595 		$theme->install_url = add_query_arg(
  3563 			array(
  3596 			array(
  3564 				'theme'    => $theme->slug,
  3597 				'theme'    => $theme->slug,
  3587 					admin_url( 'themes.php' )
  3620 					admin_url( 'themes.php' )
  3588 				);
  3621 				);
  3589 			}
  3622 			}
  3590 		}
  3623 		}
  3591 
  3624 
       
  3625 		$is_theme_installed = array_key_exists( $theme->slug, $installed_themes );
       
  3626 
       
  3627 		// We only care about installed themes.
       
  3628 		$theme->block_theme = $is_theme_installed && wp_get_theme( $theme->slug )->is_block_theme();
       
  3629 
  3592 		if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  3630 		if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
       
  3631 			$customize_url = $theme->block_theme ? admin_url( 'site-editor.php' ) : wp_customize_url( $theme->slug );
       
  3632 
  3593 			$theme->customize_url = add_query_arg(
  3633 			$theme->customize_url = add_query_arg(
  3594 				array(
  3634 				array(
  3595 					'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
  3635 					'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
  3596 				),
  3636 				),
  3597 				wp_customize_url( $theme->slug )
  3637 				$customize_url
  3598 			);
  3638 			);
  3599 		}
  3639 		}
  3600 
  3640 
  3601 		$theme->name        = wp_kses( $theme->name, $themes_allowedtags );
  3641 		$theme->name        = wp_kses( $theme->name, $themes_allowedtags );
  3602 		$theme->author      = wp_kses( $theme->author['display_name'], $themes_allowedtags );
  3642 		$theme->author      = wp_kses( $theme->author['display_name'], $themes_allowedtags );
  3908 				add_filter( 'image_size_names_choose', array( $wp_site_icon, 'additional_sizes' ) );
  3948 				add_filter( 'image_size_names_choose', array( $wp_site_icon, 'additional_sizes' ) );
  3909 				break;
  3949 				break;
  3910 			}
  3950 			}
  3911 
  3951 
  3912 			/** This filter is documented in wp-admin/includes/class-custom-image-header.php */
  3952 			/** This filter is documented in wp-admin/includes/class-custom-image-header.php */
  3913 			$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
  3953 			$cropped    = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
  3914 			$object  = $wp_site_icon->create_attachment_object( $cropped, $attachment_id );
  3954 			$attachment = $wp_site_icon->create_attachment_object( $cropped, $attachment_id );
  3915 			unset( $object['ID'] );
  3955 			unset( $attachment['ID'] );
  3916 
  3956 
  3917 			// Update the attachment.
  3957 			// Update the attachment.
  3918 			add_filter( 'intermediate_image_sizes_advanced', array( $wp_site_icon, 'additional_sizes' ) );
  3958 			add_filter( 'intermediate_image_sizes_advanced', array( $wp_site_icon, 'additional_sizes' ) );
  3919 			$attachment_id = $wp_site_icon->insert_attachment( $object, $cropped );
  3959 			$attachment_id = $wp_site_icon->insert_attachment( $attachment, $cropped );
  3920 			remove_filter( 'intermediate_image_sizes_advanced', array( $wp_site_icon, 'additional_sizes' ) );
  3960 			remove_filter( 'intermediate_image_sizes_advanced', array( $wp_site_icon, 'additional_sizes' ) );
  3921 
  3961 
  3922 			// Additional sizes in wp_prepare_attachment_for_js().
  3962 			// Additional sizes in wp_prepare_attachment_for_js().
  3923 			add_filter( 'image_size_names_choose', array( $wp_site_icon, 'additional_sizes' ) );
  3963 			add_filter( 'image_size_names_choose', array( $wp_site_icon, 'additional_sizes' ) );
  3924 			break;
  3964 			break;
  3938 			do_action( 'wp_ajax_crop_image_pre_save', $context, $attachment_id, $cropped );
  3978 			do_action( 'wp_ajax_crop_image_pre_save', $context, $attachment_id, $cropped );
  3939 
  3979 
  3940 			/** This filter is documented in wp-admin/includes/class-custom-image-header.php */
  3980 			/** This filter is documented in wp-admin/includes/class-custom-image-header.php */
  3941 			$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
  3981 			$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
  3942 
  3982 
  3943 			$parent_url = wp_get_attachment_url( $attachment_id );
  3983 			$parent_url      = wp_get_attachment_url( $attachment_id );
  3944 			$url        = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url );
  3984 			$parent_basename = wp_basename( $parent_url );
       
  3985 			$url             = str_replace( $parent_basename, wp_basename( $cropped ), $parent_url );
  3945 
  3986 
  3946 			$size       = wp_getimagesize( $cropped );
  3987 			$size       = wp_getimagesize( $cropped );
  3947 			$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
  3988 			$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
  3948 
  3989 
  3949 			$object = array(
  3990 			// Get the original image's post to pre-populate the cropped image.
  3950 				'post_title'     => wp_basename( $cropped ),
  3991 			$original_attachment  = get_post( $attachment_id );
  3951 				'post_content'   => $url,
  3992 			$sanitized_post_title = sanitize_file_name( $original_attachment->post_title );
       
  3993 			$use_original_title   = (
       
  3994 				( '' !== trim( $original_attachment->post_title ) ) &&
       
  3995 				/*
       
  3996 				 * Check if the original image has a title other than the "filename" default,
       
  3997 				 * meaning the image had a title when originally uploaded or its title was edited.
       
  3998 				 */
       
  3999 				( $parent_basename !== $sanitized_post_title ) &&
       
  4000 				( pathinfo( $parent_basename, PATHINFO_FILENAME ) !== $sanitized_post_title )
       
  4001 			);
       
  4002 			$use_original_description = ( '' !== trim( $original_attachment->post_content ) );
       
  4003 
       
  4004 			$attachment = array(
       
  4005 				'post_title'     => $use_original_title ? $original_attachment->post_title : wp_basename( $cropped ),
       
  4006 				'post_content'   => $use_original_description ? $original_attachment->post_content : $url,
  3952 				'post_mime_type' => $image_type,
  4007 				'post_mime_type' => $image_type,
  3953 				'guid'           => $url,
  4008 				'guid'           => $url,
  3954 				'context'        => $context,
  4009 				'context'        => $context,
  3955 			);
  4010 			);
  3956 
  4011 
  3957 			$attachment_id = wp_insert_attachment( $object, $cropped );
  4012 			// Copy the image caption attribute (post_excerpt field) from the original image.
       
  4013 			if ( '' !== trim( $original_attachment->post_excerpt ) ) {
       
  4014 				$attachment['post_excerpt'] = $original_attachment->post_excerpt;
       
  4015 			}
       
  4016 
       
  4017 			// Copy the image alt text attribute from the original image.
       
  4018 			if ( '' !== trim( $original_attachment->_wp_attachment_image_alt ) ) {
       
  4019 				$attachment['meta_input'] = array(
       
  4020 					'_wp_attachment_image_alt' => wp_slash( $original_attachment->_wp_attachment_image_alt ),
       
  4021 				);
       
  4022 			}
       
  4023 
       
  4024 			$attachment_id = wp_insert_attachment( $attachment, $cropped );
  3958 			$metadata      = wp_generate_attachment_metadata( $attachment_id, $cropped );
  4025 			$metadata      = wp_generate_attachment_metadata( $attachment_id, $cropped );
  3959 
  4026 
  3960 			/**
  4027 			/**
  3961 			 * Filters the cropped image attachment metadata.
  4028 			 * Filters the cropped image attachment metadata.
  3962 			 *
  4029 			 *
  4126 				),
  4193 				),
  4127 				admin_url( 'themes.php' )
  4194 				admin_url( 'themes.php' )
  4128 			);
  4195 			);
  4129 		}
  4196 		}
  4130 	}
  4197 	}
       
  4198 
       
  4199 	$theme                = wp_get_theme( $slug );
       
  4200 	$status['blockTheme'] = $theme->is_block_theme();
  4131 
  4201 
  4132 	if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  4202 	if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  4133 		$status['customizeUrl'] = add_query_arg(
  4203 		$status['customizeUrl'] = add_query_arg(
  4134 			array(
  4204 			array(
  4135 				'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
  4205 				'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),