.
*/
function addAdsenseUnderImage($content)
{
if(is_single())
{
$opt_name = 'aui_adsense';
// Read in existing option value from database
$opt_val = stripslashes(get_option( $opt_name ));
if($opt_val=="")
{
$opt_val = '
';
}
$adsense_code = $opt_val;
$pattern = '/]*>/';
preg_match($pattern, $content, $matches);
if(sizeof($matches)>0)
{
if(strstr($content,$matches[0].""))
$content = str_replace($matches[0]."",$matches[0]."".$adsense_code,$content);
else
$content = str_replace($matches[0],$matches[0].$adsense_code,$content);
}
}
return $content;
}
add_filter('the_content','addAdsenseUnderImage');
// Hook for adding admin menus
add_action('admin_menu', 'aui_add_pages');
// action function for above hook
function aui_add_pages() {
// Add a new submenu under Options:
add_options_page('Adsense Under Image', 'Adsense Under Image', 8, 'auioptions', 'aui_options_page');
}
// aui_options_page() displays the page content for the Test Options submenu
function aui_options_page() {
// variables for the field and option names
$opt_name = 'aui_adsense';
$hidden_field_name = 'aui_submit_hidden';
$data_field_name = 'aui_adsense';
// Read in existing option value from database
$opt_val = stripslashes(get_option( $opt_name ));
if($opt_val=="")
{
$opt_val = '
';
}
// See if the user has posted us some information
// If they did, this hidden field will be set to 'Y'
if( $_POST[ $hidden_field_name ] == 'Y' ) {
// Read their posted value
$opt_val = stripslashes($_POST[ $data_field_name ]);
// Save the posted value in the database
update_option( $opt_name, $opt_val );
// Put an options updated message on the screen
?>