Advertisement
Guest User

Untitled

a guest
Nov 5th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.41 KB | None | 0 0
  1. <?php
  2. /**
  3.  
  4. Plugin Name: WP Analytics Tracking
  5. Plugin URI: http://neoptin.com/
  6. Description: Manage Google Analytics code or any other Tracking code
  7. Author: Neoptin
  8. Version: 1.0.1
  9. Author URI: http://neoptin.com/
  10.  
  11. Copyright 2012 Neoptin
  12.  
  13. */
  14.  
  15.  
  16. //===============================================
  17. // Plugin setup
  18. //===============================================
  19.  
  20. /**
  21.  * Hooks for install
  22.  */
  23. if (function_exists('register_uninstall_hook')) {
  24.   register_deactivation_hook(__FILE__, 'wat_uninstall');
  25. }
  26.  
  27. /**
  28.  * Hooks for uninstall
  29.  */
  30. if( function_exists('register_activation_hook')){
  31.   register_activation_hook(__FILE__, 'wat_install');
  32. }
  33.  
  34.  
  35. /**
  36.  * INSTALL function
  37.  */
  38. function wat_install() {
  39.   // Nothing to do
  40. }
  41.  
  42. /**
  43.  * UNINSTALL function
  44.  */
  45. function wat_uninstall() {
  46.   // Unregister setting
  47.   unregister_setting('wat-options-group', 'wat_content');
  48. }
  49.  
  50.  
  51. /**
  52.  * Register menu
  53.  */
  54. add_action(
  55.   'admin_menu',
  56.   function() {
  57.     add_options_page(
  58.       __("WP Analytics Tracking Options", "wp-analytics-tracking"), // Settings page title
  59.       __("WP Analytics Tracking", "wp-analytics-tracking"),         // Menu name
  60.       'administrator',                                              // Role needed
  61.       'wp-analytics-tracking',                                      // ID
  62.       'wat_settings_page'                                           // Callback function
  63.     );
  64.   }
  65. );
  66.  
  67. /**
  68.  * Register option
  69.  */
  70. add_action(
  71.   'admin_init',
  72.   function() {
  73.     // We need a textarea
  74.     register_setting('wat-options-group', 'wat_content');
  75.   }
  76. );
  77.  
  78. /**
  79.  * Display notice once activated ("Please configure it!")
  80.  */
  81. add_action(
  82.   'admin_notices',
  83.   function() {
  84.     if (strlen(trim(get_option('wat_content'))) == 0 &&
  85.         substr( $_SERVER["PHP_SELF"], -11 ) == 'plugins.php') {
  86.       echo '
  87.      <div class="error">
  88.        <p><strong>'
  89.           .sprintf(
  90.              __("%s is activated but no tracking code are specified. Please go to the <a href='%s'>settings page</a> in order to fill your tracking codes.", "wp-analytics-tracking"),
  91.               __("WP Analytics Tracking"), get_admin_url().'options-general.php?page=wp-analytics-tracking'
  92.            )
  93.         .'</strong></p>
  94.      </div>';
  95.     }
  96.   }
  97. );
  98.  
  99.  
  100.  
  101. //===============================================
  102. // Back Office
  103. //===============================================
  104.  
  105. /**
  106.  * Display form of admin settings page
  107.  */
  108. function wat_settings_page() {
  109.   echo '
  110. <div class="wrap">
  111.  <h2>'.__("WP Analytics Tracking Options").'</h2>
  112.  
  113.  <form method="post" action="options.php">';
  114.  
  115.   settings_fields('wat-options-group');
  116.  
  117.   echo '
  118.    <table class="form-table">
  119.      <tr valign="top">
  120.        <th scope="row">
  121.          '.__("Tracking codes", "wp-analytics-tracking").'
  122.        </th>
  123.        <td>
  124.          <textarea name="wat_content"
  125.                    style="font-family:monospace;"
  126.                    rows="15"
  127.                    cols="60">'.get_option('wat_content').'</textarea>
  128.        </td>
  129.      </tr>
  130.    </table>';
  131.  
  132.   submit_button();
  133.  
  134.   echo '
  135.  </form>
  136. </div>';
  137. }
  138.  
  139.  
  140.  
  141.  
  142. //===============================================
  143. // Front Office
  144. //===============================================
  145.  
  146. /**
  147.  * Display tracking codes in the footer
  148.  */
  149. add_action(
  150.   'wp_footer',
  151.   function() {
  152.     echo "<!-- Plugin: WP Analytics Tracking -->\n"
  153.     .get_option('wat_content');
  154.   }
  155. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement