Skip to content

Instantly share code, notes, and snippets.

@scofennell
Last active January 21, 2021 17:27
Show Gist options
  • Save scofennell/652811d9f7f6df719dfd995fe0343537 to your computer and use it in GitHub Desktop.
Save scofennell/652811d9f7f6df719dfd995fe0343537 to your computer and use it in GitHub Desktop.
Ad Exclude
<?php
/**
* Determine if a widget should be hidden from QA.
*
* @param string $widget_id The ID for this widget instance.
* @return boolean Returns TRUE if the widget should be hidden from QA, else FALSE.
*/
static function is_widget_hidden_from_qa( $widget_id ) {
$widget_type = self::get_widget_type( $widget_id );
// Let's figure out if it's an ad widget.
$widget_types_that_might_contain_ads = array(
// The widget type => the widget setting that'd contain an ad.
'custom_html' => 'content',
'text' => 'text',
);
// Is this widget the type of widget that might contain an ad?
if( array_key_exists( $widget_type, $widget_types_that_might_contain_ads ) ) {
// What do ads tend to contain?
$ad_blacklist = array(
'adserve',
'adbutler',
);
// Where we'd look in the settings for this widget.
$key = $widget_types_that_might_contain_ads[ $widget_type ];
// The value for that setting that might contain an ad.
$val = self::get_setting_of_widget( $widget_id, $key );
// Are any of the ad-like words in the widget setting?
foreach( $ad_blacklist as $black ) {
if( stristr( $val, $black ) ) {
return TRUE;
}
}
}
$val = self::get_setting_of_widget( $widget_id, 'hide_from_qa' );
if( empty( $val ) ) { return FALSE; }
return TRUE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment