Edit File by line
/home/barbar84/www/wp-conte.../plugins/wordpres.../admin
File: ajax.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WPSEO plugin file.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WPSEO\Admin
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
if ( ! defined( 'WPSEO_VERSION' ) ) {
[7] Fix | Delete
header( 'Status: 403 Forbidden' );
[8] Fix | Delete
header( 'HTTP/1.1 403 Forbidden' );
[9] Fix | Delete
exit();
[10] Fix | Delete
}
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Convenience function to JSON encode and echo results and then die.
[14] Fix | Delete
*
[15] Fix | Delete
* @param array $results Results array for encoding.
[16] Fix | Delete
*/
[17] Fix | Delete
function wpseo_ajax_json_echo_die( $results ) {
[18] Fix | Delete
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: WPSEO_Utils::format_json_encode is safe.
[19] Fix | Delete
echo WPSEO_Utils::format_json_encode( $results );
[20] Fix | Delete
die();
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* Function used from AJAX calls, takes it variables from $_POST, dies on exit.
[25] Fix | Delete
*/
[26] Fix | Delete
function wpseo_set_option() {
[27] Fix | Delete
if ( ! current_user_can( 'manage_options' ) ) {
[28] Fix | Delete
die( '-1' );
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
check_ajax_referer( 'wpseo-setoption' );
[32] Fix | Delete
[33] Fix | Delete
$option = sanitize_text_field( filter_input( INPUT_POST, 'option' ) );
[34] Fix | Delete
if ( $option !== 'page_comments' ) {
[35] Fix | Delete
die( '-1' );
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
update_option( $option, 0 );
[39] Fix | Delete
die( '1' );
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
add_action( 'wp_ajax_wpseo_set_option', 'wpseo_set_option' );
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Since 3.2 Notifications are dismissed in the Notification Center.
[46] Fix | Delete
*/
[47] Fix | Delete
add_action( 'wp_ajax_yoast_dismiss_notification', [ 'Yoast_Notification_Center', 'ajax_dismiss_notification' ] );
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* Function used to remove the admin notices for several purposes, dies on exit.
[51] Fix | Delete
*/
[52] Fix | Delete
function wpseo_set_ignore() {
[53] Fix | Delete
if ( ! current_user_can( 'manage_options' ) ) {
[54] Fix | Delete
die( '-1' );
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
check_ajax_referer( 'wpseo-ignore' );
[58] Fix | Delete
[59] Fix | Delete
$ignore_key = sanitize_text_field( filter_input( INPUT_POST, 'option' ) );
[60] Fix | Delete
WPSEO_Options::set( 'ignore_' . $ignore_key, true );
[61] Fix | Delete
[62] Fix | Delete
die( '1' );
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
add_action( 'wp_ajax_wpseo_set_ignore', 'wpseo_set_ignore' );
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Save an individual SEO title from the Bulk Editor.
[69] Fix | Delete
*/
[70] Fix | Delete
function wpseo_save_title() {
[71] Fix | Delete
wpseo_save_what( 'title' );
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
add_action( 'wp_ajax_wpseo_save_title', 'wpseo_save_title' );
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Save an individual meta description from the Bulk Editor.
[78] Fix | Delete
*/
[79] Fix | Delete
function wpseo_save_description() {
[80] Fix | Delete
wpseo_save_what( 'metadesc' );
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
add_action( 'wp_ajax_wpseo_save_metadesc', 'wpseo_save_description' );
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* Save titles & descriptions.
[87] Fix | Delete
*
[88] Fix | Delete
* @param string $what Type of item to save (title, description).
[89] Fix | Delete
*/
[90] Fix | Delete
function wpseo_save_what( $what ) {
[91] Fix | Delete
check_ajax_referer( 'wpseo-bulk-editor' );
[92] Fix | Delete
[93] Fix | Delete
$new = filter_input( INPUT_POST, 'new_value' );
[94] Fix | Delete
$post_id = intval( filter_input( INPUT_POST, 'wpseo_post_id' ) );
[95] Fix | Delete
$original = filter_input( INPUT_POST, 'existing_value' );
[96] Fix | Delete
[97] Fix | Delete
$results = wpseo_upsert_new( $what, $post_id, $new, $original );
[98] Fix | Delete
[99] Fix | Delete
wpseo_ajax_json_echo_die( $results );
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* Helper function to update a post's meta data, returning relevant information
[104] Fix | Delete
* about the information updated and the results or the meta update.
[105] Fix | Delete
*
[106] Fix | Delete
* @param int $post_id Post ID.
[107] Fix | Delete
* @param string $new_meta_value New meta value to record.
[108] Fix | Delete
* @param string $orig_meta_value Original meta value.
[109] Fix | Delete
* @param string $meta_key Meta key string.
[110] Fix | Delete
* @param string $return_key Return key string to use in results.
[111] Fix | Delete
*
[112] Fix | Delete
* @return string
[113] Fix | Delete
*/
[114] Fix | Delete
function wpseo_upsert_meta( $post_id, $new_meta_value, $orig_meta_value, $meta_key, $return_key ) {
[115] Fix | Delete
[116] Fix | Delete
$post_id = intval( $post_id );
[117] Fix | Delete
$sanitized_new_meta_value = wp_strip_all_tags( $new_meta_value );
[118] Fix | Delete
$orig_meta_value = wp_strip_all_tags( $orig_meta_value );
[119] Fix | Delete
[120] Fix | Delete
$upsert_results = [
[121] Fix | Delete
'status' => 'success',
[122] Fix | Delete
'post_id' => $post_id,
[123] Fix | Delete
"new_{$return_key}" => $sanitized_new_meta_value,
[124] Fix | Delete
"original_{$return_key}" => $orig_meta_value,
[125] Fix | Delete
];
[126] Fix | Delete
[127] Fix | Delete
$the_post = get_post( $post_id );
[128] Fix | Delete
if ( empty( $the_post ) ) {
[129] Fix | Delete
[130] Fix | Delete
$upsert_results['status'] = 'failure';
[131] Fix | Delete
$upsert_results['results'] = __( 'Post doesn\'t exist.', 'wordpress-seo' );
[132] Fix | Delete
[133] Fix | Delete
return $upsert_results;
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
$post_type_object = get_post_type_object( $the_post->post_type );
[137] Fix | Delete
if ( ! $post_type_object ) {
[138] Fix | Delete
[139] Fix | Delete
$upsert_results['status'] = 'failure';
[140] Fix | Delete
$upsert_results['results'] = sprintf(
[141] Fix | Delete
/* translators: %s expands to post type. */
[142] Fix | Delete
__( 'Post has an invalid Content Type: %s.', 'wordpress-seo' ),
[143] Fix | Delete
$the_post->post_type
[144] Fix | Delete
);
[145] Fix | Delete
[146] Fix | Delete
return $upsert_results;
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
if ( ! current_user_can( $post_type_object->cap->edit_posts ) ) {
[150] Fix | Delete
[151] Fix | Delete
$upsert_results['status'] = 'failure';
[152] Fix | Delete
$upsert_results['results'] = sprintf(
[153] Fix | Delete
/* translators: %s expands to post type name. */
[154] Fix | Delete
__( 'You can\'t edit %s.', 'wordpress-seo' ),
[155] Fix | Delete
$post_type_object->label
[156] Fix | Delete
);
[157] Fix | Delete
[158] Fix | Delete
return $upsert_results;
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
if ( ! current_user_can( $post_type_object->cap->edit_others_posts ) && (int) $the_post->post_author !== get_current_user_id() ) {
[162] Fix | Delete
[163] Fix | Delete
$upsert_results['status'] = 'failure';
[164] Fix | Delete
$upsert_results['results'] = sprintf(
[165] Fix | Delete
/* translators: %s expands to the name of a post type (plural). */
[166] Fix | Delete
__( 'You can\'t edit %s that aren\'t yours.', 'wordpress-seo' ),
[167] Fix | Delete
$post_type_object->label
[168] Fix | Delete
);
[169] Fix | Delete
[170] Fix | Delete
return $upsert_results;
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
if ( $sanitized_new_meta_value === $orig_meta_value && $sanitized_new_meta_value !== $new_meta_value ) {
[174] Fix | Delete
$upsert_results['status'] = 'failure';
[175] Fix | Delete
$upsert_results['results'] = __( 'You have used HTML in your value which is not allowed.', 'wordpress-seo' );
[176] Fix | Delete
[177] Fix | Delete
return $upsert_results;
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
$res = update_post_meta( $post_id, $meta_key, $sanitized_new_meta_value );
[181] Fix | Delete
[182] Fix | Delete
$upsert_results['status'] = ( $res !== false ) ? 'success' : 'failure';
[183] Fix | Delete
$upsert_results['results'] = $res;
[184] Fix | Delete
[185] Fix | Delete
return $upsert_results;
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
/**
[189] Fix | Delete
* Save all titles sent from the Bulk Editor.
[190] Fix | Delete
*/
[191] Fix | Delete
function wpseo_save_all_titles() {
[192] Fix | Delete
wpseo_save_all( 'title' );
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
add_action( 'wp_ajax_wpseo_save_all_titles', 'wpseo_save_all_titles' );
[196] Fix | Delete
[197] Fix | Delete
/**
[198] Fix | Delete
* Save all description sent from the Bulk Editor.
[199] Fix | Delete
*/
[200] Fix | Delete
function wpseo_save_all_descriptions() {
[201] Fix | Delete
wpseo_save_all( 'metadesc' );
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
add_action( 'wp_ajax_wpseo_save_all_descriptions', 'wpseo_save_all_descriptions' );
[205] Fix | Delete
[206] Fix | Delete
/**
[207] Fix | Delete
* Utility function to save values.
[208] Fix | Delete
*
[209] Fix | Delete
* @param string $what Type of item so save.
[210] Fix | Delete
*/
[211] Fix | Delete
function wpseo_save_all( $what ) {
[212] Fix | Delete
check_ajax_referer( 'wpseo-bulk-editor' );
[213] Fix | Delete
[214] Fix | Delete
$results = [];
[215] Fix | Delete
if ( ! isset( $_POST['items'], $_POST['existingItems'] ) ) {
[216] Fix | Delete
wpseo_ajax_json_echo_die( $results );
[217] Fix | Delete
}
[218] Fix | Delete
[219] Fix | Delete
$new_values = array_map( [ 'WPSEO_Utils', 'sanitize_text_field' ], wp_unslash( (array) $_POST['items'] ) );
[220] Fix | Delete
$original_values = array_map( [ 'WPSEO_Utils', 'sanitize_text_field' ], wp_unslash( (array) $_POST['existingItems'] ) );
[221] Fix | Delete
[222] Fix | Delete
foreach ( $new_values as $post_id => $new_value ) {
[223] Fix | Delete
$original_value = $original_values[ $post_id ];
[224] Fix | Delete
$results[] = wpseo_upsert_new( $what, $post_id, $new_value, $original_value );
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
wpseo_ajax_json_echo_die( $results );
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
/**
[231] Fix | Delete
* Insert a new value.
[232] Fix | Delete
*
[233] Fix | Delete
* @param string $what Item type (such as title).
[234] Fix | Delete
* @param int $post_id Post ID.
[235] Fix | Delete
* @param string $new New value to record.
[236] Fix | Delete
* @param string $original Original value.
[237] Fix | Delete
*
[238] Fix | Delete
* @return string
[239] Fix | Delete
*/
[240] Fix | Delete
function wpseo_upsert_new( $what, $post_id, $new, $original ) {
[241] Fix | Delete
$meta_key = WPSEO_Meta::$meta_prefix . $what;
[242] Fix | Delete
[243] Fix | Delete
return wpseo_upsert_meta( $post_id, $new, $original, $meta_key, $what );
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
/**
[247] Fix | Delete
* Retrieves the keyword for the keyword doubles.
[248] Fix | Delete
*/
[249] Fix | Delete
function ajax_get_keyword_usage() {
[250] Fix | Delete
$post_id = filter_input( INPUT_POST, 'post_id' );
[251] Fix | Delete
$keyword = filter_input( INPUT_POST, 'keyword' );
[252] Fix | Delete
[253] Fix | Delete
if ( ! current_user_can( 'edit_post', $post_id ) ) {
[254] Fix | Delete
die( '-1' );
[255] Fix | Delete
}
[256] Fix | Delete
[257] Fix | Delete
wp_die(
[258] Fix | Delete
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: WPSEO_Utils::format_json_encode is safe.
[259] Fix | Delete
WPSEO_Utils::format_json_encode( WPSEO_Meta::keyword_usage( $keyword, $post_id ) )
[260] Fix | Delete
);
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
add_action( 'wp_ajax_get_focus_keyword_usage', 'ajax_get_keyword_usage' );
[264] Fix | Delete
[265] Fix | Delete
/**
[266] Fix | Delete
* Retrieves the keyword for the keyword doubles of the termpages.
[267] Fix | Delete
*/
[268] Fix | Delete
function ajax_get_term_keyword_usage() {
[269] Fix | Delete
$post_id = filter_input( INPUT_POST, 'post_id' );
[270] Fix | Delete
$keyword = filter_input( INPUT_POST, 'keyword' );
[271] Fix | Delete
$taxonomy_name = filter_input( INPUT_POST, 'taxonomy' );
[272] Fix | Delete
[273] Fix | Delete
$taxonomy = get_taxonomy( $taxonomy_name );
[274] Fix | Delete
[275] Fix | Delete
if ( ! $taxonomy ) {
[276] Fix | Delete
wp_die( 0 );
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) {
[280] Fix | Delete
wp_die( -1 );
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
$usage = WPSEO_Taxonomy_Meta::get_keyword_usage( $keyword, $post_id, $taxonomy_name );
[284] Fix | Delete
[285] Fix | Delete
// Normalize the result so it it the same as the post keyword usage AJAX request.
[286] Fix | Delete
$usage = $usage[ $keyword ];
[287] Fix | Delete
[288] Fix | Delete
wp_die(
[289] Fix | Delete
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: WPSEO_Utils::format_json_encode is safe.
[290] Fix | Delete
WPSEO_Utils::format_json_encode( $usage )
[291] Fix | Delete
);
[292] Fix | Delete
}
[293] Fix | Delete
[294] Fix | Delete
add_action( 'wp_ajax_get_term_keyword_usage', 'ajax_get_term_keyword_usage' );
[295] Fix | Delete
[296] Fix | Delete
/**
[297] Fix | Delete
* Registers hooks for all AJAX integrations.
[298] Fix | Delete
*
[299] Fix | Delete
* @return void
[300] Fix | Delete
*/
[301] Fix | Delete
function wpseo_register_ajax_integrations() {
[302] Fix | Delete
$integrations = [ new Yoast_Network_Admin() ];
[303] Fix | Delete
[304] Fix | Delete
foreach ( $integrations as $integration ) {
[305] Fix | Delete
$integration->register_ajax_hooks();
[306] Fix | Delete
}
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
wpseo_register_ajax_integrations();
[310] Fix | Delete
[311] Fix | Delete
new WPSEO_Shortcode_Filter();
[312] Fix | Delete
[313] Fix | Delete
new WPSEO_Taxonomy_Columns();
[314] Fix | Delete
[315] Fix | Delete
/* ********************* DEPRECATED FUNCTIONS ********************* */
[316] Fix | Delete
[317] Fix | Delete
/**
[318] Fix | Delete
* Hides the default tagline notice for a specific user.
[319] Fix | Delete
*
[320] Fix | Delete
* @deprecated 13.2
[321] Fix | Delete
* @codeCoverageIgnore
[322] Fix | Delete
*/
[323] Fix | Delete
function wpseo_dismiss_tagline_notice() {
[324] Fix | Delete
if ( ! current_user_can( 'manage_options' ) ) {
[325] Fix | Delete
die( '-1' );
[326] Fix | Delete
}
[327] Fix | Delete
[328] Fix | Delete
_deprecated_function( __FUNCTION__, 'WPSEO 13.2', 'This method is deprecated.' );
[329] Fix | Delete
wpseo_ajax_json_echo_die( '' );
[330] Fix | Delete
}
[331] Fix | Delete
[332] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function