' . $adUnitCode . '' . $adUnitStyles; } return ''; } /* End Ad Unit */ /* Begin Ad Unit Styles */ function wp_insert_get_ad_unit_styles( $data, $adunitClass ) { $adBreakpoints = [ 'device_large_desktop_width' => (int) ( ( ! isset( $data['device_large_desktop_width'] ) || ( $data['device_large_desktop_width'] == '' ) ) ? '1200' : $data['device_large_desktop_width'] ), 'device_medium_desktop_width' => (int) ( ( ! isset( $data['device_medium_desktop_width'] ) || ( $data['device_medium_desktop_width'] == '' ) ) ? '992' : $data['device_medium_desktop_width'] ), 'device_tablet_width' => (int) ( ( ! isset( $data['device_tablet_width'] ) || ( $data['device_tablet_width'] == '' ) ) ? '768' : $data['device_tablet_width'] ), 'device_mobile_width' => (int) ( ( ! isset( $data['device_mobile_width'] ) || ( $data['device_mobile_width'] == '' ) ) ? '480' : $data['device_mobile_width'] ), ]; $adUnitStyles = '' . "\r\n"; return $adUnitStyles; } /* End Ad Unit Styles */ /* Begin Ad Unit Code */ function wp_insert_get_ad_unit_code( $data ) { global $wpInsertABTestingMode; global $wpInsertVIAdDisplayed; global $wpInsertGeoLocation; $adUnitCode = ''; $geoGroup1Countries = ( isset( $data['geo_group1_countries'] ) && is_array( $data['geo_group1_countries'] ) ) ? $data['geo_group1_countries'] : []; $geoGroup2Countries = ( isset( $data['geo_group2_countries'] ) && is_array( $data['geo_group2_countries'] ) ) ? $data['geo_group2_countries'] : []; if ( ( $wpInsertGeoLocation != false ) && ( $wpInsertGeoLocation != '' ) && ( ( count( $geoGroup1Countries ) > 0 ) || ( count( $geoGroup2Countries ) > 0 ) ) ) { if ( ( ( $data['geo_group1_adcode'] ?? '' ) != '' ) && in_array( $wpInsertGeoLocation, $geoGroup1Countries ) ) { $adUnitCode = do_shortcode( stripslashes( $data['geo_group1_adcode'] ) ); } if ( ( ( $data['geo_group2_adcode'] ?? '' ) != '' ) && in_array( $wpInsertGeoLocation, $geoGroup2Countries ) ) { $adUnitCode = do_shortcode( stripslashes( $data['geo_group2_adcode'] ) ); } } if ( $adUnitCode == '' ) { switch ( $wpInsertABTestingMode ) { case 1: if ( isset( $data['primary_ad_code_type'] ) && ( $data['primary_ad_code_type'] == 'vicode' ) && function_exists( 'wp_insert_vi_api_get_vi_code' ) ) { if ( $wpInsertVIAdDisplayed !== true ) { $wpInsertVIAdDisplayed = true; $adUnitCode = '
' . wp_insert_vi_api_get_vi_code( 'wp_insert_vi_code_settings' ) . '
'; } else { $adUnitCode = ''; } } else { $adUnitCode = do_shortcode( stripslashes( $data['primary_ad_code'] ?? '' ) ); } break; case 2: $adUnitCode = do_shortcode( stripslashes( $data['secondary_ad_code'] ?? '' ) ); break; case 3: $adUnitCode = do_shortcode( stripslashes( $data['tertiary_ad_code'] ?? '' ) ); break; default: $adUnitCode = do_shortcode( stripslashes( $data['primary_ad_code'] ?? '' ) ); } } return $adUnitCode; } /* End Ad Unit Code */ /* Begin Assign Instance Identifier */ add_action( 'the_content', 'wp_insert_track_post_instance', 1 ); function wp_insert_track_post_instance( $content ) { global $wpInsertPostInstance; if ( is_main_query() ) { if ( $wpInsertPostInstance == '' ) { $wpInsertPostInstance = 1; } else { ++$wpInsertPostInstance; } } return $content; } /* End Assign Instance Identifier */ /* Begin Assign AB Testing Mode */ add_action( 'wp', 'wp_insert_track_ad_instance', 1 ); function wp_insert_track_ad_instance() { global $wpInsertABTestingMode; $abtestingMode = get_option( 'wp_insert_abtesting_mode' ); $wpInsertABTestingMode = wp_rand( 1, max( 1, (int) $abtestingMode ) ); } /* End Assign AB Testing Mode */ /* Begin Get Current Page Type */ function wp_insert_get_page_details() { global $post; $page_details = [ 'type' => 'POST', 'ID' => ( isset( $post->ID ) ? $post->ID : '' ), ]; if ( is_home() || is_front_page() ) { $page_details['type'] = 'HOME'; } elseif ( is_category() ) { $page_details['type'] = 'CATEGORY'; $page_details['ID'] = get_query_var( 'cat' ); } elseif ( is_archive() ) { $page_details['type'] = 'ARCHIVE'; } elseif ( is_search() ) { $page_details['type'] = 'SEARCH'; } elseif ( is_page() ) { $page_details['type'] = 'PAGE'; } elseif ( is_single() ) { if ( is_singular( 'post' ) ) { $page_details['type'] = 'POST'; $page_details['categories'] = wp_get_post_categories( $page_details['ID'] ); } else { $page_details['type'] = 'CUSTOM'; $page_details['type_name'] = $post->post_type; } } elseif ( is_404() ) { $page_details['type'] = '404'; } return $page_details; } /* End Get Current Page Type */ /* Begin Get Ad Status */ function wp_insert_get_ad_status( $rules ) { if ( ! isset( $rules ) ) { return false; } if ( ! wp_validate_boolean( $rules['status'] ?? '' ) ) { return false; } if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) { return false; } if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) { return false; } if ( isset( $rules['rules_exclude_loggedin'] ) && wp_validate_boolean( $rules['rules_exclude_loggedin'] ) && is_user_logged_in() ) { return false; } if ( isset( $rules['rules_exclude_mobile_devices'] ) && wp_validate_boolean( $rules['rules_exclude_mobile_devices'] ) && wp_is_mobile() ) { return false; } global $wpInsertPostInstance; $page_details = wp_insert_get_page_details(); switch ( $page_details['type'] ) { case 'HOME': if ( isset( $rules['rules_exclude_home'] ) && wp_validate_boolean( $rules['rules_exclude_home'] ) ) { return false; } elseif ( isset( $rules['rules_home_instances'] ) && is_array( $rules['rules_home_instances'] ) && ( in_array( $wpInsertPostInstance, $rules['rules_home_instances'] ) ) ) { return false; } break; case 'ARCHIVE': if ( isset( $rules['rules_exclude_archives'] ) && wp_validate_boolean( $rules['rules_exclude_archives'] ) ) { return false; } elseif ( isset( $rules['rules_archives_instances'] ) && is_array( $rules['rules_archives_instances'] ) && ( in_array( $wpInsertPostInstance, $rules['rules_archives_instances'] ) ) ) { return false; } break; case 'SEARCH': if ( isset( $rules['rules_exclude_search'] ) && wp_validate_boolean( $rules['rules_exclude_search'] ) ) { return false; } elseif ( isset( $rules['rules_search_instances'] ) && is_array( $rules['rules_search_instances'] ) && ( in_array( $wpInsertPostInstance, $rules['rules_search_instances'] ) ) ) { return false; } break; case 'PAGE': if ( isset( $rules['rules_exclude_page'] ) && wp_validate_boolean( $rules['rules_exclude_page'] ) ) { if ( ( ! isset( $rules['rules_page_exceptions'] ) ) || ( ! is_array( $rules['rules_page_exceptions'] ) ) || ( ! in_array( $page_details['ID'], $rules['rules_page_exceptions'] ) ) ) { return false; } } elseif ( isset( $rules['rules_page_exceptions'] ) && is_array( $rules['rules_page_exceptions'] ) && ( in_array( $page_details['ID'], $rules['rules_page_exceptions'] ) ) ) { return false; } break; case 'POST': if ( isset( $rules['rules_exclude_post'] ) && wp_validate_boolean( $rules['rules_exclude_post'] ) ) { if ( ( ! isset( $rules['rules_post_exceptions'] ) ) || ( ! is_array( $rules['rules_post_exceptions'] ) ) || ( ! in_array( $page_details['ID'], $rules['rules_post_exceptions'] ) ) ) { return false; } elseif ( ( ! isset( $rules['rules_post_categories_exceptions'] ) ) || ( ! is_array( $rules['rules_post_categories_exceptions'] ) ) || ( ! isset( $page_details['categories'] ) ) || ( ! is_array( $page_details['categories'] ) ) || ( ! ( count( array_intersect( $page_details['categories'], $rules['rules_post_categories_exceptions'] ) ) > 0 ) ) ) { return false; } } elseif ( isset( $rules['rules_post_exceptions'] ) && is_array( $rules['rules_post_exceptions'] ) && ( in_array( $page_details['ID'], $rules['rules_post_exceptions'] ) ) ) { return false; } elseif ( isset( $rules['rules_post_categories_exceptions'] ) && isset( $page_details['categories'] ) && is_array( $rules['rules_post_categories_exceptions'] ) && is_array( $page_details['categories'] ) && ( count( array_intersect( $page_details['categories'], $rules['rules_post_categories_exceptions'] ) ) > 0 ) ) { return false; } break; case 'CATEGORY': if ( isset( $rules['rules_exclude_categories'] ) && wp_validate_boolean( $rules['rules_exclude_categories'] ) ) { if ( ( ! isset( $rules['rules_categories_exceptions'] ) ) || ( ! is_array( $rules['rules_categories_exceptions'] ) ) || ( ! in_array( $page_details['ID'], $rules['rules_categories_exceptions'] ) ) ) { return false; } } elseif ( isset( $rules['rules_categories_exceptions'] ) && is_array( $rules['rules_categories_exceptions'] ) && ( in_array( $page_details['ID'], $rules['rules_categories_exceptions'] ) ) ) { return false; } elseif ( isset( $rules['rules_categories_instances'] ) && is_array( $rules['rules_categories_instances'] ) && ( in_array( $wpInsertPostInstance, $rules['rules_categories_instances'] ) ) ) { return false; } break; case '404': if ( isset( $rules['rules_exclude_404'] ) && wp_validate_boolean( $rules['rules_exclude_404'] ) ) { return false; } break; case 'CUSTOM': if ( isset( $rules[ 'rules_exclude_cpt_' . $page_details['type_name'] ] ) && wp_validate_boolean( $rules[ 'rules_exclude_cpt_' . $page_details['type_name'] ] ) ) { return false; } break; } return true; } /* End Get Ad Status */