Per page add to head - Version 1.4

Version Description

  • Added shortcode support. You can now place shortcodes in both the posts/pages, and the "every page" area
  • Fixed an error generating output during installation, and corrected a misplaced linebreak outside the PHP code
  • Fixed an error that could cause content for a page being inserted into an archive page for a category or tag if the id's matched up
Download this release

Release Info

Developer Erikvona
Plugin Icon wp plugin Per page add to head
Version 1.4
Comparing to
See all releases

Code changes from version 1.3 to 1.4

Files changed (3) hide show
  1. installdeinstall.php +0 -6
  2. perpagehead.php +25 -32
  3. readme.txt +7 -2
installdeinstall.php CHANGED
@@ -1,12 +1,6 @@
1
  <?php
2
  defined( 'ABSPATH' ) or die( 'Direct access not allowed' );
3
  function PerPageATHInstallStep2(){
4
- if(!file_exists($htmlfile)){
5
- if($htmlcreatehandle = fopen($htmlfile, 'x')){
6
- fwrite($htmlcreatehandle, "");
7
- fclose($htmlcreatehandle);
8
- }
9
- }
10
  global $wp_roles;
11
  $roleobject = $wp_roles->get_role('administrator');
12
  $roleobject->add_cap('add-to-head');
1
  <?php
2
  defined( 'ABSPATH' ) or die( 'Direct access not allowed' );
3
  function PerPageATHInstallStep2(){
 
 
 
 
 
 
4
  global $wp_roles;
5
  $roleobject = $wp_roles->get_role('administrator');
6
  $roleobject->add_cap('add-to-head');
perpagehead.php CHANGED
@@ -1,28 +1,21 @@
1
  <?php
2
-
3
  /*
4
  Plugin Name: Per page head
5
  Plugin URI: http://www.evona.nl/plugins/per-page-head
6
- Description: Allows you to add content into the &lt;head&gt; section for a specific page, like custom JS or custom HTML, using post meta. Also allows you to add content for every page, under Settings -> Per Page Add To Head
7
- Version: 1.3
8
  Author: Erik von Asmuth
9
- Author URI: http://evona.nl/about-me/
10
  License: GPLv2
11
- Text Domain: per-page-ath
12
  */
13
- defined( 'ABSPATH' ) or die( 'Direct access not allowed' );
14
- load_plugin_textdomain('per-page-ath', false, basename( dirname( __FILE__ ) ) . '/languages' );
15
 
16
  //Add the meta box
17
  function perpageathaddbox() {
18
- if(current_user_can('add-to-head')||current_user_can('manage_options')){
19
- $addtohead = __('Add to head', 'per-page-ath');
20
- $screens = get_option('ppath_types_allowed', array('post', 'page'));
21
- foreach ( $screens as $screen ) {
22
- add_meta_box( 'per-page-ath', $addtohead, 'athcallback', $screen, 'normal',
23
- 'default', null );
24
- }
25
- }
26
  }
27
 
28
  add_action( 'add_meta_boxes', 'perpageathaddbox' );
@@ -41,7 +34,7 @@ function athcallback($post){
41
  echo '<label for="per-page-ath">';
42
  _e( "Put your head html here", 'per-page-ath' );
43
  echo '</label><br/> ';
44
- echo '<textarea id="perpageathtextbox" style="width:100%; min-height:120px; white-space: pre-wrap;" name="per-page-ath">'.str_replace('%BREAK%', "\n",stripslashes_deep(esc_attr($value))).'</textarea>';
45
  }
46
 
47
  /**
@@ -85,8 +78,8 @@ function perpageath_save_postdata( $post_id ) {
85
  /* OK, its safe for us to save the data now. */
86
 
87
  // Sanitize user input.
88
- //esc_sql is doing funky things with line breaks, so taking them out and putting them back in
89
- $mydata = str_replace('%BREAK%', "\r\n", esc_sql(str_replace(array("\r\n", "\r", "\n"), '%BREAK%',$_POST['per-page-ath']) ));
90
  // Update the meta field in the database.
91
  update_post_meta( $post_id, 'per-page-ath-content', $mydata );
92
  }
@@ -94,35 +87,35 @@ add_action( 'save_post', 'perpageath_save_postdata' );
94
  //Now that's done. Let's add the meta field to the head
95
 
96
  function perpageath_display(){
97
- $pageid = get_queried_object_id();
 
 
 
 
 
 
98
  $html = get_option("ppath_head_every_page", "");
99
- if(!empty($html)){
100
- echo $html;
101
- }else{
102
  $htmlfile = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig'.DIRECTORY_SEPARATOR.'everyheadpage.html';
103
  if(file_exists($htmlfile)&& filesize($htmlfile) > 0){
104
  if($htmlhandle = fopen($htmlfile, 'r')){
105
  $html = fread($htmlhandle, filesize($htmlfile));
106
  fclose($htmlhandle);
107
- echo $html;
108
  }else{
109
- echo "<!-- ".printf( __( 'Error reading config file %s! Is this file readable by the webserver?', 'per-page-ath' ), $htmlfile )." -->";
110
  }
111
  }
 
 
112
  }
113
- $addtoheadcontent = get_post_meta( $pageid, 'per-page-ath-content', true );
114
- if(!empty($addtoheadcontent)){
115
- echo str_replace('%BREAK%', "\n", stripslashes_deep($addtoheadcontent));
116
- }
117
-
118
  }
119
- add_action('wp_head', 'perpageath_display', 1000);
120
 
121
  //Create a menu
122
  //Load in the option page
123
  function EvonaCreateATHMenu() {
124
- $menuname = __('Per Page Add To Head', 'per-page-ath');
125
- add_options_page( $menuname, $menuname, 'manage_options', 'perpageath-every-page', 'PerPageATHSettings' );
126
  }
127
 
128
  function PerPageATHSettings(){
1
  <?php
 
2
  /*
3
  Plugin Name: Per page head
4
  Plugin URI: http://www.evona.nl/plugins/per-page-head
5
+ Description: Allows you to add content into the <head> section for a specific page, like custom JS or custom HTML
6
+ Version: 1.4
7
  Author: Erik von Asmuth
8
+ Author URI: http://evona.nl/over-mij/
9
  License: GPLv2
 
10
  */
 
 
11
 
12
  //Add the meta box
13
  function perpageathaddbox() {
14
+ $screens = array( 'post', 'page' );
15
+ foreach ( $screens as $screen ) {
16
+ add_meta_box( 'per-page-ath', 'Add to head', 'athcallback', $screen, 'normal',
17
+ 'default', null );
18
+ }
 
 
 
19
  }
20
 
21
  add_action( 'add_meta_boxes', 'perpageathaddbox' );
34
  echo '<label for="per-page-ath">';
35
  _e( "Put your head html here", 'per-page-ath' );
36
  echo '</label><br/> ';
37
+ echo '<textarea id="perpageathtextbox" style="width:100%;" name="per-page-ath">'.esc_attr(stripslashes_deep( $value )).'</textarea>';
38
  }
39
 
40
  /**
78
  /* OK, its safe for us to save the data now. */
79
 
80
  // Sanitize user input.
81
+ $mydata = esc_sql( str_replace(array("\r\n", "\r", "\n"), '',$_POST['per-page-ath']) );
82
+
83
  // Update the meta field in the database.
84
  update_post_meta( $post_id, 'per-page-ath-content', $mydata );
85
  }
87
  //Now that's done. Let's add the meta field to the head
88
 
89
  function perpageath_display(){
90
+ if(!is_archive()){
91
+ $pageid = get_queried_object_id();
92
+ $addtoheadcontent = get_post_meta( $pageid, 'per-page-ath-content', true );
93
+ if(!empty($addtoheadcontent)){
94
+ echo do_shortcode(stripslashes_deep($addtoheadcontent));
95
+ }
96
+ }
97
  $html = get_option("ppath_head_every_page", "");
98
+ if(empty($html)){
 
 
99
  $htmlfile = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig'.DIRECTORY_SEPARATOR.'everyheadpage.html';
100
  if(file_exists($htmlfile)&& filesize($htmlfile) > 0){
101
  if($htmlhandle = fopen($htmlfile, 'r')){
102
  $html = fread($htmlhandle, filesize($htmlfile));
103
  fclose($htmlhandle);
104
+ echo do_shortcode($html);
105
  }else{
106
+ echo "<!-- Error reading ".$htmlfile."! Is the file readable? -->";
107
  }
108
  }
109
+ }else{
110
+ echo do_shortcode($html);
111
  }
 
 
 
 
 
112
  }
113
+ add_action('wp_head', 'perpageath_display');
114
 
115
  //Create a menu
116
  //Load in the option page
117
  function EvonaCreateATHMenu() {
118
+ add_options_page( 'Add &lt;head&gt; to every page', 'Add &lt;head&gt; to every page', 'manage_options', 'perpageath-every-page', 'PerPageATHSettings' );
 
119
  }
120
 
121
  function PerPageATHSettings(){
readme.txt CHANGED
@@ -5,8 +5,8 @@ Tags: head, css, favicon
5
  Author URI: http://evona.nl/over-mij
6
  Author: Erik von Asmuth (Erikvona)
7
  Requires at least: 3.5
8
- Tested up to: 4.4.2
9
- Stable tag: 1.3
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
@@ -35,6 +35,11 @@ Installation is plain and simple
35
  1. You can also add head to all posts! Just use settings -> per page add to head
36
 
37
  == Changelog ==
 
 
 
 
 
38
  = 1.3 =
39
  - Now stores HTML for every page as a WordPress option in the database, instead of as a separate file (fixing problems with WP multisite, but setting a maximum size to it equal to the maximum that WordPress can store inside an option)
40
  - Now correctly puts line returns in the database, instead of escaping them with %BREAK% (Note: %BREAK% is still being converted into \r\n)
5
  Author URI: http://evona.nl/over-mij
6
  Author: Erik von Asmuth (Erikvona)
7
  Requires at least: 3.5
8
+ Tested up to: 4.7
9
+ Stable tag: 1.4
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
35
  1. You can also add head to all posts! Just use settings -> per page add to head
36
 
37
  == Changelog ==
38
+ = 1.4 =
39
+ - Added shortcode support. You can now place shortcodes in both the posts/pages, and the "every page" area
40
+ - Fixed an error generating output during installation, and corrected a misplaced linebreak outside the PHP code
41
+ - Fixed an error that could cause content for a page being inserted into an archive page for a category or tag if the id's matched up
42
+
43
  = 1.3 =
44
  - Now stores HTML for every page as a WordPress option in the database, instead of as a separate file (fixing problems with WP multisite, but setting a maximum size to it equal to the maximum that WordPress can store inside an option)
45
  - Now correctly puts line returns in the database, instead of escaping them with %BREAK% (Note: %BREAK% is still being converted into \r\n)