Archived
Updates
This commit is contained in:
1 parent
70d2335bba
commit
7428b67da5
1086 files changed
+94145
-59082
No files matched your search
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Admin
|
||||
* @package WPSEO\Admin
|
||||
*/
|
||||
|
||||
if ( ! defined( 'WPSEO_VERSION' ) ) {
|
||||
@@ -9,6 +9,20 @@ if ( ! defined( 'WPSEO_VERSION' ) ) {
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo this whole thing should probably be a proper class.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Convenience function to JSON encode and echo resuls and then die
|
||||
*
|
||||
* @param array $results
|
||||
*/
|
||||
function wpseo_ajax_json_echo_die( $results ) {
|
||||
echo json_encode( $results );
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function used from AJAX calls, takes it variables from $_POST, dies on exit.
|
||||
*/
|
||||
@@ -19,7 +33,7 @@ function wpseo_set_option() {
|
||||
|
||||
check_ajax_referer( 'wpseo-setoption' );
|
||||
|
||||
$option = sanitize_text_field( $_POST['option'] );
|
||||
$option = sanitize_text_field( WPSEO_Utils::filter_input( INPUT_POST, 'option' ) );
|
||||
if ( $option !== 'page_comments' ) {
|
||||
die( '-1' );
|
||||
}
|
||||
@@ -41,7 +55,7 @@ function wpseo_set_ignore() {
|
||||
check_ajax_referer( 'wpseo-ignore' );
|
||||
|
||||
$options = get_option( 'wpseo' );
|
||||
$ignore_key = sanitize_text_field( $_POST['option'] );
|
||||
$ignore_key = sanitize_text_field( WPSEO_Utils::filter_input( INPUT_POST, 'option' ) );
|
||||
$options[ 'ignore_' . $ignore_key ] = true;
|
||||
update_option( 'wpseo', $options );
|
||||
die( '1' );
|
||||
@@ -70,7 +84,7 @@ function wpseo_kill_blocking_files() {
|
||||
}
|
||||
else {
|
||||
unset( $options['blocking_files'][ $k ] );
|
||||
$files_removed++;
|
||||
$files_removed ++;
|
||||
}
|
||||
}
|
||||
if ( $files_removed > 0 ) {
|
||||
@@ -90,7 +104,7 @@ add_action( 'wp_ajax_wpseo_kill_blocking_files', 'wpseo_kill_blocking_files' );
|
||||
function wpseo_get_suggest() {
|
||||
check_ajax_referer( 'wpseo-get-suggest' );
|
||||
|
||||
$term = urlencode( $_GET['term'] );
|
||||
$term = urlencode( WPSEO_Utils::filter_input( INPUT_GET, 'term' ) );
|
||||
$result = wp_remote_get( 'https://www.google.com/complete/search?output=toolbar&q=' . $term );
|
||||
|
||||
$return_arr = array();
|
||||
@@ -104,8 +118,7 @@ function wpseo_get_suggest() {
|
||||
}
|
||||
}
|
||||
}
|
||||
echo json_encode( $return_arr );
|
||||
die();
|
||||
wpseo_ajax_json_echo_die( $return_arr );
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_wpseo_get_suggest', 'wpseo_get_suggest' );
|
||||
@@ -114,11 +127,12 @@ add_action( 'wp_ajax_wpseo_get_suggest', 'wpseo_get_suggest' );
|
||||
* Used in the editor to replace vars for the snippet preview
|
||||
*/
|
||||
function wpseo_ajax_replace_vars() {
|
||||
global $post;
|
||||
check_ajax_referer( 'wpseo-replace-vars' );
|
||||
|
||||
$post = get_post( $_POST['post_id'] );
|
||||
$post = get_post( intval( WPSEO_Utils::filter_input( INPUT_POST, 'post_id' ) ) );
|
||||
$omit = array( 'excerpt', 'excerpt_only', 'title' );
|
||||
echo wpseo_replace_vars( stripslashes( $_POST['string'] ), $post, $omit );
|
||||
echo wpseo_replace_vars( stripslashes( WPSEO_Utils::filter_input( INPUT_POST, 'string' ) ), $post, $omit );
|
||||
die;
|
||||
}
|
||||
|
||||
@@ -128,40 +142,54 @@ add_action( 'wp_ajax_wpseo_replace_vars', 'wpseo_ajax_replace_vars' );
|
||||
* Save an individual SEO title from the Bulk Editor.
|
||||
*/
|
||||
function wpseo_save_title() {
|
||||
check_ajax_referer( 'wpseo-bulk-editor' );
|
||||
|
||||
$new_title = $_POST['new_value'];
|
||||
$id = intval( $_POST['wpseo_post_id'] );
|
||||
$original_title = $_POST['existing_value'];
|
||||
|
||||
$results = wpseo_upsert_new_title( $id, $new_title, $original_title );
|
||||
|
||||
echo json_encode( $results );
|
||||
die();
|
||||
wpseo_save_what( 'title' );
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_wpseo_save_title', 'wpseo_save_title' );
|
||||
|
||||
/**
|
||||
* Helper function for updating an existing seo title or create a new one
|
||||
* if it doesn't already exist.
|
||||
* Save an individual meta description from the Bulk Editor.
|
||||
*/
|
||||
function wpseo_upsert_new_title( $post_id, $new_title, $original_title ) {
|
||||
function wpseo_save_description() {
|
||||
wpseo_save_what( 'metadesc' );
|
||||
}
|
||||
|
||||
$meta_key = WPSEO_Meta::$meta_prefix . 'title';
|
||||
$return_key = 'title';
|
||||
return wpseo_upsert_meta( $post_id, $new_title, $original_title, $meta_key, $return_key );
|
||||
add_action( 'wp_ajax_wpseo_save_metadesc', 'wpseo_save_description' );
|
||||
|
||||
/**
|
||||
* Save titles & descriptions
|
||||
*
|
||||
* @param string $what
|
||||
*/
|
||||
function wpseo_save_what( $what ) {
|
||||
check_ajax_referer( 'wpseo-bulk-editor' );
|
||||
|
||||
$new = WPSEO_Utils::filter_input( INPUT_POST, 'new_value' );
|
||||
$post_id = intval( WPSEO_Utils::filter_input( INPUT_POST, 'wpseo_post_id' ) );
|
||||
$original = WPSEO_Utils::filter_input( INPUT_POST, 'existing_value' );
|
||||
|
||||
$results = wpseo_upsert_new( $what, $post_id, $new, $original );
|
||||
|
||||
wpseo_ajax_json_echo_die( $results );
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to update a post's meta data, returning relevant information
|
||||
* about the information updated and the results or the meta update.
|
||||
*
|
||||
* @param int $post_id
|
||||
* @param string $new_meta_value
|
||||
* @param string $orig_meta_value
|
||||
* @param string $meta_key
|
||||
* @param string $return_key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function wpseo_upsert_meta( $post_id, $new_meta_value, $orig_meta_value, $meta_key, $return_key ) {
|
||||
|
||||
$post_id = intval( $post_id );
|
||||
$sanitized_new_meta_value = wp_strip_all_tags( $new_meta_value );
|
||||
$orig_meta_value = wp_strip_all_tags( $orig_meta_value );
|
||||
$post_id = intval( $post_id );
|
||||
$sanitized_new_meta_value = wp_strip_all_tags( $new_meta_value );
|
||||
$orig_meta_value = wp_strip_all_tags( $orig_meta_value );
|
||||
|
||||
$upsert_results = array(
|
||||
'status' => 'success',
|
||||
@@ -224,73 +252,69 @@ function wpseo_upsert_meta( $post_id, $new_meta_value, $orig_meta_value, $meta_k
|
||||
* Save all titles sent from the Bulk Editor.
|
||||
*/
|
||||
function wpseo_save_all_titles() {
|
||||
check_ajax_referer( 'wpseo-bulk-editor' );
|
||||
|
||||
$new_titles = $_POST['items'];
|
||||
$original_titles = $_POST['existing_items'];
|
||||
|
||||
$results = array();
|
||||
|
||||
if ( is_array( $new_titles ) && $new_titles !== array() ) {
|
||||
foreach ( $new_titles as $id => $new_title ) {
|
||||
$original_title = $original_titles[ $id ];
|
||||
$results[] = wpseo_upsert_new_title( $id, $new_title, $original_title );
|
||||
}
|
||||
}
|
||||
echo json_encode( $results );
|
||||
die();
|
||||
wpseo_save_all( 'title' );
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_wpseo_save_all_titles', 'wpseo_save_all_titles' );
|
||||
|
||||
/**
|
||||
* Save an individual meta description from the Bulk Editor.
|
||||
*/
|
||||
function wpseo_save_description() {
|
||||
|
||||
check_ajax_referer( 'wpseo-bulk-editor' );
|
||||
|
||||
$new_metadesc = $_POST['new_value'];
|
||||
$id = intval( $_POST['wpseo_post_id'] );
|
||||
$original_metadesc = $_POST['existing_value'];
|
||||
|
||||
$results = wpseo_upsert_new_description( $id, $new_metadesc, $original_metadesc );
|
||||
|
||||
echo json_encode( $results );
|
||||
die();
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_wpseo_save_metadesc', 'wpseo_save_description' );
|
||||
|
||||
/**
|
||||
* Helper function to create or update a post's meta description.
|
||||
*/
|
||||
function wpseo_upsert_new_description( $post_id, $new_metadesc, $original_metadesc ) {
|
||||
|
||||
$meta_key = WPSEO_Meta::$meta_prefix . 'metadesc';
|
||||
$return_key = 'metadesc';
|
||||
return wpseo_upsert_meta( $post_id, $new_metadesc, $original_metadesc, $meta_key, $return_key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save all description sent from the Bulk Editor.
|
||||
*/
|
||||
function wpseo_save_all_descriptions() {
|
||||
check_ajax_referer( 'wpseo-bulk-editor' );
|
||||
|
||||
$new_metadescs = $_POST['items'];
|
||||
$original_metadescs = $_POST['existing_items'];
|
||||
|
||||
$results = array();
|
||||
|
||||
if ( is_array( $new_metadescs ) && $new_metadescs !== array() ) {
|
||||
foreach ( $new_metadescs as $id => $new_metadesc ) {
|
||||
$original_metadesc = $original_metadescs[ $id ];
|
||||
$results[] = wpseo_upsert_new_description( $id, $new_metadesc, $original_metadesc );
|
||||
}
|
||||
}
|
||||
echo json_encode( $results );
|
||||
die();
|
||||
wpseo_save_all( 'metadesc' );
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_wpseo_save_all_descriptions', 'wpseo_save_all_descriptions' );
|
||||
|
||||
/**
|
||||
* Utility function to save values
|
||||
*
|
||||
* @param string $what
|
||||
*/
|
||||
function wpseo_save_all( $what ) {
|
||||
check_ajax_referer( 'wpseo-bulk-editor' );
|
||||
|
||||
// @todo the WPSEO Utils class can't filter arrays in POST yet.
|
||||
$new_values = $_POST['items'];
|
||||
$original_values = $_POST['existing_items'];
|
||||
|
||||
$results = array();
|
||||
|
||||
if ( is_array( $new_values ) && $new_values !== array() ) {
|
||||
foreach ( $new_values as $post_id => $new_value ) {
|
||||
$original_value = $original_values[ $post_id ];
|
||||
$results[] = wpseo_upsert_new( $what, $post_id, $new_value, $original_value );
|
||||
}
|
||||
}
|
||||
wpseo_ajax_json_echo_die( $results );
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a new value
|
||||
*
|
||||
* @param string $what
|
||||
* @param int $post_id
|
||||
* @param string $new
|
||||
* @param string $original
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function wpseo_upsert_new( $what, $post_id, $new, $original ) {
|
||||
$meta_key = WPSEO_Meta::$meta_prefix . $what;
|
||||
|
||||
return wpseo_upsert_meta( $post_id, $new, $original, $meta_key, $what );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an export and return the URL
|
||||
*/
|
||||
function wpseo_get_export() {
|
||||
check_ajax_referer( 'wpseo-export' );
|
||||
|
||||
$include_taxonomy = ( WPSEO_Utils::filter_input( INPUT_POST, 'include_taxonomy' ) === 'true' ) ? true : false;
|
||||
$export = new WPSEO_Export( $include_taxonomy );
|
||||
|
||||
wpseo_ajax_json_echo_die( $export->get_results() );
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_wpseo_export', 'wpseo_get_export' );
|
||||
Reference in new issue
Block a user