ajax.php
2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* @package Admin
*/
if ( !defined('WPSEO_VERSION') ) {
header('HTTP/1.0 403 Forbidden');
die;
}
/**
* Function used from AJAX calls, takes it variables from $_POST, dies on exit.
*/
function wpseo_set_option() {
if ( !current_user_can( 'manage_options' ) )
die( '-1' );
check_ajax_referer( 'wpseo-setoption' );
$option = esc_attr( $_POST['option'] );
if ( $option != 'page_comments' )
die( '-1' );
update_option( $option, 0 );
die( '1' );
}
add_action( 'wp_ajax_wpseo_set_option', 'wpseo_set_option' );
/**
* Function used to remove the admin notices for several purposes, dies on exit.
*/
function wpseo_set_ignore() {
if ( !current_user_can( 'manage_options' ) )
die( '-1' );
check_ajax_referer( 'wpseo-ignore' );
$options = get_option( 'wpseo' );
$options['ignore_' . $_POST['option']] = 'ignore';
update_option( 'wpseo', $options );
die( '1' );
}
add_action( 'wp_ajax_wpseo_set_ignore', 'wpseo_set_ignore' );
/**
* Function used to remove the admin notices for several purposes, dies on exit.
*/
function wpseo_kill_blocking_files() {
if ( !current_user_can( 'manage_options' ) )
die( '-1' );
check_ajax_referer( 'wpseo-blocking-files' );
$message = 'There were no files to delete.';
$options = get_option( 'wpseo' );
if ( isset( $options['blocking_files'] ) && is_array( $options['blocking_files'] ) && count( $options['blocking_files'] ) > 0 ) {
$message = 'success';
foreach ( $options['blocking_files'] as $k => $file ) {
if ( !@unlink( $file ) )
$message = __( 'Some files could not be removed. Please remove them via FTP.', 'wordpress-seo' );
else
unset( $options['blocking_files'][$k] );
}
update_option( 'wpseo', $options );
}
die( $message );
}
add_action( 'wp_ajax_wpseo_kill_blocking_files', 'wpseo_kill_blocking_files' );
/**
* Retrieve the suggestions from the Google Suggest API and return them to be
* used in the suggest box within the plugin. Dies on exit.
*/
function wpseo_get_suggest() {
check_ajax_referer( 'wpseo-get-suggest' );
$term = urlencode( $_GET['term'] );
$result = wp_remote_get( 'http://www.google.com/complete/search?output=toolbar&q=' . $term );
preg_match_all( '`suggestion data="([^"]+)"/>`u', $result['body'], $matches );
$return_arr = array();
foreach ( $matches[1] as $match ) {
$return_arr[] = html_entity_decode( $match, ENT_COMPAT, "UTF-8" );
}
echo json_encode( $return_arr );
die();
}
add_action( 'wp_ajax_wpseo_get_suggest', 'wpseo_get_suggest' );