PluginProbe
Add Code To Head / 1.13
Add Code To Head v1.13
trunk 1.07 1.09 1.13 1.15 1.17 1.23
add-code-to-head / add-code-to-head.php

add-code-to-head.php in Add Code To Head 1.13, at add-code-to-head.php

132 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugin Name: Add Code to Head
4 * Plugin URI: http://hbjitney.com/add-code-to-header.html
5 * Description: Adds custom html code (javascript, css, etc.) to each public page's head
6 * Version: 1.09
7 * Author: HBJitney, LLC
8 * Author URI: http://hbjitney.com/
9 * License: GPL3
10
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 */
24
25 if ( !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 }
39
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 }
46
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 ?>
59
60 <input name="Submit" type="submit" value="<?php esc_attr_e( 'Save Changes' ); ?>" />
61 </form>
62 </div>
63 <?php
64 }
65
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 }
74
75 /*
76 * Static content for options section
77 */
78 function main_section() {
79 // GNDN
80 }
81
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 }
91
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 }
99
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 }
110 }
111 }
112 }
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 */
118 if( 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:support@hbjitney.com?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 }
131 ?>
132