Advertisement
Guest User

Untitled

a guest
Jan 11th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.02 KB | None | 0 0
  1. <?php
  2. /**
  3. * Plugin Name: CS Plugin Template
  4. * Description: ...
  5. * Author: Martin Pultz
  6. * Version: 1.0
  7. * Author URI: http://www.casensitive.ca
  8. */
  9.  
  10. define('CS_VERSION', 1.0);
  11. define('CS_PLUGIN_URL', plugin_dir_url( __FILE__ ));
  12.  
  13. if (!class_exists("CSPI_plugin"))
  14. {
  15. class CSPI_plugin
  16. {
  17. // unique admin options
  18. var $adminOptionsName = 'CSPI_PluginOptions';
  19. var $adminUsersName = 'CSPI_PluginAdminUsersOptions';
  20.  
  21. // constructor
  22. function CSPI_plugin()
  23. {
  24.  
  25. } // end function CSPI_plugin()
  26.  
  27. function init()
  28. {
  29. // store defaults on plugin activation
  30. $this->getAdminOptions();
  31. } // end function init()
  32.  
  33. function getAdminOptions()
  34. {
  35. // assign defaults for admin options
  36. $cs_adminOptions = array('show_header' => true,
  37. 'add_content' => true,
  38. 'comment_author' => true,
  39. 'content' => '');
  40.  
  41. // attempt to find previous options that may have been stored
  42. $cs_options = get_option($this->adminOptionsName);
  43. if(!empty($cs_options))
  44. {
  45. // overwrite default options
  46. foreach($cs_options as $key => $option)
  47. $cs_adminOptions[$key] = $option;
  48. }
  49. // store options in wp database
  50. update_option($this->adminOptionsName, $cs_adminOptions);
  51. return $cs_adminOptions;
  52. } // end function getAdminOptions()
  53.  
  54. function printAdminPage()
  55. {
  56. $cs_options = $this->getAdminOptions();
  57.  
  58. // load admin options
  59. if (isset($_POST['update_cs_plugin']))
  60. {
  61. if (isset($_POST['cs_header']))
  62. {
  63. $cs_options['show_header'] = $_POST['cs_header'];
  64. }
  65.  
  66. if (isset($_POST['cs_addContent']))
  67. {
  68. $cs_options['add_content'] = $_POST['cs_addContent'];
  69. }
  70.  
  71. if (isset($_POST['cs_author']))
  72. {
  73. $cs_options['comment_author'] = $_POST['cs_author'];
  74. }
  75.  
  76. if (isset($_POST['cs_content']))
  77. {
  78. $cs_options['content'] = apply_filters('content_save_pre', $_POST['cs_Content']);
  79. }
  80.  
  81. update_option($this->adminOptionsName, $cs_options);
  82. ?>
  83.  
  84. <div class="updated">
  85. <p><strong><?php _e("Settings Updated.", "CSPI_plugin");?></strong></p>
  86. </div>
  87.  
  88. <div class=wrap>
  89. <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
  90. <h2>CSPI Plugin</h2>
  91. <h3>Content to Add to the End of a Post</h3>
  92. <textarea name="cs_content" style="width: 80%; height: 100px;"><?php _e(apply_filters('format_to_edit',$devOptions['content']), 'CSPI_plugin') ?></textarea>
  93. <h3>Allow Comment Code in the Header?</h3>
  94. <p>Selecting "No" will disable the comment code inserted in the header.</p>
  95. <p><label for="cs_header_yes">
  96. <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>&nbsp;&nbsp;&nbsp;&nbsp;
  97. <label for="cs_header_no">
  98. <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>
  99. <h3>Allow Content Added to the End of a Post?</h3>
  100. <p>Selecting "No" will disable the content from being added into the end of a post.</p>
  101. <p><label for="cs_addContent_yes">
  102. <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>&nbsp;&nbsp;&nbsp;&nbsp;
  103. <label for="cs_addContent_no">
  104. <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>
  105. <h3>Allow Comment Authors to be Uppercase?</h3>
  106. <p>Selecting "No" will leave the comment authors alone.</p>
  107. <p><label for="cs_author_yes">
  108. <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>&nbsp;&nbsp;&nbsp;&nbsp;
  109. <label for="cs_author_no">
  110. <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>
  111. <div class="submit">
  112. <input type="submit" name="update_cs_plugin" value="<?php _e('Update Settings', 'CSPI_plugin') ?>" /></div>
  113. </form>
  114. </div>
  115.  
  116. <?php
  117. }
  118. } // end printAdminPage()
  119.  
  120. function addHeaderCode()
  121. {
  122. ?><!-- CSPI_Plugin --><?php
  123.  
  124. } // end function addHeaderCode()
  125.  
  126. function addContent($content='')
  127. {
  128. $content = '<p>CSPI Plugin</p>';
  129. return $content;
  130. } // end function addContent()
  131.  
  132. function authorUpperCase($author='')
  133. {
  134. return strtoupper($author);
  135. } // end function authorUpperCase()
  136. }
  137.  
  138. } // end Class CSPI_plugin
  139.  
  140. if( class_exists("CSPI_plugin") )
  141. {
  142. $cspi_plugin = new CSPI_plugin();
  143. }
  144.  
  145. // initialize admin panel
  146. if ( !function_exists("CSPI_plugin_ap") )
  147. {
  148. function CSPI_plugin_ap()
  149. {
  150. global $cs_plugin;
  151. // does $cs_plugin exist?
  152. if (!isset($cs_plugin)) return;
  153.  
  154. //
  155. if (function_exists('add_options_page'))
  156. {
  157. // WP: add_options_page(page title, menu title, access_level/capability, file, [function])
  158. add_options_page('CSPI Plugin', 'CSPI Plugin Page', 9,
  159. basename(__FILE__), array(&$cs_plugin, 'printAdminPage'));
  160. }
  161. }
  162. }
  163.  
  164. // actions and filters
  165. if( isset($cspi_plugin) )
  166. {
  167. /**
  168. * Actions
  169. */
  170.  
  171. // run initialization when plugin is activated
  172. add_action('activate_plugin/plugin.php', array(&$cspi_plugin));
  173.  
  174. // insert code into <head>
  175. add_action('wp_head', array(&$cspi_plugin, 'addHeaderCode'), 1);
  176.  
  177. // run admin panel page
  178. add_action('admin_menu', 'CSPI_plugin_ap');
  179.  
  180. /**
  181. * Filters
  182. */
  183. //
  184. add_filter('the_content', array(&$cspi_plugin, 'addContent'));
  185.  
  186. //
  187. add_filter('get_comment_author', array(&$cspi_plugin, 'authorUpperCase'));
  188. }
  189.  
  190. /* END OF FILE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement