Skip to content

Commit 82113c7

Browse files
author
Balazs P
authored
Merge pull request #28 from rankmath/v1.1.13
2 parents 4c0724e + e607c79 commit 82113c7

File tree

6 files changed

+42
-69
lines changed

6 files changed

+42
-69
lines changed

assets/js/console.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,25 @@ jQuery(document).ready(function($) {
116116
});
117117

118118
$('#indexnow_reset_key').on( 'click', function( e ) {
119-
e.preventDefault()
120-
var originalValue = $( '#giapi_indexnow_api_key' ).val()
121-
$( '#giapi_indexnow_api_key' ).val( '...' )
119+
e.preventDefault();
120+
let originalValue = $( '#giapi_indexnow_api_key' ).val();
121+
$( '#giapi_indexnow_api_key' ).val( '...' );
122122
$.ajax( {
123-
url: ajaxurl,
124-
type: 'GET',
125-
data: { action: 'rm_giapi_reset_key', _ajax_nonce: $('#reset_key_nonce').val() },
123+
url: rankMath.indexNow.restUrl + '/resetKey',
124+
type: 'POST',
125+
beforeSend( xhr ) {
126+
xhr.setRequestHeader( 'X-WP-Nonce', rankMath.api.nonce );
127+
},
126128
success: function( response ) {
127129
$( '#giapi_indexnow_api_key' ).val( response.key );
128130
$( '#indexnow_api_key_location').text( response.location );
129131
$( '#indexnow_check_key' ).attr( 'href', response.location );
130132
},
131133
error: function( response ) {
132-
$( '#giapi_indexnow_api_key' ).val( originalValue );
134+
$( '#giapi_indexnow_api_key' ).val( originalValue )
133135
},
134-
} );
135-
} );
136+
} )
137+
} )
136138

137139
});
138140

assets/js/console.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/class-instant-indexing.php

Lines changed: 21 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class RM_GIAPI {
1515
*
1616
* @var string
1717
*/
18-
public $version = '1.1.12';
18+
public $version = '1.1.13';
1919

2020
/**
2121
* Holds the admin menu hook suffix for the "dummy" dashboard.
@@ -156,7 +156,6 @@ public function __construct() {
156156
add_action( 'admin_footer', [ $this, 'admin_footer' ], 20 );
157157
add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
158158
add_action( 'wp_ajax_rm_giapi', [ $this, 'ajax_rm_giapi' ] );
159-
add_action( 'wp_ajax_rm_giapi_reset_key', [ $this, 'ajax_reset_key' ] );
160159
add_action( 'wp_ajax_rm_giapi_limits', [ $this, 'ajax_get_limits' ] );
161160
add_action( 'admin_init', [ $this, 'rm_missing_admin_notice_error' ], 20, 1 );
162161
add_action( 'admin_notices', [ $this, 'display_notices' ], 10, 1 );
@@ -407,6 +406,25 @@ public function send_to_api( $url_input, $action, $is_manual = true ) {
407406
}
408407
} else {
409408
// IndexNow submit URL.
409+
410+
/**
411+
* Filter the URL to be submitted to IndexNow.
412+
* Returning false will prevent the URL from being submitted.
413+
*
414+
* @param bool $is_manual Whether the URL is submitted manually by the user.
415+
*/
416+
$url_input = apply_filters( 'rank_math/instant_indexing/submit_url', $url_input, $is_manual );
417+
if ( ! $url_input ) {
418+
return false;
419+
}
420+
421+
if ( ! $is_manual ) {
422+
$logs = array_values( array_reverse( $this->rmapi->get_log() ) );
423+
if ( ! empty( $logs[0] ) && $logs[0]['url'] === $url_input[0] && time() - $logs[0]['time'] < 15 ) {
424+
return false;
425+
}
426+
}
427+
410428
$request = $this->rmapi->submit( $url_input, $is_manual );
411429
if ( $request ) {
412430
$data = [
@@ -562,65 +580,13 @@ public function ajax_get_limits() {
562580
die();
563581
}
564582

565-
/**
566-
* AJAX handler to generate and save a new API key.
567-
*
568-
* @return void
569-
*/
570-
public function ajax_reset_key() {
571-
check_ajax_referer( 'rm_giapi_reset_key' );
572-
573-
if ( ! current_user_can( apply_filters( 'rank_math/indexing_api/capability', 'manage_options' ) ) ) {
574-
die( '0' );
575-
}
576-
577-
$this->reset_indexnow_key();
578-
579-
$settings = get_option( 'rank-math-options-instant-indexing', [] );
580-
$key = $settings['indexnow_api_key'];
581-
$location = trailingslashit( home_url() ) . $key . '.txt';
582-
583-
wp_send_json(
584-
[
585-
'status' => 'ok',
586-
'key' => $key,
587-
'location' => $location,
588-
]
589-
);
590-
die();
591-
}
592-
593-
/**
594-
* Generate new API key and save it.
595-
*
596-
* @return void
597-
*/
598-
public function reset_indexnow_key() {
599-
$settings = RankMath\Helper::get_settings( 'instant_indexing', [] );
600-
$settings['indexnow_api_key'] = $this->generate_indexnow_key();
601-
$this->api_key = $settings['indexnow_api_key'];
602-
update_option( 'rank-math-options-instant-indexing', $settings );
603-
}
604-
605-
/**
606-
* Generate new API key.
607-
*
608-
* @return string
609-
*/
610-
public function generate_indexnow_key() {
611-
$api_key = wp_generate_uuid4();
612-
$api_key = preg_replace( '[-]', '', $api_key );
613-
614-
return $api_key;
615-
}
616-
617583
/**
618584
* Normalize input URLs.
619585
*
620586
* @return array Input URLs.
621587
*/
622588
public function get_input_urls() {
623-
return array_values( array_filter( array_map( 'trim', explode( "\n", sanitize_textarea_field( wp_unslash( $_POST['url'] ) ) ) ) ) );
589+
return array_values( array_filter( array_map( 'trim', array_map( 'esc_url_raw', explode( "\n", wp_unslash( $_POST['url'] ) ) ) ) ) );
624590
}
625591

626592
/**

instant-indexing.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Instant Indexing
44
* Plugin URI: https://rankmath.com/wordpress/plugin/instant-indexing/
55
* Description: Get your website crawled immediately by Google using their NEW Indexing APIs.
6-
* Version: 1.1.12
6+
* Version: 1.1.13
77
* Author: Rank Math
88
* Author URI: https://s.rankmath.com/home
99
* License: GPL v3

readme.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
Contributors: rankmath
33
Plugin link: https://rankmath.com/wordpress/plugin/instant-indexing/
44
Tags: indexing api, crawling, live streaming, fast indexing, job posting
5-
Tested up to: 5.9
5+
Tested up to: 5.9.2
66
Requires at least: 5.6
77
Requires PHP: 7.2
8-
Stable tag: 1.1.12
8+
Stable tag: 1.1.13
99
License: GPL-2.0+
1010
License URI: https://www.gnu.org/licenses/gpl-2.0.txt
1111

@@ -106,6 +106,11 @@ Technically, yes. That's what the plugin is made to do. But, please note that we
106106

107107
== Changelog ==
108108

109+
= v1.1.13 [Mar 16, 2022] =
110+
* Fixed: special characters getting removed from submitted URL
111+
* Fixed: double IndexNow submissions
112+
* Improved: use reset key REST API endpoint from Rank Math
113+
109114
= v1.1.12 [Feb 08, 2022] =
110115
* Fixed: Can't update IndexNow post types option
111116

views/bing-settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<p class="description"><?php esc_html_e( 'The IndexNow API key proves the ownership of the site. It is generated automatically. You can change the key if it becomes known to third parties.', 'fast-indexing-api' ); ?></p>
3535
</th>
3636
<td>
37-
<input type="text" class="large-text" id="giapi_indexnow_api_key" readonly="readonly" name="giapi_settings[indexnow_api_key]" value="<?php echo esc_attr( $this->rmapi->get_api_key() ); ?>">
37+
<input type="text" class="large-text" id="giapi_indexnow_api_key" readonly="readonly" name="giapi_settings[indexnow_api_key]" value="<?php echo esc_attr( $this->rmapi->get_key() ); ?>">
3838
<br />
3939
<?php echo wp_kses_post( $reset_button ); ?>
4040
<?php echo $reset_nonce; ?>

0 commit comments

Comments
 (0)