Plugin Directory

Changeset 1494668


Ignore:
Timestamp:
09/12/2016 05:12:47 PM (10 years ago)
Author:
salubrio
Message:

Multisite uninstall

Location:
add-code-to-head/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • add-code-to-head/trunk/.gitignore

    r1263618 r1494668  
     1.project
     2.settings
    13*~
    24*.swp
  • add-code-to-head/trunk/add-code-to-head.php

    r1494667 r1494668  
    33 * Plugin Name: Add Code to Head
    44 * Plugin URI: http://www.hbjitney.com/wordpress/add-code-to-head
    5  * Description: Adds any code to a page's head (javascript, css, etc)
    6  * Version: 1.0
    7  * Author: Bryan Hanks, PMP
     5 * Description: Adds custom html code (javascript, css, etc.) to each public page's head
     6 * Version: 1.05
     7 * Author: HBJitney, LLC
    88 * Author URI: http://hbjitney.com/
    99 * License: GPL3
     
    2323 */
    2424
    25 class AddCodeToHead {
    26     function __construct() {
    27         // add the admin options page
    28         add_action( 'admin_menu', array( $this, 'add_admin' ) );
    29         add_action( 'admin_init', array( $this, 'admin_init' ) );
    30         add_action( 'wp_head', array( $this, 'display' ) );
    31     }
     25if ( !class_exists('AddCodeToHead' ) ) {
     26    /**
     27    * Wrapper class to isolate us from the global space in order
     28    * to prevent method collision
     29    */
     30    class AddCodeToHead {
     31        /**
     32         * Set up all actions, instantiate other
     33         */
     34        function __construct() {
     35            add_action( 'admin_menu', array( $this, 'add_admin' ) );
     36            add_action( 'admin_init', array( $this, 'admin_init' ) );
     37            add_action( 'wp_head', array( $this, 'display' ) );
     38        }
    3239
    33     function add_admin() {
    34         add_options_page('Add Code to Head', 'Add Code to Head', 'manage_options', 'acth_plugin', array( $this, 'plugin_options_page' ) );
    35     }
     40        /**
     41         * Add our options to the settings menu
     42         */
     43        function add_admin() {
     44            add_options_page('Add Code to Head', 'Add Code to Head', 'manage_options', 'acth_plugin', array( $this, 'plugin_options_page' ) );
     45        }
    3646
    37     function plugin_options_page() { ?>
    38     <div class="plugin-options">
    39      <h2><span>Add Code to Head</span></h2>
    40      <form action="options.php" method="post">
    41       <?php
    42       settings_fields('acth_options');
    43       do_settings_sections('acth_plugin'); ?>
     47        /**
     48         * Callback for options page - set up page title and instantiate fields
     49         */
     50        function plugin_options_page() {
     51?>
     52        <div class="plugin-options">
     53         <h2><span>Add Code to Head</span></h2>
     54         <form action="options.php" method="post">
     55<?php
     56          settings_fields( 'acth_options' );
     57          do_settings_sections( 'acth_plugin' );
     58?>
    4459
    45       <input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />
    46      </form>
    47     </div>
    48     <?php }
     60          <input name="Submit" type="submit" value="<?php esc_attr_e( 'Save Changes' ); ?>" />
     61         </form>
     62        </div>
     63<?php
     64        }
    4965
    50     // define fields
     66        /*
     67         * Define options section (only one) and fields (also only one!)
     68         */
     69        function admin_init() {
     70            register_setting( 'acth_options', 'acth_options', array( $this, 'options_validate' ) );
     71            add_settings_section( 'acth_section', '', array( $this, 'main_section' ), 'acth_plugin' );
     72            add_settings_field( 'acth_string', 'Code', array( $this, 'text_field'), 'acth_plugin', 'acth_section');
     73        }
    5174
    52     function admin_init() {
    53         register_setting( 'acth_options', 'acth_options', array( $this, 'options_validate' ) );
    54         add_settings_section( 'acth_section', '', array( $this, 'main_section' ), 'acth_plugin' );
    55         add_settings_field( 'acth_string', 'Code', array( $this, 'text_field'), 'acth_plugin', 'acth_section');
    56     }
     75        /*
     76         * Static content for options section
     77         */
     78        function main_section() {
     79            // GNDN
     80        }
    5781
    58     function main_section() { ?>
    59     <!--<p>Main section</p>-->
    60     <?php }
     82        /*
     83         * Code for field
     84         */
     85        function text_field() {
     86            $options = get_option( 'acth_options' );
     87?>
     88                <textarea id="acth_options" name="acth_options[text_string]" rows="20" cols="90"><?php _e( $options['text_string'] );?></textarea>
     89<?php
     90        }
    6191
    62     // Code for field
    63     function text_field() {
    64         $options = get_option('acth_options'); ?>
    65             <textarea id="acth_options" name="acth_options[text_string]" rows="20" cols="90"><?php _e($options['text_string']); ?></textarea>
    66     <?php }
     92        /*
     93         * No validation, just remove leading and trailing spaces
     94         */
     95        function options_validate($input) {
     96            $newinput['text_string'] = trim( $input['text_string'] );
     97            return $newinput;
     98        }
    6799
    68 
    69     // Validate input
    70     function options_validate($input) {
    71         $newinput['text_string'] = trim( $input['text_string'] );
    72         return $newinput;
    73     }
    74 
    75     // Display it
    76     function display() {
    77         if( !is_admin() ) {
    78             $options = get_option('acth_options');
    79             _e( "<!--- ADD TEXT TO HEAD plugin ************************ -->" );
    80             _e( $options['text_string'] );
    81             _e( "<!--- /ADD TEXT TO HEAD plugin *********************** -->" );
     100        /*
     101         * Display the code(s) on the public page.
     102         * We do an extra check to ensure that the codes don't show up
     103         * in the admin tool.
     104         */
     105        function display() {
     106            if( !is_admin() ) {
     107                $options = get_option( 'acth_options' );
     108                _e( $options['text_string'] );
     109            }
    82110        }
    83111    }
    84112}
    85 new AddCodeToHead();
     113
     114/*
     115 * Sanity - was there a problem setting up the class? If so, bail with error
     116 * Otherwise, class is now defined; create a new one it to get the ball rolling.
     117 */
     118if( class_exists( AddCodeToHead ) ) {
     119    new AddCodeToHead();
     120} else {
     121    $message = "<h2 style='color:red'>Error in plugin</h2>
     122    <p>Sorry about that! Plugin <span style='color:blue;font-family:monospace'>add-code-to-head</span> reports that it was unable to start.</p>
     123    <p><a href='mailto:[email protected]?subject=Add-code-to-head%20error&body=What version of Wordpress are you running? Please paste a list of your current active plugins here:'>Please report this error</a>.
     124    Meanwhile, here are some things you can try:</p>
     125    <ul><li>Make sure you are running the latest version of the plugin; update the plugin if not.</li>
     126    <li>There might be a conflict with other plugins. You can try disabling every other plugin; if the problem goes away, there is a conflict.</li>
     127    <li>Try a different theme to see if there's a conflict between the theme and the plugin.</li>
     128    </ul>";
     129    wp_die( $message );
     130}
    86131?>
Note: See TracChangeset for help on using the changeset viewer.