View IndexNow Insights Of WordPress site in Bing Webmaster Tools

This commit is contained in:
dareddyM 2024-03-04 14:32:23 +05:30
Родитель 9b749d513d
Коммит ca6f6652d0
7 изменённых файлов: 114 добавлений и 4 удалений

Просмотреть файл

@ -40,6 +40,9 @@ We are providing a limited number of URLs submitted on the WordPress dashboard (
Indexing of URLs is specific and dependent on each search engines rules, please reach out to individual search engine for debugging and resolution.
### 1.0.2
- Allow plugin owners of WordPress site to access Indexing Insights in Bing Webmaster tools.
### 1.0.1

Просмотреть файл

@ -217,12 +217,18 @@ class BWT_IndexNow_Admin {
}
/**
* Renders the IndexNow page for path site_url/{apikey}.txt.
* Renders the IndexNow page for path site_url/{apikey}.txt OR site_url/{bwtsiteauthkey}.ttl.
*
*/
public function check_for_indexnow_page() {
$admin_api_key = get_option( $this->prefix . "admin_api_key" );
$api_key = base64_decode( $admin_api_key );
$admin_bwt_site_auth_key = get_option( $this->prefix . "admin_bwt_site_auth_key" );
$bwt_site_auth_key = $admin_bwt_site_auth_key;
$admin_bwt_site_auth_timestamp = get_option($this->prefix . "admin_bwt_site_auth_timestamp");
global $wp;
$current_url = home_url( $wp->request );
@ -231,8 +237,16 @@ class BWT_IndexNow_Admin {
header( 'X-Robots-Tag: noindex' );
status_header( 200 );
esc_html_e($api_key);
exit();
}
if ( isset( $current_url ) && trailingslashit( get_home_url() ) . $admin_bwt_site_auth_key . '.ttl' === $current_url ) {
header( 'Content-Type: text/plain' );
header( 'X-Robots-Tag: noindex' );
status_header( 200 );
esc_html_e($admin_bwt_site_auth_timestamp);
exit();
}
}
}

Просмотреть файл

@ -114,6 +114,15 @@ class BWT_IndexNow_Admin_Routes {
),
) );
$endpoint = '/getIndexNowInsightsUrl/';
register_rest_route( $namespace, $endpoint, array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( $this, 'get_indexnow_insights_url' ),
'permission_callback' => array( $this, 'admin_permissions_check' ),
),
) );
register_rest_route( $namespace, $endpoint, array(
array(
'methods' => \WP_REST_Server::EDITABLE,
@ -167,6 +176,10 @@ class BWT_IndexNow_Admin_Routes {
return $this->try_catch(array($request, array($this, 'call_get_submissions')), array($this, 'validate_api_key'));
}
public function get_indexnow_insights_url( $request ) {
return $this->try_catch(array($request, array($this, 'call_get_indexnow_insights_url')), array($this, 'validate_api_key'));
}
public function resubmit_submissions( $request ) {
return $this->try_catch(array($request, array($this, 'call_resubmit_submissions')), array($this, 'validate_api_key'));
}
@ -534,6 +547,36 @@ class BWT_IndexNow_Admin_Routes {
), 200 );
}
private function call_get_indexnow_insights_url( $request, $admin_api_key ) {
$bwt_site_auth_key = wp_generate_uuid4();
$updated = update_option( $this->prefix . 'admin_bwt_site_auth_key', $bwt_site_auth_key );
if ($updated == false)
{
return new \WP_REST_Response( array(
'InsightsUrl' => "",
'error_type' => WP_IN_Errors::InvalidRequest
), 200 );
}
$currenttimestamp = time();
$updated = update_option( $this->prefix . 'admin_bwt_site_auth_timestamp', $currenttimestamp );
if ($updated == false)
{
return new \WP_REST_Response( array(
'InsightsUrl' => "",
'error_type' => WP_IN_Errors::InvalidRequest
), 200 );
}
$siteUrl = get_home_url();
$insightsurl = "https://bing.com/webmasters/indexnow?siteUrl=" . $siteUrl . "&itoken=" . base64_encode($bwt_site_auth_key);
return new \WP_REST_Response( array(
'InsightsUrl' => $insightsurl,
'error_type' => WP_IN_Errors::NoError
), 200 );
}
private function call_resubmit_submissions( $request, $admin_api_key ) {
$api_key = base64_decode(($admin_api_key));
$body = $request->get_body();

Просмотреть файл

@ -4,7 +4,7 @@ Plugin link: https://bing.com/indexnow
Tags: seo, crawling
Requires at least: 5.3
Tested up to: 5.8
Stable tag: 1.0.1
Stable tag: 1.0.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.txt
Requires PHP: 5.6.20
@ -60,6 +60,9 @@ Indexing of URLs is specific and dependent on each search engines rules, plea
== Changelog ==
= 1.0.2 =
* Allow plugin owners of WordPress site to access Indexing Insights in Bing Webmaster tools.
= 1.0.1 =
* Moving Admin menu under Settings.
* Text domain fix and minor changes.

Просмотреть файл

@ -11,7 +11,8 @@ import {
RetryFailedSubmissions,
SubmitUrl,
UpdateAutoSubmissionsEnabled,
GetApiKey
GetApiKey,
GetIndexNowInsightsUrl
} from "./withDashboardData";
import { ShimmeredDetailsList } from "@fluentui/react/lib/ShimmeredDetailsList";
import {
@ -27,9 +28,11 @@ import {
IGetApiSettingsResponse,
IGetAllSubmissionsResponse,
UrlSubmission,
IGetInsightsUrlResponse,
} from "./Interfaces";
import { Card } from "./Card";
import { StringConstants, ApiKeyRegex, SubmitUrlRegex } from "../Constants";
import { IHttpResponse } from "./IndexNowAPIHelper";
interface IDashboardProps {
addBanner: (str: string) => void;
@ -212,6 +215,19 @@ export const Dashboard: React.FunctionComponent<IDashboardProps> = (props) => {
);
};
// Function handler for fetching URL for view Indexing Insights to Bing webmaster tools.
const viewInsightsOnClick = (
event: React.MouseEvent<HTMLElement, MouseEvent>
) => {
Promise.resolve(GetIndexNowInsightsUrl()).then(
(response : IHttpResponse<IGetInsightsUrlResponse>) => {
if (response && response.data) {
window.open(response.data?.InsightsUrl, "_blank")
}
}
);
};
const onClickUpdateAutoSubmissions = (
event: React.MouseEvent<HTMLElement, MouseEvent>
) => {
@ -282,6 +298,21 @@ export const Dashboard: React.FunctionComponent<IDashboardProps> = (props) => {
(modalState !== DashboardModalState.Hidden ? " darken" : "")
}
>
<div className="sectionTitleContainer">
<h2 className="sectionTitle">IndexNow Insights in Bing Webmaster tools</h2>
</div>
<div className="indexnow-CardRow">
<div className="indexnow-CardColumn indexnow-CardColumn-1 indexnow-UrlSubmissions">
<Card tooltip="This feature allows you to view Indexing insights of your site in Bing webmaster tools" leadingIconName="Send" title="Indexnow Insights">
<p className="cardDescription">
IndexNow Insights feature in Bing Webmaster tools can be used to monitor the indexing status and performance of the URLs submitted via IndexNow on Bing.
</p>
<p style={{ marginLeft: "25px" }} >
<DefaultButton onClick={viewInsightsOnClick} className="button submitButton" text="View Indexing Insights" />
</p>
</Card>
</div>
</div>
<div className="indexnow-CardRow">
<div className="indexnow-CardColumn indexnow-CardColumn-2">
<Card

Просмотреть файл

@ -80,3 +80,8 @@ export interface SubmissionErrors {
status: string;
error_msg: string;
}
export interface IGetInsightsUrlResponse extends ApiResponse {
InsightsUrl: string;
error_type: string;
}

Просмотреть файл

@ -13,6 +13,7 @@ import {
ISetAutoSubmissionEnabledResponse,
ISetAutoSubmissionEnabledRequest,
UrlSubmission,
IGetInsightsUrlResponse,
} from "./Interfaces";
export async function GetApiKey() {
@ -118,3 +119,13 @@ export async function SubmitUrl(url: string) {
);
return response;
}
export async function GetIndexNowInsightsUrl() {
let response: IHttpResponse<IGetInsightsUrlResponse>;
const url = `getIndexNowInsightsUrl`;
response = await useFetch<IGetInsightsUrlResponse>(url).catch((err) => {
console.error("Error while fetching login URL of Bing webmaster tools.");
return err;
});
return response;
}