enqueue_backend();
}
/**
* Load JS and CSS for Backend Area.
*
* @since 1.0.0
* @access public
**/
public function enqueue_backend() {
/** Add admin javascript. */
add_action( 'admin_enqueue_scripts', [ $this, 'add_admin_scripts' ] );
}
/**
* Add JS for admin area.
*
* @return void
**@since 1.0.0
*/
public function add_admin_scripts() {
$screen = get_current_screen();
if ( null === $screen ) { return; }
/** Add styles only on plugin settings page */
if ( ! in_array( $screen->base, Plugin::get_menu_bases(), true ) ) { return; }
wp_enqueue_script( 'jquery-datetimepicker-full', Plugin::get_url() . 'src/Core/Inc/assets/js/jquery.datetimepicker.full' . Plugin::get_suffix() . '.js', [ 'jquery' ], Plugin::get_version(), true );
wp_enqueue_script( 'pp-AdUnlocker-assignments', Plugin::get_url() . 'src/Core/Inc/assets/js/assignments' . Plugin::get_suffix() . '.js', [ 'jquery-datetimepicker-full', 'jquery' ], Plugin::get_version(), true );
/** Add code editor for Custom PHP. */
wp_enqueue_code_editor( ['type' => 'application/x-httpd-php'] );
}
/**
* Generate Assignments Tab.
*
* @since 1.0.0
* @access public
**/
public function add_settings() {
/** Assignments Tab. */
$this->add_settings_base( self::TAB_SLUG );
}
/**
* Render form with all settings fields.
*
* @since 1.0.0
* @access public
*
* @return void
**/
public function do_settings() {
/** No status tab, nothing to do. */
if ( ! $this->is_enabled( self::TAB_SLUG ) ) { return; }
/** Render title. */
$this->render_title( self::TAB_SLUG );
/** Render fields. */
$this->do_settings_base( self::TAB_SLUG );
/** Render Assignments. */
$this->render_assignments();
}
/**
* Render Assignments field.
*
* @since 1.0.0
**/
public function render_assignments() {
/**
* Output options list for select
*/
$options = [];
$defaults = [
'search' => 'Search'
];
$selected = is_array( $options ) ? $options : [ '*' ];
if ( count( $selected ) > 1 && in_array( '*', $selected, true ) ) {
$selected = [ '*' ];
}
// set default options
foreach ( $defaults as $val => $label ) {
$attributes = in_array( $val, $selected, true ) ? [
'value' => $val,
'selected' => 'selected'
] : [ 'value' => $val ];
$options[] = sprintf( '', $attributes["value"], $label );
}
// set pages
if ( $pages = get_pages() ) {
$options[] = '';
}
// set posts
$options[] = '';
// set custom post types
foreach ( array_keys( get_post_types( ['_builtin' => false ] ) ) as $posttype ) {
$obj = get_post_type_object( $posttype );
if ( null === $obj ) { continue; }
$label = ucfirst( $posttype );
if ( $obj->publicly_queryable ) {
$options[] = '';
}
}
// set categories
foreach ( array_keys( get_taxonomies() ) as $tax ) {
if ( in_array( $tax, [ "post_tag", "nav_menu" ] ) ) {
continue;
}
if ( $categories = get_categories( [ 'taxonomy' => $tax ] ) ) {
$options[] = '';
}
}
?>
[assignments]'
value='options['assignments'] ); ?>'>
$day_of_week = date('w');
if( '5' == $day_of_week ) { // Work only on Fridays.
$result = true;
} else {
$result = false;
}
return $result;
options['assignments'];
/** Get assignments for plugin. */
$assignment = json_decode( str_replace('|', '"', $assignments ), false );
if ( ! $assignment ) { return true; } // If no settings - Show plugin Everywhere
/** WordPress Content. */
$wordPressContent = $this->WordPressContent( $assignment );
/** Home Page. */
$homePage = $this->HomePage( $assignment );
/** Menu Items. */
$menuItems = $this->MenuItems( $assignment );
/** Date & Time */
$dateTime = $this->DateTime( $assignment );
/** Languages. */
$sub_results[] = $this->Languages( $assignment );
/** User Roles. */
$userRoles = $this->UserRoles( $assignment );
/** URL. */
$URL = $this->URL( $assignment );
/** Devices. */
$devices = $this->Devices( $assignment );
/** Operating Systems. */
$sub_results[] = $this->OS( $assignment );
/** Browsers. */
$sub_results[] = $this->Browsers( $assignment );
/** IP Addresses. */
$sub_results[] = $this->IPs( $assignment );
/** Custom PHP. */
$PHP = $this->PHP( $assignment );
/** Matching Method. */
return $this->MatchingMethod( $assignment, [$wordPressContent, $homePage, $menuItems, $dateTime, $userRoles, $URL, $devices, $PHP] );
}
/**
* Plugin Assignments - Date & Time.
*
* @param $assignment
*
* @return bool|int
* @since 1.0.0
* @access protected
*/
protected function DateTime( $assignment ) {
/** If no dateTime - ignore. */
if ( $assignment->dateTimeStart === "" || $assignment->dateTimeEnd === "" ) {
return - 1;
}
$time = time();
$s = strtotime( $assignment->dateTimeStart ) - $time;
$e = strtotime( $assignment->dateTimeEnd ) - $time;
switch ( $assignment->dateTime ) {
case 1: // Include
$result = false;
if ( $s <= 0 && $e >= 0 ) {
$result = true;
}
break;
case 2: // Exclude
$result = true;
if ( $s <= 0 && $e >= 0 ) {
$result = false;
}
break;
default: // Ignore
$result = - 1;
break;
}
return $result;
}
/**
* Plugin assignments - Languages.
*
* @param $assignment
*
* @since 1.0.0
* @access protected
*
* @return bool|int
**/
protected function Languages( $assignment ) {
/** If wrong input array - Ignore. */
if ( ! is_array( $assignment->languagesVal ) ) { return - 1; }
switch ( $assignment->languages ) {
case 1: // Include
$result = false;
$locale = get_user_locale();
if ( in_array( $locale, $assignment->languagesVal, true ) ) {
$result = true;
}
break;
case 2: // Exclude
$result = true;
$locale = get_user_locale();
if ( in_array( $locale, $assignment->languagesVal, true ) ) {
$result = false;
}
break;
case 0;
default: // Ignore
$result = - 1;
break;
}
return $result;
}
/**
* Plugin assignments - WordPress Content.
*
* @param $assignment
*
* @since 1.0.0
* @access protected
*
* @return bool|int
**/
protected function WordPressContent( $assignment ) {
$result = - 1;
switch ( $assignment->WPContent ) {
case 0: // Ignore
$result = - 1;
break;
case 1: // Include
$result = $this->check_wordpress_content( false, $assignment );
break;
case 2: // Exclude
$result = $this->check_wordpress_content( true, $assignment );
break;
}
return $result;
}
private function check_wordpress_content( $flag, $assignment ) {
$result = $flag;
if ( ! $assignment->WPContentVal ) {
$result = - 1;
return $result;
} // If no menu items - ignore
$query = $this->getQuery();
foreach ( $query as $q ) {
if ( in_array( $q, $assignment->WPContentVal, true ) ) {
$result = !$flag;
return $result;
}
}
return $result;
}
/**
* Plugin assignments - Home Page.
*
* @param $assignment
*
* @since 1.0.0
* @access protected
*
* @return bool|int
**/
protected function HomePage( $assignment ) {
switch ( $assignment->homePage ) {
case 1: // Include
$result = false;
if ( is_front_page() ) {
$result = true;
}
break;
case 2: // Exclude
$result = true;
if ( is_front_page() ) {
$result = false;
}
break;
default: // Ignore
$result = - 1;
break;
}
return $result;
}
/**
* Plugin assignments - Menu Items.
*
* @param $assignment
*
* @return bool|int
* @since 1.0.0
* @access protected
*/
protected function MenuItems( $assignment ) {
$result = - 1;
// If wrong input array - Ignore
if ( ! is_array( $assignment->menuItemsVal ) ) {
$result = - 1;
return $result;
}
// Current URL
if ( ! isset( $_SERVER["HTTPS"] ) || ( $_SERVER["HTTPS"] !== 'on' ) ) {
$currentUrl = 'http://' . $_SERVER["SERVER_NAME"];
} else {
$currentUrl = 'https://' . $_SERVER["SERVER_NAME"];
}
$currentUrl .= $_SERVER["REQUEST_URI"];
switch ( $assignment->menuItems ) {
case 0: // Ignore
$result = - 1;
break;
case 1: // Include
$result = false;
if ( ! $assignment->menuItemsVal ) {
$result = - 1;
return $result;
} // If no menu items - ignore
$menu_items_arr = []; // Assignments menu items
foreach ( $assignment->menuItemsVal as $val ) {
if ( $val === "" ) {
continue;
}
list( $menuSlug, $menuItemID ) = explode( "+", $val );
$menu_items = wp_get_nav_menu_items( $menuSlug );
$menu_item = wp_filter_object_list( $menu_items, [ 'ID' => $menuItemID ] );
$menu_items_arr[] = reset( $menu_item );
}
foreach ( $menu_items_arr as $mItem ) {
if ( $currentUrl === $mItem->url ) {
$result = true;
return $result;
}
}
break;
case 2: // Exclude
$result = true;
if ( ! $assignment->menuItemsVal ) {
$result = - 1;
return $result;
} // If no menu items - ignore
$menu_items_arr = []; // Assignments menu items
foreach ( $assignment->menuItemsVal as $val ) {
list( $menuSlug, $menuItemID ) = explode( "+", $val );
$menu_items = wp_get_nav_menu_items( $menuSlug );
$menu_item = wp_filter_object_list( $menu_items, [ 'ID' => $menuItemID ] );
$menu_items_arr[] = reset( $menu_item );
}
foreach ( $menu_items_arr as $mItem ) {
if ( $currentUrl === $mItem->url ) {
$result = false;
return $result;
}
}
break;
}
return $result;
}
/**
* Plugin assignments - User Roles.
*
* @param $assignment
*
* @return bool|int
* @since 1.0.0
* @access protected
*/
protected function UserRoles( $assignment ) {
// If wrong input array - Ignore
if ( ! is_array( $assignment->userRolesVal ) ) {
return - 1;
}
include_once( ABSPATH . 'wp-includes/pluggable.php' );
switch ( $assignment->userRoles ) {
case 1: // Include
$result = false;
$user = wp_get_current_user();
if ( null === $user ) { return false; }
foreach ( $user->roles as $role ) {
if ( in_array( $role, $assignment->userRolesVal, true ) ) {
$result = true;
}
}
break;
case 2: // Exclude
$result = true;
$user = wp_get_current_user();
foreach ( $user->roles as $role ) {
if ( in_array( $role, $assignment->userRolesVal, true ) ) {
$result = false;
}
}
break;
default: // Ignore
$result = - 1;
break;
}
return $result;
}
/**
* Plugin assignments - Devices.
*
* @param $assignment
*
* @return bool|int
* @since 1.0.0
* @access protected
*/
protected function Devices( $assignment ) {
$detect = new MobileDetect;
/** Detect current user device. */
$device = 'desktop';
if ( $detect->isTablet() ) {
$device = 'tablet';
}
if ( $detect->isMobile() && ! $detect->isTablet() ) {
$device = 'mobile';
}
/** If wrong input array - Ignore. */
if ( ! is_array( $assignment->devicesVal ) ) {
return - 1;
}
switch ( $assignment->devices ) {
case 1: // Include
$result = false;
if ( in_array( $device, $assignment->devicesVal, true ) ) {
$result = true;
}
break;
case 2: // Exclude
$result = true;
if ( in_array( $device, $assignment->devicesVal, true ) ) {
$result = false;
}
break;
default: // Ignore
$result = - 1;
break;
}
return $result;
}
/**
* Plugin assignments - Browsers.
*
* @param $assignment
*
* @since 1.0.0
* @access protected
*
* @return bool|int
**/
protected function Browsers( $assignment ) {
/** If wrong input array - Ignore. */
if ( ! ( is_array( $assignment->browsersVal ) || is_array( $assignment->mobileBrowsersVal ) ) ) { return - 1; }
switch ( $assignment->browsers ) {
case 1: // Include
if ( is_array( $assignment->browsersVal ) ) {
foreach ( $assignment->browsersVal as $browser ) {
if ( ! $this->passBrowser( $browser ) ) { continue; }
return true;
}
}
if ( is_array( $assignment->mobileBrowsersVal ) ) {
foreach ( $assignment->mobileBrowsersVal as $browser ) {
if ( ! $this->passBrowser( $browser ) ) { continue; }
return true;
}
}
return false;
case 2: // Exclude
if ( is_array( $assignment->mobileBrowsersVal ) ) {
foreach ( $assignment->mobileBrowsersVal as $browser ) {
if ( ! $this->passBrowser( $browser ) ) { continue; }
return false;
}
}
if ( is_array( $assignment->browsersVal ) ) {
foreach ( $assignment->browsersVal as $browser ) {
if ( ! $this->passBrowser( $browser ) ) { continue; }
return false;
}
}
return true;
case 0;
default: // Ignore
$result = - 1;
break;
}
return $result;
}
/**
* Plugin assignments - IP Addresses.
*
* @param $assignment
*
* @since 1.0.0
* @access protected
*
* @return bool|int
**/
protected function IPs( $assignment ) {
switch ( $assignment->IPs ) {
case 1: // Include
$result = $this->passIPs( $assignment->IPsVal );
break;
case 2: // Exclude
$result = ! $this->passIPs( $assignment->IPsVal );
break;
case 0;
default: // Ignore
$result = - 1;
break;
}
return $result;
}
private function passIPs( $IPsVal ) {
if ( is_array( $IPsVal ) ) {
$IPsVal = implode( ',', $IPsVal );
}
$IPsVal = explode( ',', str_replace( [' ', "\r", "\n"], ['', '', ','], $IPsVal ) );
return $this->checkIPList( $IPsVal );
}
private function checkIPList( $IPsVal ) {
foreach ( $IPsVal as $range ) {
/** Check next range if this one doesn't match. */
if ( ! $this->checkIP( $range ) ) {
continue;
}
/** Match found. */
return true;
}
/** No matches found. */
return false;
}
private function checkIP( $range ) {
if ( empty( $range ) ) {
return false;
}
if ( strpos( $range, '-' ) !== false ) {
/** Selection is an IP range. */
return $this->checkIPRange( $range );
}
/** Selection is a single IP (part). */
return $this->checkIPPart( $range );
}
private function checkIPPart( $range ) {
$ip = $_SERVER['REMOTE_ADDR'];
/** Return if no IP address can be found (shouldn't happen, but who knows). */
if ( empty( $ip ) ) {
return false;
}
$ip_parts = explode( '.', $ip );
$range_parts = explode( '.', trim( $range ) );
/** Trim the IP to the part length of the range. */
$ip = implode( '.', array_slice( $ip_parts, 0, count( $range_parts ) ) );
/** Return false if ip does not match the range. */
return ! ( $range !== $ip );
}
private function checkIPRange( $range ) {
$ip = $_SERVER['REMOTE_ADDR'];
/** Return if no IP address can be found (shouldn't happen, but who knows). */
if ( empty( $ip ) ) { return false; }
/** Check if IP is between or equal to the from and to IP range. */
list( $min, $max ) = explode( '-', trim( $range ), 2 );
/** Return false if IP is smaller than the range start. */
if ( $ip < trim( $min ) ) { return false; }
$max = $this->fillMaxRange( $max, $min );
/** Return false if IP is larger than the range end. */
return ! ( $ip > trim( $max ) );
}
/**
* Fill the max range by prefixing it with the missing parts from the min range
* So 101.102.103.104-201.202 becomes:
* max: 101.102.201.202
*
* @param $max
* @param $min
*
* @return string
**/
private function fillMaxRange( $max, $min ) {
$max_parts = explode( '.', $max );
if ( count( $max_parts ) === 4 ) { return $max; }
$min_parts = explode( '.', $min );
$prefix = array_slice( $min_parts, 0, count( $min_parts ) - count( $max_parts ) );
return implode( '.', $prefix ) . '.' . implode( '.', $max_parts );
}
/**
* Plugin assignments - Operating Systems.
*
* @param $assignment
*
* @return bool|int
* @since 1.0.0
* @access protected
**/
protected function OS( $assignment ) {
/** If wrong input array - Ignore. */
if ( ! is_array( $assignment->osVal ) ) { return - 1; }
switch ( $assignment->os ) {
case 1: // Include
foreach ( $assignment->osVal as $browser ) {
if ( ! $this->passBrowser( $browser ) ) { continue; }
return true;
}
return false;
case 2: // Exclude
foreach ( $assignment->osVal as $browser ) {
if ( ! $this->passBrowser( $browser ) ) { continue; }
return false;
}
return true;
case 0;
default: // Ignore
$result = - 1;
break;
}
return $result;
}
private function passBrowser( $browser = '' ) {
if ( ! $browser) { return false; }
if ( $browser === 'mobile' ) { return $this->isMobile(); }
if ( ! ( strpos( $browser, '#' ) === 0 ) ) {
$browser = '#' . self::pregQuote( $browser ) . '#';
}
// also check for _ instead of .
$browser = preg_replace( '#\\\.([^]])#', '[\._]\1', $browser );
$browser = str_replace( '\.]', '\._]', $browser );
return preg_match( $browser . 'i', $this->getAgent() );
}
private function getAgent() {
$detect = new MobileDetect;
$agent = $detect->getUserAgent();
switch (true) {
case ( stripos( $agent, 'Trident' ) !== false ):
// Add MSIE to IE11
/** @noinspection NotOptimalRegularExpressionsInspection */
$agent = preg_replace( '#(Trident/[0-9.]+; rv:([0-9.]+))#is', '\1 MSIE \2', $agent );
break;
case ( stripos( $agent, 'Chrome' ) !== false ):
// Remove Safari from Chrome
$agent = preg_replace( '#(Chrome/.*)Safari/[0-9.]*#is', '\1', $agent );
// Add MSIE to IE Edge and remove Chrome from IE Edge
/** @noinspection NotOptimalRegularExpressionsInspection */
$agent = preg_replace( '#Chrome/.*(Edge/[0-9])#is', 'MSIE \1', $agent );
break;
case ( stripos( $agent, 'Opera' ) !== false ):
$agent = preg_replace( '#(Opera/.*)Version/#is', '\1Opera/', $agent );
break;
}
return $agent;
}
public static function pregQuote( $string = '', $delimiter = '#' ) {
return self::quote( $string, '', $delimiter );
}
/**
* preg_quote the given string or array of strings
*
* @param string|array $data
* @param string $name
* @param string $delimiter
*
* @param bool $capture
*
* @return string
**/
public static function quote( $data, $name = '', $delimiter = '#', $capture = true ) {
if ( is_array( $data ) ) {
$array = self::quoteArray( $data, $delimiter );
$prefix = '?!';
if ( $capture ) {
$prefix = $name ? '?<' . $name . '>' : '';
}
return '(' . $prefix . implode( '|', $array ) . ')';
}
if ( ! empty( $name ) ) {
return '(?<' . $name . '>' . preg_quote( $data, $delimiter ) . ')';
}
return preg_quote( $data, $delimiter );
}
/**
* preg_quote the given array of strings
*
* @param array $array
* @param string $delimiter
*
* @return array
**/
public static function quoteArray($array = [], $delimiter = '#') {
array_walk($array, static function ( &$part, $delimiter ) {
$part = self::quote( $part, '', $delimiter );
}, $delimiter );
return $array;
}
public function isMobile() {
return $this->getDevice() === 'mobile';
}
private function getDevice() {
$detect = new MobileDetect;
switch (true)
{
case( $detect->isTablet() ):
return 'tablet';
case ($detect->isMobile()):
return 'mobile';
default:
return 'desktop';
}
}
/**
* Plugin assignments - URL.
*
* @param $assignment
*
* @return bool|int
* @since 1.0.0
* @access protected
*/
protected function URL( $assignment ) {
/** Current URL. */
if ( ! isset( $_SERVER["HTTPS"] ) || ( $_SERVER["HTTPS"] !== 'on' ) ) {
$curUrl = 'http://' . $_SERVER["SERVER_NAME"];
} else {
$curUrl = 'https://' . $_SERVER["SERVER_NAME"];
}
$curUrl .= $_SERVER["REQUEST_URI"];
$URLVal = (array) preg_split( '/\r\n|[\r\n]/', $assignment->URLVal );
$URLVal = array_filter( $URLVal, static function ( $value ) {
if ( trim( $value ) !== '' ) { return $value; }
return null;
} );
switch ( $assignment->URL ) {
case 1: // Include
$result = false;
if ( count( $URLVal ) === 0 ) {
$result = false;
} // If no URLS to include - hide widget
foreach ( $URLVal as $u ) {
if ( strpos( $curUrl, $u ) !== false ) {
$result = true;
}
}
break;
case 2: // Exclude
$result = true;
if ( count( $URLVal ) === 0 ) {
$result = true;
} // If no URLS to exclude - show widget
foreach ( $URLVal as $u ) {
if ( strpos( $curUrl, $u ) !== false ) {
$result = false;
}
}
break;
default: // Ignore
$result = - 1;
break;
}
return $result;
}
/**
* Plugin assignments - Custom PHP.
*
* @param $assignment
*
* @return bool|int
* @since 1.0.0
* @access protected
*/
protected function PHP( $assignment ) {
/** Replace PHPVal );
$p = substr( $php, 0, 5 );
if ( strtolower( $p ) === 'PHP ) {
case 1: // Include
$result = false;
if ( $pass ) {
$result = true;
}
break;
case 2: // Exclude
$result = true;
if ( $pass ) {
$result = false;
}
break;
default: // Ignore
$result = - 1;
break;
}
return $result;
}
/**
* Plugin assignments - Matching Method.
*
* @param object $assignment
* @param array $checks
*
* @return bool
* @since 1.0.0
* @access protected
*/
protected function MatchingMethod( $assignment, $checks = [] ) {
$arrCond = []; // Add condition values
foreach ( $checks as $check ) {
// Ignore if -1
if ( $check !== - 1 ) {
$arrCond[] = $check;
}
}
if ( ! count( $arrCond ) ) {
$arrCond[] = true;
}
// If all rules are Ignore - Show widget
// Initialization
$any_true = false;
$all_true = true;
// Processing
foreach ( $arrCond as $v ) {
$any_true |= $v;
$all_true &= $v;
}
// Result
if ( $all_true ) {
// All elements are TRUE
$result = true;
} elseif ( ! $any_true ) {
// All elements are FALSE
$result = false;
} else if ( $assignment->matchingMethod === 0 ) { // ALL RULES
$result = false;
} else { // ANY OF RULES
$result = true;
}
return $result;
}
/**
* Output options list for select.
*
* @param $arr
* @param $menu_slug
* @param int $level
*
* @since 1.0.0
*/
public function printMenuTree( $arr, $menu_slug, $level = 0 ) {
if ( ! is_array( $arr ) ) { return; }
foreach ( $arr as $item ) {
?>
wpse_children ) && count( $item->wpse_children ) ) {
$this->printMenuTree( $item->wpse_children, $menu_slug, $level + 1 );
}
}
}
/**
* Transform a navigational menu to it's tree structure
*
* @param $menu_id
*
* @return array|null $tree
* @uses buildTree()
* @uses wp_get_nav_menu_items()
*
**/
public function wpse_nav_menu_2_tree( $menu_id ) {
$items = wp_get_nav_menu_items( $menu_id );
return $items ? $this->buildTree( $items, 0 ) : null;
}
/**
* Modification of "Build a tree from a flat array in PHP"
*
* Authors: @DSkinner, @ImmortalFirefly and @SteveEdson
*
* @link https://stackoverflow.com/a/28429487/2078474
*
* @param array $elements
* @param int $parentId
*
* @return array
**/
public function buildTree( array &$elements, $parentId = 0 ) {
$branch = [];
foreach ( $elements as &$element ) {
if ( intval( $element->menu_item_parent ) === intval( $parentId ) ) {
$children = $this->buildTree( $elements, $element->ID );
if ( $children ) {
$element->wpse_children = $children;
}
$branch[$element->ID] = $element;
unset( $element );
}
}
return $branch;
}
/**
* Get current query information.
*
* @return string[]
* @global WP_Query $wp_query
*
*/
public function getQuery() {
global $wp_query;
// create, if not set
if ( empty( $this->query ) ) {
// init vars
$obj = $wp_query->get_queried_object();
$type = get_post_type();
$query = [];
if ( is_home() ) {
$query[] = 'home';
}
if ( is_front_page() ) {
$query[] = 'front_page';
}
if ( $type === 'post' ) {
if ( is_single() ) {
$query[] = 'single';
}
if ( is_archive() ) {
$query[] = 'archive';
}
} else if ( is_single() ) {
$query[] = $type . '-single';
} elseif ( is_archive() ) {
$query[] = $type . '-archive';
}
if ( is_search() ) {
$query[] = 'search';
}
if ( is_page() ) {
$query[] = $type;
$query[] = $type . '-' . $obj->ID;
}
if ( is_category() ) {
$query[] = 'cat-' . $obj->term_id;
}
// WooCommerce
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
/** @noinspection PhpUndefinedFunctionInspection */
if ( is_shop() && ! is_search() ) {
$query[] = 'page';
/** @noinspection PhpUndefinedFunctionInspection */
$query[] = 'page-' . wc_get_page_id( 'shop' );
}
/** @noinspection PhpUndefinedFunctionInspection */
if ( is_product_category() || is_product_tag() ) {
$query[] = 'cat-' . $obj->term_id;
}
}
/** @noinspection PhpUndefinedFieldInspection */
$this->query = $query;
}
return $this->query;
}
/**
* Main TabAssignments Instance.
*
* Insures that only one instance of TabAssignments exists in memory at any one time.
*
* @static
* @since 1.0.0
*
* @return TabAssignments
**/
public static function get_instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) {
self::$instance = new self;
}
return self::$instance;
}
} // End Class TabAssignments.