summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/modules/wordads/php/api.php')
-rw-r--r--plugins/jetpack/modules/wordads/php/api.php32
1 files changed, 28 insertions, 4 deletions
diff --git a/plugins/jetpack/modules/wordads/php/api.php b/plugins/jetpack/modules/wordads/php/api.php
index 704193ed..34b5235a 100644
--- a/plugins/jetpack/modules/wordads/php/api.php
+++ b/plugins/jetpack/modules/wordads/php/api.php
@@ -11,6 +11,7 @@ class WordAds_API {
/**
* Returns site's WordAds status
+ *
* @return array boolean values for 'approved' and 'active'
*
* @since 4.5.0
@@ -22,22 +23,24 @@ class WordAds_API {
'approved' => true,
'active' => true,
'house' => true,
+ 'unsafe' => false,
);
return self::$wordads_status;
}
- $endpoint = sprintf( '/sites/%d/wordads/status', Jetpack::get_option( 'id' ) );
+ $endpoint = sprintf( '/sites/%d/wordads/status', Jetpack::get_option( 'id' ) );
$wordads_status_response = $response = Jetpack_Client::wpcom_json_api_request_as_blog( $endpoint );
if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
return new WP_Error( 'api_error', __( 'Error connecting to API.', 'jetpack' ), $response );
}
- $body = json_decode( wp_remote_retrieve_body( $response ) );
+ $body = json_decode( wp_remote_retrieve_body( $response ) );
self::$wordads_status = array(
'approved' => $body->approved,
'active' => $body->active,
'house' => $body->house,
+ 'unsafe' => $body->unsafe,
);
return self::$wordads_status;
@@ -45,24 +48,26 @@ class WordAds_API {
/**
* Returns the ads.txt content needed to run WordAds.
+ *
* @return array string contents of the ads.txt file.
*
* @since 6.1.0
*/
public static function get_wordads_ads_txt() {
- $endpoint = sprintf( '/sites/%d/wordads/ads-txt', Jetpack::get_option( 'id' ) );
+ $endpoint = sprintf( '/sites/%d/wordads/ads-txt', Jetpack::get_option( 'id' ) );
$wordads_status_response = $response = Jetpack_Client::wpcom_json_api_request_as_blog( $endpoint );
if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
return new WP_Error( 'api_error', __( 'Error connecting to API.', 'jetpack' ), $response );
}
- $body = json_decode( wp_remote_retrieve_body( $response ) );
+ $body = json_decode( wp_remote_retrieve_body( $response ) );
$ads_txt = str_replace( '\\n', PHP_EOL, $body->adstxt );
return $ads_txt;
}
/**
* Returns status of WordAds approval.
+ *
* @return boolean true if site is WordAds approved
*
* @since 4.5.0
@@ -77,6 +82,7 @@ class WordAds_API {
/**
* Returns status of WordAds active.
+ *
* @return boolean true if ads are active on site
*
* @since 4.5.0
@@ -91,6 +97,7 @@ class WordAds_API {
/**
* Returns status of WordAds house ads.
+ *
* @return boolean true if WP.com house ads should be shown
*
* @since 4.5.0
@@ -103,6 +110,22 @@ class WordAds_API {
return self::$wordads_status['house'] ? '1' : '0';
}
+
+ /**
+ * Returns whether or not this site is safe to run ads on.
+ *
+ * @return boolean true if ads shown not be shown on this site.
+ *
+ * @since 6.5.0
+ */
+ public static function is_wordads_unsafe() {
+ if ( is_null( self::$wordads_status ) ) {
+ self::get_wordads_status();
+ }
+
+ return self::$wordads_status['unsafe'] ? '1' : '0';
+ }
+
/**
* Grab WordAds status from WP.com API and store as option
*
@@ -114,6 +137,7 @@ class WordAds_API {
update_option( 'wordads_approved', self::is_wordads_approved(), true );
update_option( 'wordads_active', self::is_wordads_active(), true );
update_option( 'wordads_house', self::is_wordads_house(), true );
+ update_option( 'wordads_unsafe', self::is_wordads_unsafe(), true );
}
}
}