Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Plugin Name: CS Plugin Template
- * Description: ...
- * Author: Martin Pultz
- * Version: 1.0
- * Author URI: http://www.casensitive.ca
- */
- define('CS_VERSION', 1.0);
- define('CS_PLUGIN_URL', plugin_dir_url( __FILE__ ));
- if (!class_exists("CSPI_plugin"))
- {
- class CSPI_plugin
- {
- // unique admin options
- var $adminOptionsName = 'CSPI_PluginOptions';
- var $adminUsersName = 'CSPI_PluginAdminUsersOptions';
- // constructor
- function CSPI_plugin()
- {
- } // end function CSPI_plugin()
- function init()
- {
- // store defaults on plugin activation
- $this->getAdminOptions();
- } // end function init()
- function getAdminOptions()
- {
- // assign defaults for admin options
- $cs_adminOptions = array('show_header' => true,
- 'add_content' => true,
- 'comment_author' => true,
- 'content' => '');
- // attempt to find previous options that may have been stored
- $cs_options = get_option($this->adminOptionsName);
- if(!empty($cs_options))
- {
- // overwrite default options
- foreach($cs_options as $key => $option)
- $cs_adminOptions[$key] = $option;
- }
- // store options in wp database
- update_option($this->adminOptionsName, $cs_adminOptions);
- return $cs_adminOptions;
- } // end function getAdminOptions()
- function printAdminPage()
- {
- $cs_options = $this->getAdminOptions();
- // load admin options
- if (isset($_POST['update_cs_plugin']))
- {
- if (isset($_POST['cs_header']))
- {
- $cs_options['show_header'] = $_POST['cs_header'];
- }
- if (isset($_POST['cs_addContent']))
- {
- $cs_options['add_content'] = $_POST['cs_addContent'];
- }
- if (isset($_POST['cs_author']))
- {
- $cs_options['comment_author'] = $_POST['cs_author'];
- }
- if (isset($_POST['cs_content']))
- {
- $cs_options['content'] = apply_filters('content_save_pre', $_POST['cs_Content']);
- }
- update_option($this->adminOptionsName, $cs_options);
- ?>
- <div class="updated">
- <p><strong><?php _e("Settings Updated.", "CSPI_plugin");?></strong></p>
- </div>
- <div class=wrap>
- <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
- <h2>CSPI Plugin</h2>
- <h3>Content to Add to the End of a Post</h3>
- <textarea name="cs_content" style="width: 80%; height: 100px;"><?php _e(apply_filters('format_to_edit',$devOptions['content']), 'CSPI_plugin') ?></textarea>
- <h3>Allow Comment Code in the Header?</h3>
- <p>Selecting "No" will disable the comment code inserted in the header.</p>
- <p><label for="cs_header_yes">
- <input type="radio" id="cs_header_yes" name="cs_header" value="true" <?php if($devOptions['show_header'] == "true") { _e('checked="checked"', "CSPI_plugin"); }?> /> Yes</label>
- <label for="cs_header_no">
- <input type="radio" id="cs_header_no" name="cs_header" value="false" <?php if ($devOptions['show_header'] == "false") { _e('checked="checked"', "CSPI_plugin"); }?>/> No</label></p>
- <h3>Allow Content Added to the End of a Post?</h3>
- <p>Selecting "No" will disable the content from being added into the end of a post.</p>
- <p><label for="cs_addContent_yes">
- <input type="radio" id="cs_addContent_yes" name="cs_addContent" value="true" <?php if ($devOptions['add_content'] == "true") { _e('checked="checked"', "CSPI_plugin"); }?> /> Yes</label>
- <label for="cs_addContent_no">
- <input type="radio" id="cs_addContent_no" name="cs_addContent" value="false" <?php if ($devOptions['add_content'] == "false") { _e('checked="checked"', "CSPI_plugin"); }?>/> No</label></p>
- <h3>Allow Comment Authors to be Uppercase?</h3>
- <p>Selecting "No" will leave the comment authors alone.</p>
- <p><label for="cs_author_yes">
- <input type="radio" id="cs_author_yes" name="cs_author" value="true" <?php if($devOptions['comment_author'] == "true") { _e('checked="checked"', "CSPI_plugin"); }?> /> Yes</label>
- <label for="cs_author_no">
- <input type="radio" id="cs_author_no" name="cs_author" value="false" <?php if($devOptions['comment_author'] == "false") { _e('checked="checked"', "CSPI_plugin"); }?>/> No</label></p>
- <div class="submit">
- <input type="submit" name="update_cs_plugin" value="<?php _e('Update Settings', 'CSPI_plugin') ?>" /></div>
- </form>
- </div>
- <?php
- }
- } // end printAdminPage()
- function addHeaderCode()
- {
- ?><!-- CSPI_Plugin --><?php
- } // end function addHeaderCode()
- function addContent($content='')
- {
- $content = '<p>CSPI Plugin</p>';
- return $content;
- } // end function addContent()
- function authorUpperCase($author='')
- {
- return strtoupper($author);
- } // end function authorUpperCase()
- }
- } // end Class CSPI_plugin
- if( class_exists("CSPI_plugin") )
- {
- $cspi_plugin = new CSPI_plugin();
- }
- // initialize admin panel
- if ( !function_exists("CSPI_plugin_ap") )
- {
- function CSPI_plugin_ap()
- {
- global $cs_plugin;
- // does $cs_plugin exist?
- if (!isset($cs_plugin)) return;
- //
- if (function_exists('add_options_page'))
- {
- // WP: add_options_page(page title, menu title, access_level/capability, file, [function])
- add_options_page('CSPI Plugin', 'CSPI Plugin Page', 9,
- basename(__FILE__), array(&$cs_plugin, 'printAdminPage'));
- }
- }
- }
- // actions and filters
- if( isset($cspi_plugin) )
- {
- /**
- * Actions
- */
- // run initialization when plugin is activated
- add_action('activate_plugin/plugin.php', array(&$cspi_plugin));
- // insert code into <head>
- add_action('wp_head', array(&$cspi_plugin, 'addHeaderCode'), 1);
- // run admin panel page
- add_action('admin_menu', 'CSPI_plugin_ap');
- /**
- * Filters
- */
- //
- add_filter('the_content', array(&$cspi_plugin, 'addContent'));
- //
- add_filter('get_comment_author', array(&$cspi_plugin, 'authorUpperCase'));
- }
- /* END OF FILE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement