Plugin Directory

Changeset 1948199


Ignore:
Timestamp:
09/27/2018 06:24:16 PM (8 years ago)
Author:
joerhoney
Message:

Release of version 2!

Location:
addfunc-head-footer-code
Files:
5 added
5 edited

Legend:

Unmodified
Added
Removed
  • addfunc-head-footer-code/trunk/addfunc-head-footer-code.php

    r1729674 r1948199  
    44    Plugin URI:
    55    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.5
     6    Version: 2
    77    Author: AddFunc
    88    Author URI: http://profiles.wordpress.org/addfunc
     
    2525*/
    2626
    27 if(!class_exists('aFhfc_class')) :
    28 define('AFHDFTRCD_ID', 'aFhfc');
    29 define('AFHDFTRCD_NICK', 'Head & Footer Code');
    30   class aFhfc_class
     27if(!class_exists('aFHFCClass')) :
     28  define('AFHDFTRCD_ID', 'aFhfc');
     29  define('AFHDFTRCD_NICK', 'Head & Footer Code');
     30  class aFHFCClass
    3131  {
    3232    public static function file_path($file)
     
    3838      register_setting(AFHDFTRCD_ID.'_options', 'aFhfc_site_wide_head_code');
    3939      register_setting(AFHDFTRCD_ID.'_options', 'aFhfc_head_code_priority');
     40      register_setting(AFHDFTRCD_ID.'_options', 'aFhfc_site_wide_body_code');
    4041      register_setting(AFHDFTRCD_ID.'_options', 'aFhfc_site_wide_footer_code');
    4142      register_setting(AFHDFTRCD_ID.'_options', 'aFhfc_footer_code_priority');
     
    4344    public static function menu()
    4445    {
    45       add_options_page(AFHDFTRCD_NICK.' Plugin Options', AFHDFTRCD_NICK, 'manage_options', AFHDFTRCD_ID.'_options', array('aFhfc_class', 'options_page'));
     46      add_options_page(AFHDFTRCD_NICK.' Plugin Options', AFHDFTRCD_NICK, 'manage_options', AFHDFTRCD_ID.'_options', array('aFHFCClass', 'options_page'));
    4647    }
    4748    public static function options_page()
     
    5758    {
    5859      $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);
    6061      $head_replace = get_post_meta(get_the_ID(),'aFhfc_head_replace',true);
    6162      if(!empty($head_replace)){
     
    6566      }
    6667    }
     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    }
    6779    public static function output_footer_code()
    6880    {
    6981      $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);
    7183      $footer_replace = get_post_meta(get_the_ID(),'aFhfc_footer_replace',true);
    7284      if(!empty($footer_replace)){
     
    7991  if (is_admin())
    8092  {
    81     add_action('admin_init', array('aFhfc_class','register'));
    82     add_action('admin_menu', array('aFhfc_class','menu'));
     93    add_action('admin_init', array('aFHFCClass','register'));
     94    add_action('admin_menu', array('aFHFCClass','menu'));
    8395  }
    8496  $head_code_prior = get_option('aFhfc_head_code_priority');
    8597  if(!empty($head_code_prior)){
    86     add_action('wp_head', array('aFhfc_class','output_head_code'),$head_code_prior);
     98    add_action('wp_head', array('aFHFCClass','output_head_code'),$head_code_prior);
    8799  }
    88100  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');
    91117  $footer_code_prior = get_option('aFhfc_footer_code_priority');
    92118  if(!empty($footer_code_prior)){
    93     add_action('wp_footer', array('aFhfc_class','output_footer_code'),$footer_code_prior);
     119    add_action('wp_footer', array('aFHFCClass','output_footer_code'),$footer_code_prior);
    94120  }
    95121  else {
    96     add_action('wp_footer', array('aFhfc_class','output_footer_code'));
     122    add_action('wp_footer', array('aFHFCClass','output_footer_code'));
    97123  }
    98124endif;
     
    118144  $head_text = isset($values['aFhfc_head_code']) ? esc_attr($values['aFhfc_head_code'][0]) : '';
    119145  $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]) : '';
    120148  $footer_text = isset($values['aFhfc_footer_code']) ? esc_attr($values['aFhfc_footer_code'][0]) : '';
    121149  $footer_replace = isset($values['aFhfc_footer_replace']) ? esc_attr($values['aFhfc_footer_replace'][0]) : '';
     
    127155    <input id="aFhfc_head_replace" type="checkbox" name="aFhfc_head_replace" value="1" <?php checked($head_replace,'1'); ?> />
    128156    <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>
    129163  </p>
    130164  <p>
     
    139173function aFhfc_save($post_id)
    140174{
    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');
    147182    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':'';
    150185  if(empty($_POST['aFhfc_head_replace']))
    151186    delete_post_meta($post_id,'aFhfc_head_replace');
    152187  else
    153188    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');
    157193    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':'';
    160207  if(empty($_POST['aFhfc_footer_replace']))
    161208    delete_post_meta($post_id,'aFhfc_footer_replace');
  • addfunc-head-footer-code/trunk/options.php

    r1729674 r1948199  
    11<div class="wrap">
    2   <?php screen_icon(); ?>
    32  <h2>Head & Footer Code</h2>
    43  <div id="poststuff">
     
    1413      <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'); ?>" />
    1514      <span class="description">Higher number = ealier output | Lower number = later output | Default = 10</span>
     15      <p>&nbsp;</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>
    1622      <p>&nbsp;</p>
    1723    </div>
  • addfunc-head-footer-code/trunk/readme.txt

    r1729674 r1948199  
    44Contributors: AddFunc,joerhoney
    55Donate 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_footer
     6Tags: 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
    77Requires at least: 3.0.1
    8 Tested up to: 4.8
    9 Stable tag: 1.5
     8Tested up to: 4.9
     9Stable tag: 2
    1010License: GPLv2 or later
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1212
    13 Easily add code to your head and/or footer, site-wide and/or on any individual page/post.
     13Easily add code to your head, footer and/or immediately after the opening body tag, site-wide and/or on any individual page/post.
    1414
    1515== Description ==
     
    3737For 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.
    3838
    39 = Where does the head code output? =
     39= Where does the Head Code output? =
    4040
    4141Wherever `wp_head()` is located in your theme.
    4242
    43 = Where does the footer code output? =
     43= Where does the Body Start Code output? =
     44
     45Immediately 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? =
    4448
    4549Wherever `wp_footer()` is located in your theme.
     
    4751= Will AddFunc Head & Footer Code work if there is no `wp_head()` or `wp_footer()` in my theme? =
    4852
    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! :)
     53Wherever 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.
    5454
    5555= Does AddFunc have a website? =
     
    5959== Screenshots ==
    6060
    61 1. Simply paste your code into one of these two fields and it will be included on every page of your website.
     611. Simply paste your code into one of these three fields and it will be included on every page of your website.
    6262
    63632. 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.
     
    6565== Changelog ==
    6666
     67= 2 =
     6819 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 =
     7817 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
    6789= 1.5 =
    68 13-Sep-2017
     9013 Sep 2017
    6991
    7092*   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.
     
    7395
    7496= 1.4 =
    75 3-Apr-2017
     973 Apr 2017
    7698
    7799*   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.
    81103*   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.
    84106
    85107= 1.3 =
    86 23-Jun-2015
     10823 Jun 2015
    87109
    88110*   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.
    89111
    90112= 1.2 =
    91 19-Jun-2015
     11319 Jun 2015
    92114
    93115*   Discovered addfunc-head-footer-code.php was saved with text encoding Western (Mac OS Roman). ~>:( Changed to Unicode (UTF-8).
     
    96118
    97119= 1.1 =
    98 28-Nov-2014
     12028 Nov 2014
    99121
    100122*   Fixes meta box nounce.
    101123*   Changes all references to Average (including but not limited to "avrg", "average", etc.) to relate to AddFunc (changing project name).
    102124*   Changes a few other function and variable names for namespacing purposes.
    103 *   Submitted to WordPress under the name AddFunc.
     125*   Submitted to the WordPress Plugin Repository under the name AddFunc.
    104126
    105127= 1.0 =
    106 7-Aug-2014
     1287 Aug 2014
    107129
    108130*   Includes readme.txt.
    109 *   Submitted to WordPress.
     131*   Submitted to the WordPress Plugin Repository.
    110132
    111133= 0.4.1 =
    112 6-Aug-2014
     1346 Aug 2014
    113135
    114136*   Code cleaned up (mostly comments removed).
     
    116138
    117139= 0.4 =
    118 8-Jul-2014
     1408 Jul 2014
    119141
    120142*   Bug fix: replaced "my-meta-box-id" with "avrghdftrcdMetaBox" (duh).
    121143
    122144= 0.3 =
    123 27-Oct-2013
     14527 Oct 2013
    124146
    125147*   Hid Head & Footer Code meta box from non-admin users.
    126148
    127149= 0.2 =
    128 15-Oct-2013
     15015 Oct 2013
    129151
    130152*   Adds a Head & Footer Code settings page for site-wide code (for admins only).
    131153
    132154= 0.1 =
    133 14-Aug-2013
     15514 Aug 2013
    134156
    135157*   Adds Head & Footer Code meta box to all pages, posts and cusom post types.
Note: See TracChangeset for help on using the changeset viewer.