diff options
Diffstat (limited to 'plugins/jetpack/modules/wordads/php')
-rw-r--r-- | plugins/jetpack/modules/wordads/php/admin.php | 1 | ||||
-rw-r--r-- | plugins/jetpack/modules/wordads/php/api.php | 32 | ||||
-rw-r--r-- | plugins/jetpack/modules/wordads/php/params.php | 47 | ||||
-rw-r--r-- | plugins/jetpack/modules/wordads/php/widgets.php | 28 |
4 files changed, 69 insertions, 39 deletions
diff --git a/plugins/jetpack/modules/wordads/php/admin.php b/plugins/jetpack/modules/wordads/php/admin.php index 0d668758..b7071666 100644 --- a/plugins/jetpack/modules/wordads/php/admin.php +++ b/plugins/jetpack/modules/wordads/php/admin.php @@ -19,6 +19,7 @@ class WordAds_Admin { /** * Output the API connection debug + * * @since 4.5.0 */ function debug_output() { 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 ); } } } diff --git a/plugins/jetpack/modules/wordads/php/params.php b/plugins/jetpack/modules/wordads/php/params.php index cb50023a..5443ff48 100644 --- a/plugins/jetpack/modules/wordads/php/params.php +++ b/plugins/jetpack/modules/wordads/php/params.php @@ -13,24 +13,27 @@ class WordAds_Params { 'wordads_approved' => false, 'wordads_active' => false, 'wordads_house' => true, + 'wordads_unsafe' => false, 'enable_header_ad' => true, 'wordads_second_belowpost' => true, 'wordads_display_front_page' => true, 'wordads_display_post' => true, 'wordads_display_page' => true, 'wordads_display_archive' => true, + 'wordads_custom_adstxt' => '', ); // grab settings, or set as default if it doesn't exist $this->options = array(); foreach ( $settings as $setting => $default ) { $option = get_option( $setting, null ); + if ( is_null( $option ) ) { update_option( $setting, $default, true ); $option = $default; } - $this->options[$setting] = (bool) $option; + $this->options[ $setting ] = 'wordads_custom_adstxt' !== $setting ? (bool) $option : $option; } $host = 'localhost'; @@ -43,16 +46,16 @@ class WordAds_Params { $this->url = substr( $this->url, 0, strpos( $this->url, '?' ) ); } - $this->cloudflare = self::is_cloudflare(); - $this->blog_id = Jetpack::get_option( 'id', 0 ); - $this->mobile_device = jetpack_is_mobile( 'any', true ); + $this->cloudflare = self::is_cloudflare(); + $this->blog_id = Jetpack::get_option( 'id', 0 ); + $this->mobile_device = jetpack_is_mobile( 'any', true ); $this->targeting_tags = array( - 'WordAds' => 1, - 'BlogId' => Jetpack::is_development_mode() ? 0 : Jetpack_Options::get_option( 'id' ), - 'Domain' => esc_js( parse_url( home_url(), PHP_URL_HOST ) ), - 'PageURL' => esc_js( $this->url ), - 'LangId' => false !== strpos( get_bloginfo( 'language' ), 'en' ) ? 1 : 0, // TODO something else? - 'AdSafe' => 1, // TODO + 'WordAds' => 1, + 'BlogId' => Jetpack::is_development_mode() ? 0 : Jetpack_Options::get_option( 'id' ), + 'Domain' => esc_js( parse_url( home_url(), PHP_URL_HOST ) ), + 'PageURL' => esc_js( $this->url ), + 'LangId' => false !== strpos( get_bloginfo( 'language' ), 'en' ) ? 1 : 0, // TODO something else? + 'AdSafe' => 1, // TODO ); } @@ -94,6 +97,7 @@ class WordAds_Params { /** * Returns the user's device (see user-agent.php) or 'desktop' + * * @return string user device * * @since 4.5.0 @@ -124,17 +128,17 @@ class WordAds_Params { if ( self::is_static_home() ) { $this->page_type = 'static_home'; - } else if ( is_home() ) { + } elseif ( is_home() ) { $this->page_type = 'home'; - } else if ( is_page() ) { + } elseif ( is_page() ) { $this->page_type = 'page'; - } else if ( is_single() ) { + } elseif ( is_single() ) { $this->page_type = 'post'; - } else if ( is_search() ) { + } elseif ( is_search() ) { $this->page_type = 'search'; - } else if ( is_category() ) { + } elseif ( is_category() ) { $this->page_type = 'category'; - } else if ( is_archive() ) { + } elseif ( is_archive() ) { $this->page_type = 'archive'; } else { $this->page_type = 'wtf'; @@ -156,15 +160,15 @@ class WordAds_Params { $page_type_ipw = 6; if ( self::is_static_home() || is_home() || is_front_page() ) { $page_type_ipw = 0; - } else if ( is_page() ) { + } elseif ( is_page() ) { $page_type_ipw = 2; - } else if ( is_singular() ) { + } elseif ( is_singular() ) { $page_type_ipw = 1; - } else if ( is_search() ) { + } elseif ( is_search() ) { $page_type_ipw = 4; - } else if ( is_category() || is_tag() || is_archive() || is_author() ) { + } elseif ( is_category() || is_tag() || is_archive() || is_author() ) { $page_type_ipw = 3; - } else if ( is_404() ) { + } elseif ( is_404() ) { $page_type_ipw = 5; } @@ -174,6 +178,7 @@ class WordAds_Params { /** * Returns true if page is static home + * * @return boolean true if page is static home * * @since 4.5.0 diff --git a/plugins/jetpack/modules/wordads/php/widgets.php b/plugins/jetpack/modules/wordads/php/widgets.php index f4eb90b8..782c2dcd 100644 --- a/plugins/jetpack/modules/wordads/php/widgets.php +++ b/plugins/jetpack/modules/wordads/php/widgets.php @@ -8,7 +8,7 @@ class WordAds_Sidebar_Widget extends WP_Widget { private static $allowed_tags = array( 'mrec', 'wideskyscraper' ); - private static $num_widgets = 0; + private static $num_widgets = 0; function __construct() { parent::__construct( @@ -16,8 +16,8 @@ class WordAds_Sidebar_Widget extends WP_Widget { /** This filter is documented in modules/widgets/facebook-likebox.php */ apply_filters( 'jetpack_widget_name', 'Ads' ), array( - 'description' => __( 'Insert an ad unit wherever you can place a widget.', 'jetpack' ), - 'customize_selective_refresh' => true + 'description' => __( 'Insert an ad unit wherever you can place a widget.', 'jetpack' ), + 'customize_selective_refresh' => true, ) ); } @@ -33,10 +33,10 @@ class WordAds_Sidebar_Widget extends WP_Widget { } self::$num_widgets++; - $about = __( 'Advertisements', 'jetpack' ); - $width = WordAds::$ad_tag_ids[$instance['unit']]['width']; - $height = WordAds::$ad_tag_ids[$instance['unit']]['height']; - $unit_id = 1 == self::$num_widgets ? 3 : self::$num_widgets + 3; // 2nd belowpost is '4' + $about = __( 'Advertisements', 'jetpack' ); + $width = WordAds::$ad_tag_ids[ $instance['unit'] ]['width']; + $height = WordAds::$ad_tag_ids[ $instance['unit'] ]['height']; + $unit_id = 1 == self::$num_widgets ? 3 : self::$num_widgets + 3; // 2nd belowpost is '4' $section_id = 0 === $wordads->params->blog_id ? WORDADS_API_TEST_ID : $wordads->params->blog_id . $unit_id; @@ -46,7 +46,7 @@ class WordAds_Sidebar_Widget extends WP_Widget { $unit = 'mrec'; if ( 'leaderboard' == $instance['unit'] && ! $this->params->mobile_device ) { $unit = 'leaderboard'; - } else if ( 'wideskyscraper' == $instance['unit'] ) { + } elseif ( 'wideskyscraper' == $instance['unit'] ) { $unit = 'widesky'; } @@ -80,15 +80,15 @@ HTML; <select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'unit' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'unit' ) ); ?>"> <?php foreach ( WordAds::$ad_tag_ids as $ad_unit => $properties ) { - if ( ! in_array( $ad_unit, self::$allowed_tags ) ) { - continue; - } + if ( ! in_array( $ad_unit, self::$allowed_tags ) ) { + continue; + } - $splits = explode( '_', $properties['tag'] ); + $splits = explode( '_', $properties['tag'] ); $unit_pretty = "{$splits[0]} {$splits[1]}"; - $selected = selected( $ad_unit, $unit, false ); + $selected = selected( $ad_unit, $unit, false ); echo "<option value='", esc_attr( $ad_unit ) ,"' ", $selected, '>', esc_html( $unit_pretty ) , '</option>'; - } + } ?> </select> </p> |