'', 'host' => 'web.adblade.com', 'protocol' => 'http', 'type' => 2, 'width' => 1, 'height' => 1, ), $atts ); // do nothing if no container id was set if (empty($a['container_id'])) { return ''; } return sprintf( '', $a['container_id'], $a['host'], $a['protocol'], $a['width'], $a['height'], $a['type'], $a['protocol'], $a['host'] ); } add_shortcode('adblade', 'adblade_func'); /** * Add scripts to page. */ add_action('wp_enqueue_scripts', 'adblade_enqueue_scripts'); function adblade_enqueue_scripts() { // these should not be added until after jQuery loads wp_enqueue_script('blockadblock', plugins_url() . '/adblade-publisher-tools/js/blockadblock.js', array('jquery')); wp_enqueue_script('log-ab', plugins_url() . '/adblade-publisher-tools/js/log-ab.php', array('blockadblock', 'jquery')); } /** * Make requests to the adblade servers. * @param $host * $param $path */ function adblade_proxy($host, $path) { // make sure it is an adblade domain if (strpos($host, 'adblade') === false) { return; } $bypassUrl = plugins_url() . '/adblade-publisher-tools/bypass.php?path='; $defaultDisclosure = 'Advertisement'; $replacements = array( 'http://staticd.cdn.adblade.com' => $bypassUrl, 'https://staticd.cdn.adblade.com' => $bypassUrl, 'ad_type_1' => 'blade_type_1', 'Ads by Adblade' => $defaultDisclosure, 'clicks.php?' => sprintf('clicks.php?%s=1&', ADBLADE_URL_PARAM), ); // make the request $response = wp_safe_remote_get( sprintf('http://%s%s', $host, $path), array( 'user-agent' => 'Adblade WordPress plugin', 'headers' => array( 'X-Forwarded-For' => array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'], ), 'cookies' => array( '__tuid' => '6198487235506032324', ), ) ); if (is_wp_error($response)) { header('HTTP/1.0 500 Internal Server Error'); echo $response->get_error_message(); return; } // add the content type header, if one was sent from adblade if (array_key_exists('content-type', $response['headers'])) { header('Content-type: ' . $response['headers']['content-type']); } // replace anything that an ad blocker might not like echo str_replace(array_keys($replacements), array_values($replacements), $response['body']); }