Changeset 1948199
- Timestamp:
- 09/27/2018 06:24:16 PM (8 years ago)
- Location:
- addfunc-head-footer-code
- Files:
-
- 5 added
- 5 edited
-
assets/screenshot-1.jpg (modified) (previous)
-
assets/screenshot-2.jpg (modified) (previous)
-
tags/2 (added)
-
tags/2/addfunc-head-footer-code.php (added)
-
tags/2/index.php (added)
-
tags/2/options.php (added)
-
tags/2/readme.txt (added)
-
trunk/addfunc-head-footer-code.php (modified) (10 diffs)
-
trunk/options.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
addfunc-head-footer-code/trunk/addfunc-head-footer-code.php
r1729674 r1948199 4 4 Plugin URI: 5 5 Description: Allows admins to add code to the <head> and/or <footer> of an individual post and/or site-wide. Ideal for scripts such as Google Analytics conversion tracking codes and any other general or page-specific JavaScript. 6 Version: 1.56 Version: 2 7 7 Author: AddFunc 8 8 Author URI: http://profiles.wordpress.org/addfunc … … 25 25 */ 26 26 27 if(!class_exists('aF hfc_class')) :28 define('AFHDFTRCD_ID', 'aFhfc');29 define('AFHDFTRCD_NICK', 'Head & Footer Code');30 class aF hfc_class27 if(!class_exists('aFHFCClass')) : 28 define('AFHDFTRCD_ID', 'aFhfc'); 29 define('AFHDFTRCD_NICK', 'Head & Footer Code'); 30 class aFHFCClass 31 31 { 32 32 public static function file_path($file) … … 38 38 register_setting(AFHDFTRCD_ID.'_options', 'aFhfc_site_wide_head_code'); 39 39 register_setting(AFHDFTRCD_ID.'_options', 'aFhfc_head_code_priority'); 40 register_setting(AFHDFTRCD_ID.'_options', 'aFhfc_site_wide_body_code'); 40 41 register_setting(AFHDFTRCD_ID.'_options', 'aFhfc_site_wide_footer_code'); 41 42 register_setting(AFHDFTRCD_ID.'_options', 'aFhfc_footer_code_priority'); … … 43 44 public static function menu() 44 45 { 45 add_options_page(AFHDFTRCD_NICK.' Plugin Options', AFHDFTRCD_NICK, 'manage_options', AFHDFTRCD_ID.'_options', array('aF hfc_class', 'options_page'));46 add_options_page(AFHDFTRCD_NICK.' Plugin Options', AFHDFTRCD_NICK, 'manage_options', AFHDFTRCD_ID.'_options', array('aFHFCClass', 'options_page')); 46 47 } 47 48 public static function options_page() … … 57 58 { 58 59 $site_head_code = get_option('aFhfc_site_wide_head_code'); 59 $meta_head_code = get_post_meta(get_the_ID(),'aFhfc_head_code',true);60 $meta_head_code = ((is_archive()) || (is_author()) || (is_category()) || (is_tag()) || (is_home()) || (is_search()) || (is_404())) ? '' : get_post_meta(get_the_ID(),'aFhfc_head_code',true); 60 61 $head_replace = get_post_meta(get_the_ID(),'aFhfc_head_replace',true); 61 62 if(!empty($head_replace)){ … … 65 66 } 66 67 } 68 public static function output_body_code() 69 { 70 $site_body_code = get_option('aFhfc_site_wide_body_code'); 71 $meta_body_code = ((is_archive()) || (is_author()) || (is_category()) || (is_tag()) || (is_home()) || (is_search()) || (is_404())) ? '' : get_post_meta(get_the_ID(),'aFhfc_body_code',true); 72 $body_replace = get_post_meta(get_the_ID(),'aFhfc_body_replace',true); 73 if(!empty($body_replace)){ 74 return $meta_body_code."\n"; 75 }else{ 76 return $site_body_code."\n".$meta_body_code."\n"; 77 } 78 } 67 79 public static function output_footer_code() 68 80 { 69 81 $site_footer_code = get_option('aFhfc_site_wide_footer_code'); 70 $meta_footer_code = get_post_meta(get_the_ID(),'aFhfc_footer_code',true);82 $meta_footer_code = ((is_archive()) || (is_author()) || (is_category()) || (is_tag()) || (is_home()) || (is_search()) || (is_404())) ? '' : get_post_meta(get_the_ID(),'aFhfc_footer_code',true); 71 83 $footer_replace = get_post_meta(get_the_ID(),'aFhfc_footer_replace',true); 72 84 if(!empty($footer_replace)){ … … 79 91 if (is_admin()) 80 92 { 81 add_action('admin_init', array('aF hfc_class','register'));82 add_action('admin_menu', array('aF hfc_class','menu'));93 add_action('admin_init', array('aFHFCClass','register')); 94 add_action('admin_menu', array('aFHFCClass','menu')); 83 95 } 84 96 $head_code_prior = get_option('aFhfc_head_code_priority'); 85 97 if(!empty($head_code_prior)){ 86 add_action('wp_head', array('aF hfc_class','output_head_code'),$head_code_prior);98 add_action('wp_head', array('aFHFCClass','output_head_code'),$head_code_prior); 87 99 } 88 100 else { 89 add_action('wp_head', array('aFhfc_class','output_head_code')); 90 } 101 add_action('wp_head', array('aFHFCClass','output_head_code')); 102 } 103 function aFHFCBuffRec(){ 104 ob_start(); 105 } 106 add_action('wp_head','aFHFCBuffRec'); 107 function aFHFCBuffPlay(){ 108 $body_code = new aFHFCClass; 109 $tape = ob_get_clean(); 110 $pattern = '/<[bB][oO][dD][yY]\s[A-Za-z]{2,5}[A-Za-z0-9 "_,=%*\'\/():;\[\]\-\.]+>|<body>/'; 111 preg_match($pattern,$tape,$queue); 112 $q = $queue[0]; 113 $q = $q.$body_code->output_body_code(); 114 echo preg_replace($pattern,$q,$tape); 115 } 116 add_action('wp_print_footer_scripts','aFHFCBuffPlay'); 91 117 $footer_code_prior = get_option('aFhfc_footer_code_priority'); 92 118 if(!empty($footer_code_prior)){ 93 add_action('wp_footer', array('aF hfc_class','output_footer_code'),$footer_code_prior);119 add_action('wp_footer', array('aFHFCClass','output_footer_code'),$footer_code_prior); 94 120 } 95 121 else { 96 add_action('wp_footer', array('aF hfc_class','output_footer_code'));122 add_action('wp_footer', array('aFHFCClass','output_footer_code')); 97 123 } 98 124 endif; … … 118 144 $head_text = isset($values['aFhfc_head_code']) ? esc_attr($values['aFhfc_head_code'][0]) : ''; 119 145 $head_replace = isset($values['aFhfc_head_replace']) ? esc_attr($values['aFhfc_head_replace'][0]) : ''; 146 $body_text = isset($values['aFhfc_body_code']) ? esc_attr($values['aFhfc_body_code'][0]) : ''; 147 $body_replace = isset($values['aFhfc_body_replace']) ? esc_attr($values['aFhfc_body_replace'][0]) : ''; 120 148 $footer_text = isset($values['aFhfc_footer_code']) ? esc_attr($values['aFhfc_footer_code'][0]) : ''; 121 149 $footer_replace = isset($values['aFhfc_footer_replace']) ? esc_attr($values['aFhfc_footer_replace'][0]) : ''; … … 127 155 <input id="aFhfc_head_replace" type="checkbox" name="aFhfc_head_replace" value="1" <?php checked($head_replace,'1'); ?> /> 128 156 <label for="aFhfc_head_replace">Replace Site-wide Head Code</label> 157 </p> 158 <p> 159 <label for="aFhfc_body_code">Body Start: <span class="dashicons dashicons-info" title="Inserts immediately after the opening body tag."></span></label> 160 <textarea class="large-text" name="aFhfc_body_code" id="aFhfc_body_code"><?php echo $body_text; ?></textarea> 161 <input id="aFhfc_body_replace" type="checkbox" name="aFhfc_body_replace" value="1" <?php checked($body_replace,'1'); ?> /> 162 <label for="aFhfc_body_replace">Replace Site-wide Body Code</label> 129 163 </p> 130 164 <p> … … 139 173 function aFhfc_save($post_id) 140 174 { 141 if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; 142 if( !isset( $_POST['aFhfc_mb_nonce'] ) || !wp_verify_nonce( $_POST['aFhfc_mb_nonce'], 'aFhfc_nonce' ) ) return; 143 if( !current_user_can( 'manage_options' ) ) return; 144 if( isset( $_POST['aFhfc_head_code'] ) ) 145 if( empty( $_POST['aFhfc_head_code'] ) ) 146 delete_post_meta( $post_id, 'aFhfc_head_code' ); 175 if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)return; 176 if(!isset($_POST['aFhfc_mb_nonce']) || !wp_verify_nonce($_POST['aFhfc_mb_nonce'],'aFhfc_nonce'))return; 177 if(!current_user_can('manage_options'))return; 178 179 if(isset($_POST['aFhfc_head_code'])) 180 if(empty($_POST['aFhfc_head_code'])) 181 delete_post_meta($post_id,'aFhfc_head_code'); 147 182 else 148 update_post_meta( $post_id, 'aFhfc_head_code',$_POST['aFhfc_head_code']);149 $aFHFCHRChk = (isset($_POST['aFhfc_head_replace']) && $_POST['aFhfc_head_replace'])? '1' :'';183 update_post_meta($post_id,'aFhfc_head_code',$_POST['aFhfc_head_code']); 184 $aFHFCHRChk = (isset($_POST['aFhfc_head_replace']) && $_POST['aFhfc_head_replace'])?'1':''; 150 185 if(empty($_POST['aFhfc_head_replace'])) 151 186 delete_post_meta($post_id,'aFhfc_head_replace'); 152 187 else 153 188 update_post_meta($post_id,'aFhfc_head_replace',$aFHFCHRChk); 154 if( isset( $_POST['aFhfc_footer_code'] ) ) 155 if( empty( $_POST['aFhfc_footer_code'] ) ) 156 delete_post_meta( $post_id, 'aFhfc_footer_code' ); 189 190 if(isset($_POST['aFhfc_body_code'])) 191 if(empty($_POST['aFhfc_body_code'])) 192 delete_post_meta($post_id,'aFhfc_body_code'); 157 193 else 158 update_post_meta( $post_id, 'aFhfc_footer_code', $_POST['aFhfc_footer_code'] ); 159 $aFHFCFRChk = (isset($_POST['aFhfc_footer_replace']) && $_POST['aFhfc_footer_replace'])? '1' : ''; 194 update_post_meta($post_id,'aFhfc_body_code',$_POST['aFhfc_body_code']); 195 $aFHFCHRChk = (isset($_POST['aFhfc_body_replace']) && $_POST['aFhfc_body_replace'])?'1':''; 196 if(empty($_POST['aFhfc_body_replace'])) 197 delete_post_meta($post_id,'aFhfc_body_replace'); 198 else 199 update_post_meta($post_id,'aFhfc_body_replace',$aFHFCHRChk); 200 201 if( isset($_POST['aFhfc_footer_code'])) 202 if( empty($_POST['aFhfc_footer_code'])) 203 delete_post_meta($post_id,'aFhfc_footer_code'); 204 else 205 update_post_meta($post_id,'aFhfc_footer_code',$_POST['aFhfc_footer_code']); 206 $aFHFCFRChk = (isset($_POST['aFhfc_footer_replace']) && $_POST['aFhfc_footer_replace'])?'1':''; 160 207 if(empty($_POST['aFhfc_footer_replace'])) 161 208 delete_post_meta($post_id,'aFhfc_footer_replace'); -
addfunc-head-footer-code/trunk/options.php
r1729674 r1948199 1 1 <div class="wrap"> 2 <?php screen_icon(); ?>3 2 <h2>Head & Footer Code</h2> 4 3 <div id="poststuff"> … … 14 13 <label class="aFtext" for="aFhfc_head_code_priority"><strong>Head code Priority:</strong></label> <input id="aFhfc_head_code_priority" class="small-text" type="number" min="0" step="1" name="aFhfc_head_code_priority" value="<?php echo get_option('aFhfc_head_code_priority'); ?>" /> 15 14 <span class="description">Higher number = ealier output | Lower number = later output | Default = 10</span> 15 <p> </p> 16 </div> 17 <div> 18 <label for="aFhfc_site_wide_body_code"> 19 <h3 class="title">Site-wide Body Start Code <span class="dashicons dashicons-info" title="Inserts immediately after the opening body tag."></span></h3> 20 <p><textarea name="aFhfc_site_wide_body_code" rows="10" cols="50" id="aFhfc_site_wide_body_code" class="large-text code"><?php echo get_option('aFhfc_site_wide_body_code'); ?></textarea></p> 21 </label> 16 22 <p> </p> 17 23 </div> -
addfunc-head-footer-code/trunk/readme.txt
r1729674 r1948199 4 4 Contributors: AddFunc,joerhoney 5 5 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=7AF7P3TFKQ2C2 6 Tags: head code, footer code, add to head, per page, script, tracking code, Google Analytics, javascript, meta tags, insert code, wp_head, wp_footer6 Tags: head code, footer code, add to head, per page, tracking code, Google Analytics, javascript, meta tags, wp_head, wp_footer, body tag code, opening body tag 7 7 Requires at least: 3.0.1 8 Tested up to: 4. 89 Stable tag: 1.58 Tested up to: 4.9 9 Stable tag: 2 10 10 License: GPLv2 or later 11 11 License URI: http://www.gnu.org/licenses/gpl-2.0.html 12 12 13 Easily add code to your head and/or footer, site-wide and/or on any individual page/post.13 Easily add code to your head, footer and/or immediately after the opening body tag, site-wide and/or on any individual page/post. 14 14 15 15 == Description == … … 37 37 For the site wide code yes, as long as the theme is set up properly with the `wp_head()` and `wp_footer()` functions. For individual custom content type "entries" (as we'll call them) it will work as long as the custom content type (or custom post type more precisely) is set up in the standard way, so that WordPress will recognize that it needs to add all the usual meta boxes to it. Basically, it will work in a standard setup. 38 38 39 = Where does the head code output? =39 = Where does the Head Code output? = 40 40 41 41 Wherever `wp_head()` is located in your theme. 42 42 43 = Where does the footer code output? = 43 = Where does the Body Start Code output? = 44 45 Immediately after the opening `body` tag. Note: other plugins can be made to do the same thing and one of them has to insert before the other, so other plugins could theoretically insert code before AddFunc Head & Footer Code's Body Start Code. 46 47 = Where does the Footer Code output? = 44 48 45 49 Wherever `wp_footer()` is located in your theme. … … 47 51 = Will AddFunc Head & Footer Code work if there is no `wp_head()` or `wp_footer()` in my theme? = 48 52 49 Wherever one of those functions is missing, your code will not be output there. But omitting one of them does not stop the other one from working. AddFunc Head & Footer Code will also save your code regardless. It just can't output your code without the presence of those functions in the theme. 50 51 = Does it really require WordPress 3.0.1 or later? = 52 53 I have not tested it on earlier versions, but I believe `wp_head()` and `wp_footer()` have been a part of WordPress since the very beginning, so it should work on any version. Feel free to try it out and let us know if it works! :) 53 Wherever one of those functions is missing, your code will not be output there. But omitting one of them does not stop the other ones from working. AddFunc Head & Footer Code will also save your code regardless. It just can't output your code without the presence of those functions in the theme. 54 54 55 55 = Does AddFunc have a website? = … … 59 59 == Screenshots == 60 60 61 1. Simply paste your code into one of these t wofields and it will be included on every page of your website.61 1. Simply paste your code into one of these three fields and it will be included on every page of your website. 62 62 63 63 2. Add your code to these fields respectively and it will output specifically to this page, post or custom post type. Optionally replace or remove the site-wide code on any individual post or page. … … 65 65 == Changelog == 66 66 67 = 2 = 68 19 Sep 2018 69 70 * Adds... drumroll please... Body Start Code! 71 - Insert code immediately after the opening `body` tag! 72 - Fields for individual page/post code as well as site-wide code. 73 - Optionally replace site-wide code with individual page/post code. 74 - All behaves the same as head code and footer code, except for priority (no priority setting). 75 - Note: There is no standard for opening `body` tag code in WordPress yet (contact me if I'm wrong). If there ever is, AddFunc Head & Footer Code may change so as to conform to the standard. We don't think this will effect performance in anyway, but if it does, we will let you know through this change log. If necessary, we may even leave this feature in place along with the new standardized method. 76 77 = 1.5.1 = 78 17 Sep 2018 79 80 * Removes individual post output on various pages: 81 - archive 82 - author 83 - category 84 - tag 85 - home 86 - search 87 - 404 88 67 89 = 1.5 = 68 13 -Sep-201790 13 Sep 2017 69 91 70 92 * Adds ability to set the output priority of the head code. Thanks to John Irvine at [RD Technology Solutions](http://rdtechsol.com/) for the suggestion. … … 73 95 74 96 = 1.4 = 75 3 -Apr-201797 3 Apr 2017 76 98 77 99 * Adds option for individual post code to replace the site-wide code: 78 - Head and footer managed independently of each other 79 - Individual post code appends to site-wide by default 80 - Check the *Replace Site-wide Head/Footer Code* checkbox to replace or remove the Site-wide code for the respective area 100 - Head and footer managed independently of each other. 101 - Individual post code appends to site-wide by default. 102 - Check the *Replace Site-wide Head/Footer Code* checkbox to replace or remove the Site-wide code for the respective area. 81 103 * Fixes post meta fields: 82 - No longer saves post meta fields when not needed 83 - Deletes post meta fields if empty when saved/updated 104 - No longer saves post meta fields when not needed. 105 - Deletes post meta fields if empty when saved/updated. 84 106 85 107 = 1.3 = 86 23 -Jun-2015108 23 Jun 2015 87 109 88 110 * Corrects the generated path to options.php, so that the settings page can be found even on installs where the plugins directory is not at the standard /wp-content/plugins location. 89 111 90 112 = 1.2 = 91 19 -Jun-2015113 19 Jun 2015 92 114 93 115 * Discovered addfunc-head-footer-code.php was saved with text encoding Western (Mac OS Roman). ~>:( Changed to Unicode (UTF-8). … … 96 118 97 119 = 1.1 = 98 28 -Nov-2014120 28 Nov 2014 99 121 100 122 * Fixes meta box nounce. 101 123 * Changes all references to Average (including but not limited to "avrg", "average", etc.) to relate to AddFunc (changing project name). 102 124 * Changes a few other function and variable names for namespacing purposes. 103 * Submitted to WordPressunder the name AddFunc.125 * Submitted to the WordPress Plugin Repository under the name AddFunc. 104 126 105 127 = 1.0 = 106 7 -Aug-2014128 7 Aug 2014 107 129 108 130 * Includes readme.txt. 109 * Submitted to WordPress.131 * Submitted to the WordPress Plugin Repository. 110 132 111 133 = 0.4.1 = 112 6 -Aug-2014134 6 Aug 2014 113 135 114 136 * Code cleaned up (mostly comments removed). … … 116 138 117 139 = 0.4 = 118 8 -Jul-2014140 8 Jul 2014 119 141 120 142 * Bug fix: replaced "my-meta-box-id" with "avrghdftrcdMetaBox" (duh). 121 143 122 144 = 0.3 = 123 27 -Oct-2013145 27 Oct 2013 124 146 125 147 * Hid Head & Footer Code meta box from non-admin users. 126 148 127 149 = 0.2 = 128 15 -Oct-2013150 15 Oct 2013 129 151 130 152 * Adds a Head & Footer Code settings page for site-wide code (for admins only). 131 153 132 154 = 0.1 = 133 14 -Aug-2013155 14 Aug 2013 134 156 135 157 * Adds Head & Footer Code meta box to all pages, posts and cusom post types.
Note: See TracChangeset
for help on using the changeset viewer.