EyeReturn (/eyereturn/eyereturn.html) * > Unicast (/unicast/unicastIFD.html) * * @since Adbusters (1.0) */ function wpcom_vip_maybe_load_ad_busters() { $ad_busters = wpcom_vip_get_ad_busters_array(); // To only support a specific ad network, use this filter and return an array containing the values of $ad_busters to load $whitelist_ads = (array) apply_filters( 'wpcom_vip_ad_busters_whitelist', $ad_busters ); $ad_busters = array_intersect( $ad_busters, $whitelist_ads ); // To ignore an ad network, use this filter and return an array containing the values of $ad_busters to not load $block_ads = apply_filters( 'wpcom_vip_maybe_load_ad_busters', array() ); $ad_busters = array_diff( $ad_busters, $block_ads ); $ad_paths = $ad_busters; // nothing to do if there are no paths after whitelisting and blocking if ( empty( $ad_paths ) ) return; // If your ads need to be served from example.com/some/subfolder/*, pass "some/subfolder" to this filter $path = explode( '/', apply_filters( 'wpcom_vip_ad_busters_custom_path', '' ) ); $path = array_filter( array_map( 'sanitize_title', $path ) ); $path = implode( '/', $path ); // Make sure both the ends of the path have slashes $path = _wpcom_vip_leadingslashit( $path ); $path = trailingslashit( $path ); $ad_busters = array_map( function( $ad_file ) use ( $path ) { return "{$path}{$ad_file}"; }, $ad_busters ); // Do we have a request for a supported network? $request = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ); $index = array_search( $request, $ad_busters ); if ( false === $index ) return; // Spit out the template $file = plugin_dir_path( __FILE__ ) . 'templates/' . $ad_paths[$index]; if ( ! file_exists( $file ) ) return; header( 'Content-type: text/html' ); readfile( $file ); exit; } add_action( 'init', 'wpcom_vip_maybe_load_ad_busters', -1 ); /** * Prepends a leading slash. * * Will remove leading slash if it exists already before adding a leading slash. This prevents double slashing a string or path. * The primary use of this is for paths and thus should be used for paths. It is not restricted to paths and offers no specific path support. * * @access private * @param string $string What to add the leading slash to. * @return string String with leading slash added. */ function _wpcom_vip_leadingslashit( $string ) { return '/' . _wpcom_vip_unleadingslashit( $string ); } /** * Removes leading slash if it exists. * * The primary use of this is for paths and thus should be used for paths. It is not restricted to paths and offers no specific path support. * * @access private * @param string $string What to remove the leading slash from. * @return string String without the leading slash. */ function _wpcom_vip_unleadingslashit( $string ) { return ltrim( $string, '/' ); }