Skip to content

Instantly share code, notes, and snippets.

@szbl
Created July 14, 2009 04:59
Show Gist options
  • Save szbl/146721 to your computer and use it in GitHub Desktop.
Save szbl/146721 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Append Content
Description: Append content to your posts/pages, useful for repetitious messaging and calls to action. Apply template to all pages/posts, only to posts, or only to pages.
Version: 1.0
Author URI: http://theandystratton.com
Author: Andy Stratton <theandystratton@gmail.com>
*/
class APContent {
function APContent() {
}
function admin_menu() {
add_submenu_page('options-general.php', 'Append Content', 'Append Content', 8, basename(__FILE__), array($this,'main'));
}
function admin_head() {
if ( $_GET['page'] == basename(__FILE__) ) {
?>
<script type="text/javascript" src="../wp-includes/js/tinymce/tiny_mce.js"></script>
<script type="text/javascript">
<!--
tinyMCE.init({
theme : "advanced",
theme_advanced_toolbar_location:"top",
theme_advanced_buttons1:"bold,italic,strikethrough,|,bullist,numlist,blockquote,|,justifyleft,justifycenter,justifyright,|,link,unlink,wp_more,|,spellchecker,fullscreen,wp_adv|underline,justifyfull,forecolor,|,pastetext,pasteword,removeformat,|,media,charmap,|,outdent,indent,|,undo,redo,wp_help",
theme_advanced_buttons2:"",theme_advanced_buttons3:"", theme_advanced_buttons4:"", language:"en",
theme_advanced_toolbar_align:"left", theme_advanced_statusbar_location:"bottom", theme_advanced_resizing:"1",
mode : "exact",
elements : "content",
skin: "wp_theme",
width : "565",
height : "140"
});
-->
</script>
<?php
}
}
function the_content( $content ) {
$publish = get_option('apc_publish');
$apc_content = wpautop( get_option('apc_content') );
switch ( $publish ) {
case 'all':
$content .= "\n\n" . $apc_content;
break;
case 'posts':
if ( !is_page(get_the_ID()) ) {
$content .= "\n\n" . $apc_content;
}
break;
case 'pages':
if ( is_page(get_the_ID()) ) {
$content .= "\n\n" . $apc_content;
}
break;
default:
break;
}
return $content;
}
function main() {
?>
<div class="wrap">
<h2>Append Content Plugin Settings</h2>
<h3>Content Settings</h3>
<?php
if ( sizeof($_POST['apc_content']) ) {
$apc_content = stripslashes($_POST['apc_content']);
update_option('apc_content', $apc_content);
echo '<div class="message updated"><p>Content settings updated.</p></div>';
}
?>
<form method="post" action="?<?php echo $_SERVER['QUERY_STRING']; ?>">
<p>
<label for="content">
Content to Append:
</label>
<textarea id="content" name="apc_content" rows="8" cols="60"><?php
echo htmlentities(get_option('apc_content'));
?></textarea>
</p>
<p>
<input type="submit" value="Save Your Content" class="button-primary" />
</p>
</form>
<h3>Publishing Settings</h3>
<?php
if ( sizeof($_POST['apc_publish']) ) {
if ( in_array($_POST['apc_publish'], array('all','posts','pages')) ) {
update_option('apc_publish', $_POST['apc_publish']);
echo '<div class="message updated"><p>Publishing settings updated.</p></div>';
}
}
$apc_publish = get_option('apc_publish', 'all');
?>
<form method="post" action="?<?php echo $_SERVER['QUERY_STRING']; ?>">
<p>
Choose which posts/pages you'd like to apply content to:
</p>
<div style="margin-left: 1.5em;">
<p>
<label for="all_posts_pages">
<input type="radio" id="all_posts_pages" name="apc_publish" value="all"<?php
if ( $apc_publish == 'all' ) echo 'checked="checked"';
?> />
All posts/pages.
</label>
</p>
<p>
<label for="posts_only">
<input type="radio" id="posts_only" name="apc_publish" value="posts"<?php
if ( $apc_publish == 'posts' ) echo 'checked="checked"';
?> />
Only to posts.
</label>
</p>
<p>
<label for="pages_only">
<input type="radio" id="pages_only" name="apc_publish" value="pages"<?php
if ( $apc_publish == 'pages' ) echo 'checked="checked"';
?> />
Only to pages.
</label>
</p>
</div>
<p>
<input type="submit" value="Save Publishing Settings" class="button-primary" />
</p>
</form>
</div>
<?php
}
}
$apcontent = new APContent();
add_action('admin_menu', array($apcontent, 'admin_menu'));
add_action('admin_head', array($apcontent, 'admin_head'));
add_filter('the_content', array($apcontent, 'the_content'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment