$value){ if (isset($_POST[$key])){ $ops[$key] = $_POST[$key]; } else { $ops[$key] = ""; } } $raw_ad_code_random = stripslashes($_POST['ad_code_random_1']); $ops['ad_code_random_1'] = $raw_ad_code_random; $raw_ad_code_top = stripslashes($_POST['ad_code_top_1']); $ops['ad_code_top_1'] = $raw_ad_code_top; $raw_ad_code_bottom = stripslashes($_POST['ad_code_bottom_1']); $ops['ad_code_bottom_1'] = $raw_ad_code_bottom; $ad_referrers = stripslashes($_POST['ad_referrers']); // TODO do i need strip slashes? $ops['ad_referrers'] = $ad_referrers; $blocked_ips = stripslashes($_POST['blocked_ips']); $ops['blocked_ips'] = $blocked_ips; adinj_update_options($ops); if ($ops['ad_insertion_mode'] == 'mfunc') { global $adinj_warning_msg_filewrite; if (!file_exists(ADINJ_AD_PATH2)){ mkdir(ADINJ_AD_PATH2, 0750) //TODO is this the right permission? or $adinj_warning_msg_filewrite .= "
Error: could not create dir: ".ADINJ_AD_PATH2.". Please create it manually and try again."; } write_ad_to_file($raw_ad_code_random, ADINJ_AD_PATH2.'/'.ADINJ_AD_RANDOM_FILE); write_ad_to_file($raw_ad_code_top, ADINJ_AD_PATH2.'/'.ADINJ_AD_TOP_FILE); write_ad_to_file($raw_ad_code_bottom, ADINJ_AD_PATH2.'/'.ADINJ_AD_BOTTOM_FILE); adinj_write_config_file(); } break; case 'Reset to Default': adinj_checkNonce(); adinj_update_options(adinj_default_options()); break; case 'Delete settings from DB': adinj_checkNonce(); delete_option('adinj_options'); case 'Delete widget settings from DB': adinj_checkNonce(); delete_option('widget_adinj'); // TODO add option to delete ads files as well break; } } // Test reminder: These generated functions won't exist until the first save // so be careful if adding any new ones - they might not exist yet, but could // still be referenced by adshow. function adinj_write_config_file(){ $ops = adinj_options(); if ($ops['ad_insertion_mode'] != 'mfunc') return; $referrer_list = adinj_quote_list('ad_referrers'); $ip_list = adinj_quote_list('blocked_ips'); $sevisitors_only = adinj_ticked('sevisitors_only')?'true':'false'; $debug_mode = adinj_ticked('debug_mode')?'true':'false'; $rnd_func = adinj_add_tags(NULL, 'rnd_', 'adinj_config_add_tags_rnd'); $top_func = adinj_add_tags(NULL, 'top_', 'adinj_config_add_tags_top'); $bottom_func = adinj_add_tags(NULL, 'bottom_', 'adinj_config_add_tags_bottom'); $config = << CONFIG; adinj_write_file(ADINJ_CONFIG_FILE2, $config, 0640); } function adinj_write_file($path, $content, $permission){ $ops = adinj_options(); global $adinj_warning_msg_filewrite; $handle = fopen($path, "w"); if (strlen($content) > 0){ fwrite($handle, $content) or $adinj_warning_msg_filewrite .= "
Error: could not write to file: $path"; } fclose($handle); adinj_chmod($path, $permission); } function adinj_chmod($path, $permission){ global $adinj_warning_msg_chmod; $oldperm = substr(decoct(fileperms($path)), -3); $newperm = decoct($permission); if ($newperm == $oldperm) return; chmod($path, $permission) or $adinj_warning_msg_chmod .= "
Warning: chmod $permission " . "on $path failed. Current permissions: $oldperm
Try manually updating the permission if problems occur."; } function adinj_get_logo(){ return 'reviewmylife'; } function adinj_options_page(){ $ops = adinj_options(); if ($ops === false || adinj_options_need_upgrading($ops)){ // Upgraded via FTP without being deactivated/reactivated adinj_activate_hook(); } $ops = adinj_options(1); if ($ops['ad_insertion_mode'] == 'mfunc') { if (!file_exists(ADINJ_CONFIG_FILE2)){ adinj_write_config_file(); } } echo '
'; if (adinj_problem_with_wpminify_check()){ echo '

'; echo adinj_get_problem_with_wpminify_message(); echo '

'; } echo '

Ad Injection ' . adinj_get_version() . adinj_get_logo() . '

'; if (isset($_POST['adinj_action'])) { echo '

'; echo 'All settings saved: '; if (is_plugin_active('wp-super-cache/wp-cache.php')) { echo "You might need to clear your WP Super Cache cache for the settings to take effect."; } else { echo "If you are using a caching plugin you might need to delete its cache for any changes to take effect."; } echo ''; if ($ops['ad_insertion_mode']=='mfunc'){ global $adinj_warning_msg_filewrite; if (!empty($adinj_warning_msg_filewrite)){ echo $adinj_warning_msg_filewrite; echo "
Workaround: If you are unable to fix these errors you will have to switch to a direct insertion mode (however dynamic features won't work if you are using a caching plugin)."; } } global $adinj_warning_msg_chmod; if (!empty($adinj_warning_msg_chmod)){ echo '
Info: Some warnings were generated by chmod. See the debugging section for more info.'; } if ($ops['ads_enabled'] != 'on'){ echo '
Warning: Ads are not enabled. You need to turn the ads on for everyone to see them.'; } echo '

'; } ?>

Status

Ads enabled
   home
   page
   single
   archive
Random ads '; $info = adinj_get_status('random_home'); echo adinj_dot($info[0]).' '.$info[1]; ?>
Top ad
Bottom ad
Widgets
   home
   page
   single
   archive
Mode
Restrictions
Debug mode

More info...

More Ad Injection information

Coming soon

  • More precise control over which categories and tags the ads are shown in.
  • Extra places where adverts can be inserted.
  • Merry Christmas by the way!

Be careful!

Make sure that the ad settings and positioning you define are in compliance with your ad provider's terms of service!

Beta version

This plugin has only only recently been released. I'm actively listening to your feedback and fixing any problems, and adding new features that you request. Please let me know if you like the plugin too!

More by this author

Random ads | Top | Bottom | Widgets | Ad insert mode/dynamic restrictions | Debug | Quick Start | Test ads

These settings apply to all ads (random, top, bottom, and widget). They will override all other settings.

/> On:
/> Off
/> Test mode - Only show ads to admin.
Warning: Turn any caching plugin *off* before using test mode. If you leave them on the test adverts will be cached and shown to your real visitors.

- only for single posts and pages

Don't show ads on these page types: />home -
/>page - publish; ?> page(s)
/>single -publish; ?> individual blog post(s)
/>archive - only widgets currently appear on archives
Category and tag conditions
/>

Docs: On individual posts or pages this advert is inserted between randomly selected paragraphs. On a multi-post page (e.g. home page), one ad is inserted into each post. Try a 468x60 or 728x90 banner.

Be especially careful if you decide to use the 'float' layout options. Make sure that you don't have adverts floated over the top of other page elements, or vice-versa.

These random ad injection settings are specific to individual posts and pages.

/> (default is to inject ads at unique positions)

'; adinj_selection_box("no_random_ads_if_shorter_than", array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000)); echo adinj_getdefault('no_random_ads_if_shorter_than'); ?>
'; adinj_selection_box("one_ad_if_shorter_than", array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000)); echo adinj_getdefault('one_ad_if_shorter_than'); ?>
'; adinj_selection_box("two_ads_if_shorter_than", array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000)); echo adinj_getdefault('two_ads_if_shorter_than'); ?>
'; adinj_selection_box("three_ads_if_shorter_than", array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000, 20000)); echo adinj_getdefault('three_ads_if_shorter_than'); ?>

Docs: The above directives are processed in order from top to bottom.

()

These random ad injection settings are specific to your home page.


Docs: On a multi-post home page, one randomly positioned advert will be inserted into each post, up to the maximum number specified here.


The top ad is in addition to the quantity of other ads selected.

Docs: The top ad will only appear on single posts and pages. It will not appear on multi-post pages. Try a 468x15 or 336x280 advert.


The top ad is in addition to the quantity of other ads selected.

Docs: The bottom ad will only appear on single posts and pages. It will not appear on multi-post pages. Try a 336x280 advert.

You must configure your individual widgets from the widgets control panel. However these settings are global to all widgets. Also note that the main set of global settings will override these ones.

Don't show widget ads on these page types:

/>home -
/>page - publish; ?> page(s)
/>single - publish; ?> individual blog post(s)
/>archive - includes category, tag, author, and date pages types

Ad insertion mode

/> Use mfunc tags for dynamic features - Dynamic features will work with WP Super Cache in legacy mode (or with a caching program that is compatible with WP Super Cache's mfunc tags). Dynamic features will also work if you don't use a caching program, although if you don't use a caching program 'direct' insertion will be more efficient.

/> Direct ad insertion with dynamic features - Dynamic features will work if no caching is used. Only select this if you are not using any caching plugin.

/> Direct static ad insertion - No dynamic feature support. Select this if you are using a caching plugin which is not compatible with WP Super Cache's mfunc tags.

Show ads only to search engine visitors (dynamic feature)

/>

Comma separated list e.g.:
.google., .bing., .yahoo., .ask., search?, search., /search/

Blocked IP addresses (dynamic feature)

Comma separated list e.g.:
0.0.0.1, 0.0.0.2

Or you can list one IP per line with optional comments e.g.

192.168.0.1
0.0.0.2
//my ip
0.0.0.3

For reference your current IP address is

Recommended WP Super Cache settings:

  • Cache hits to this website for quick access.
  • Legacy page caching.
  • Compress pages so they’re served more quickly to visitors.
  • Expire time: 36000 (10 hours). Or 3600 (1 hour) for very busy site.

advanced settings page (where you can set the caching mode to Legacy)."; } else { echo "Note: WP Super Cache does not appear to be active."; } ?>

/>Enable debug mode

If you are not sure why ads aren't appearing, or why they are appearing, enable debug mode and look at the debug information (search for 'ADINJ DEBUG') in the HTML of your content pages.

If you want to restore all settings (excluding the ad contents) to their default values use this button.

You can delete the database settings if you are going to uninstall Ad Injection.


'; echo '
'; } function adinj_postbox_start($title, $anchor, $width='650px'){ $ops = adinj_options(); ?>
' />

'; } function adinj_get_status($name){ $ops = adinj_options(); $status[] = 'black'; $status[] = 'Error...'; if ($name == 'global'){ if ($ops['exclude_home'] == 'on' && $ops['exclude_page'] == 'on' && $ops['exclude_single'] == 'on' && $ops['exclude_archive'] == 'on'){ $status[0] = 'red'; $status[1] = 'excluded from all'; return $status; } $val = $ops['ads_enabled']; if ($val == 'on'){ $status[0] = 'green'; $status[1] = $val; } else if ($val == 'off'){ $status[0] = 'red'; $status[1] = $val; } else if ($val == 'test'){ $status[0] = 'orange'; $status[1] = 'test mode'; } } else if ($name == 'random'){ $ad = $ops['ad_code_random_1']; if (empty($ad)){ $status[0] = 'red'; $status[1] = 'no ad defined'; return $status; } $val = $ops['max_num_of_ads']; if ($val == '0'){ $status[0] = 'red'; $status[1] = 'off'; } else { $status[0] = 'green'; $status[1] = 'max ads: ' . $val; } } else if ($name == 'random_home'){ $val = $ops['max_num_of_ads_home_page']; $msg = '0 on home'; } else if ($ops['exclude_home'] == 'on'){ $status[0] = 'red'; $msg .= 'global">exclude from home'; } else { $status[0] = 'green'; $msg .= 'random_home">max ads: ' . $val .' (home)'; } $status[1] = $msg.''; } else if ($name == 'topad'){ $ad = $ops['ad_code_top_1']; if (empty($ad)){ $status[0] = 'red'; $status[1] = 'no ad defined'; return $status; } $val = $ops['top_ad_if_longer_than']; if ($val == ADINJ_RULE_DISABLED){ $status[0] = 'red'; $status[1] = 'off'; } else { $status[0] = 'green'; $status[1] = 'on'; } } else if ($name == 'bottomad'){ $ad = $ops['ad_code_bottom_1']; if (empty($ad)){ $status[0] = 'red'; $status[1] = 'no ad defined'; return $status; } $val = $ops['bottom_ad_if_longer_than']; if ($val == ADINJ_RULE_DISABLED){ $status[0] = 'red'; $status[1] = 'off'; } else { $status[0] = 'green'; $status[1] = 'on'; } } else if ($name == 'widgets'){ if ($ops['widget_exclude_home'] == 'on' && $ops['widget_exclude_page'] == 'on' && $ops['widget_exclude_single'] == 'on' && $ops['widget_exclude_archive'] == 'on'){ $status[0] = 'red'; $status[1] = 'exclude from all'; } else { $status[1] = 'see widgets screen'; } } else if ($name == 'mode'){ $status[1] = $ops['ad_insertion_mode']; } else if ($name == 'restrictions'){ if ($ops['ad_insertion_mode'] == 'direct_static'){ $status[1] = 'n/a for direct static'; return $status; } $status[1] = ""; if ($ops['sevisitors_only'] == 'on'){ $status[1] .= 'referrer'; } if (!empty($ops['blocked_ips'])){ $status[1] .= ' ip'; } } else if ($name == 'debugging'){ $val = $ops['debug_mode']; if ($val == 'on'){ $status[0] = 'green'; $status[1] = 'on'; } else { $status[0] = 'red'; $status[1] = 'off'; } } return $status; } // This is for 'exclude' options so 'on' is red. function adinj_green_or_red_dot($option){ $ops = adinj_options(); if ($ops[$option] == 'on'){ return adinj_dot('red'); } else { return adinj_dot('green'); } } function adinj_dot($colour){ return ''; } function adinj_selection_box($name, $values, $type=NULL){ echo ""; } function adinj_condition_table($name, $description, $type){ $options = adinj_options(); ?>

Comma separated list of
"; adinj_selection_box($prefix.'align', array(ADINJ_RULE_DISABLED, 'left', 'center', 'right', 'float left', 'float right')); echo "
"; _e("Margin top", 'adinj'); echo "
"; adinj_selection_box($prefix.'margin_top', array(ADINJ_RULE_DISABLED, 0, 1, 2, 3, 4, 5, 7, 10, 15, 20, 30), "(px)"); echo "
"; _e("Margin bottom", 'adinj'); echo "
"; adinj_selection_box($prefix.'margin_bottom', array(ADINJ_RULE_DISABLED, 0, 1, 2, 3, 4, 5, 7, 10, 15, 20, 30), "(px)"); } function adinj_debug_information(){ $stored_options = adinj_options(); $default_options = adinj_default_options(); ?>

Settings dump from database (all in 'adinj_options' option)

$value){ if ($count % 2 == 0){ echo '"; $count++; } } else { echo "
No options in database!"; } echo '
NameStoredDefault
'; } else { echo '
'; } echo "$key"; echo ""; $value = htmlentities($value); echo "$value"; echo ""; echo $default_options[$key]; echo "
'; echo '

Other settings

'; echo 'ADINJ_PATH='.ADINJ_PATH.'
'; echo 'ADINJ_CONFIG_FILE2='.ADINJ_CONFIG_FILE2.'
'; echo 'ADINJ_AD_PATH='.ADINJ_AD_PATH.' (up to v0.9.1)
'; echo 'ADINJ_AD_PATH2='.ADINJ_AD_PATH2.' (v0.9.2+)
'; echo 'Plugin version='.adinj_get_version(); echo '
'; global $adinj_warning_msg_filewrite; if (!empty($adinj_warning_msg_filewrite)){ echo "

Errors on 'Save all settings'

$adinj_warning_msg_filewriteWarnings on 'Save all settings'
$adinj_warning_msg_chmodProblem: Ad Injection will not work if WP Minify is set to minify HTML whilst WP Super Cache is enabled.
Solution: Go to the WP Minify settings page and untick "Enable HTML Minification".'; } function adinj_init_warning() { if (stripos($_SERVER["PHP_SELF"], 'plugins.php') !== false){ echo '

Ad Injection needs configuring: Go to the settings page to configure and enable your ads.

'; } // TODO add option to disable message without having to go to settings. } function adinj_compatibility_checks() { if (stripos($_SERVER["PHP_SELF"], 'ad-injection') !== false){ $wpm_options = get_option('wp_minify'); if ($wpm_options['enable_html'] == true){ echo '

'; echo adinj_get_problem_with_wpminify_message(); echo '

'; } } } function adinj_activate_hook() { $stored_options = adinj_options(); $pending_options = adinj_default_options(); if(empty($stored_options)){ // Save defaults to DB below. if (!is_plugin_active('wp-super-cache/wp-cache.php')){ $pending_options['ad_insertion_mode'] = 'direct_dynamic'; } } else { // Upgrade options if necessary. Use default as a baseline, // and then overwrite default with the saved ones. foreach ($pending_options as $key => $value){ if (array_key_exists($key, $stored_options)){ $pending_options[$key] = $stored_options[$key]; } } } $random_file2 = ADINJ_AD_PATH2.'/'.ADINJ_AD_RANDOM_FILE; $top_file2 = ADINJ_AD_PATH2.'/'.ADINJ_AD_TOP_FILE; $bottom_file2 = ADINJ_AD_PATH2.'/'.ADINJ_AD_BOTTOM_FILE; if ($pending_options['ad_insertion_mode'] == 'mfunc'){ if (!file_exists(ADINJ_AD_PATH2)){ mkdir(ADINJ_AD_PATH2, 0750) //TODO is this the right permission? or $adinj_warning_msg_filewrite .= "
Error: could not create dir: ".ADINJ_AD_PATH2.". Please create it manually and try again."; } // Restore data after automatic upgrade // TODO could remove this code further down the line when everyone // has moved to the new ad store location if (!file_exists($random_file2) && !empty($pending_options['ad_code_random_1'])){ write_ad_to_file($pending_options['ad_code_random_1'], $random_file2); } if (!file_exists($top_file2) && !empty($pending_options['ad_code_top_1'])){ write_ad_to_file($pending_options['ad_code_top_1'], $top_file2); } if (!file_exists($bottom_file2) && !empty($pending_options['ad_code_bottom_1'])){ write_ad_to_file($pending_options['ad_code_bottom_1'], $bottom_file2); } if (!file_exists(ADINJ_CONFIG_FILE2)){ adinj_write_config_file(); } } adinj_update_options($pending_options); } // If the options in the database are out of sync with our default options // then the database options will need upgrading function adinj_options_need_upgrading($stored_options){ $default_options = adinj_default_options(); foreach ($default_options as $key => $value){ if (!array_key_exists($key, $stored_options)){ return true; } } foreach ($stored_options as $key => $value){ if (!array_key_exists($key, $default_options)){ return true; } } return false; } function adinj_default_options(){ return array( // Global settings 'ads_enabled' => '', 'ads_on_page_older_than' => '10', 'exclude_home' => '', 'exclude_page' => '', 'exclude_single' => '', 'exclude_archive' => '', 'global_category_condition_mode' => ADINJ_ONLY_SHOW_IN, 'global_category_condition_entries' => '', 'global_tag_condition_mode' => ADINJ_ONLY_SHOW_IN, 'global_tag_condition_entries' => '', // Random ad 'ad_code_random_1' => '', 'max_num_of_ads' => '2', // single posts and pages 'no_random_ads_if_shorter_than' => '100', 'one_ad_if_shorter_than' => '500', 'two_ads_if_shorter_than' => '1000', 'three_ads_if_shorter_than' => ADINJ_RULE_DISABLED, 'top_ad_if_longer_than' => ADINJ_RULE_DISABLED, 'bottom_ad_if_longer_than' => ADINJ_RULE_DISABLED, 'rnd_align' => ADINJ_RULE_DISABLED, 'rnd_margin_top' => '3', 'rnd_margin_bottom' => '3', 'first_paragraph_ad' => '', 'multiple_ads_at_same_position' => '', // Home page specific random ads 'max_num_of_ads_home_page' => '3', // top 'ad_code_top_1' => '', 'top_align' => ADINJ_RULE_DISABLED, 'top_margin_top' => '3', 'top_margin_bottom' => '3', // bottom 'ad_code_bottom_1' => '', 'bottom_align' => ADINJ_RULE_DISABLED, 'bottom_margin_top' => '3', 'bottom_margin_bottom' => '3', // widgets 'widget_exclude_home' => '', 'widget_exclude_page' => '', 'widget_exclude_single' => '', 'widget_exclude_archive' => '', // dynamic features 'sevisitors_only' => '', 'ad_referrers' => '.google., .bing., .yahoo., .ask., search?, search., /search/', 'blocked_ips' => '', 'ad_insertion_mode' => 'mfunc', // ui 'ui_global_hide' => 'false', 'ui_random_hide' => 'false', 'ui_topad_hide' => 'false', 'ui_bottomad_hide' => 'false', 'ui_widgets_hide' => 'false', 'ui_restrictions_hide' => 'false', 'ui_debugging_hide' => 'true', 'ui_docs_hide' => 'false', 'ui_testads_hide' => 'false', // debug 'debug_mode' => '' ); } function adinj_getdefault($option){ $default_options = adinj_default_options(); return "(default: " . $default_options[$option] . ")"; } function write_ad_to_file($ad, $ad_path){ adinj_write_file($ad_path, $ad, 0640); } function adinj_docs(){ ?>

1. Copy and paste your ad code into the ad code boxes.

2. Choose how many ads of each type you want displayed.

3. Configure any ad positioning (optional).

4. Check the ad insertion mode (in the Insertion mode and ad display restriction section).

5. If you are using a compatible ad insertion mode you may configure dynamic ad display restrictions. i.e. showing ads only to certain people (e.g. search engine visitors), or blocking ads from specific IPs.

6. Enable your ads (tick box at the very top).

Supported in-page tags

These tags can be inserted into the page source to override the configured behaviour on individual pages. Because sometimes specific pages need to be treated differently.

  • <!--noadsense--> OR <!-no-adsense--> OR <!--NoAds--> OR <!--OffAds--> - disables all ads on this page. These tags are here to make this plugin compatible with the tags from Adsense Injection, Whydowork Adsense and Quick Adsense.

  • <!--adsandwich--> - Inserts the top and bottom ad but no random ads. Disables all other ads.
  • <!--adfooter--> - Insert a single ad at the very bottom. Disables all other ads.

  1. <!--adsensestart--> - Random ads will start from this point*. For compatibility with Adsense Injection.
  2. <!--adsenseend--> - Random ads will not be inserted after this point*. New tag but I've kept the Adsense Injection naming convention to make it fit with the above tag.
  3. <!--adstart--> - Random ads will start from this point*.
  4. <!--adend--> - Random ads will not be inserted after this point*.

These four tags will not affect the top and bottom ad.

Custom field for disabling adverts

To disable all adverts on the page you can also set the custom disable_adverts field to '1' from the WordPress post editor.

You can copy and paste these adverts into the boxes above to test your ad setup before switching to your real ads.

468x60 banner

TEST ADVERT 468x60 - www.reviewmylife.co.uk

728x90 banner

TEST ADVERT 728x90
www.reviewmylife.co.uk
www.advancedhtml.co.uk

160x90 link unit

TEST ADVERT 160x90
reviewmylife.co.uk advancedhtml.co.uk

468x15 link unit

TEST ADVERT 160x90 reviewmylife.co.uk

336x280 large rectangle

TEST ADVERT 336x280 - www.reviewmylife.co.uk

468x60 banner with dynamic PHP

The PHP will execute if 1) WP Super Cache is turned on in legacy mode, and 2) if WP Super Cache is not installed/disabled.

TEST ADVERT 468x60 with date() and rand()

www.advancedhtml.co.uk