@@ -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 /**
0 commit comments