Per page add to head - Version 1.3

Version Description

  • 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)
  • Now correctly puts line returns in the database, instead of escaping them with %BREAK% (Note: %BREAK% is still being converted into \r\n) NOTE: If you want to use the changed way of storing items, you need to update the fields you want to store that way (change something in them, then change it back)
  • Blocks direct access to plugin files (unnecessary but asked for)
  • Probably fixed problems with persons being redirected to the login page when making changes (can't verify because can't replicate)
Download this release

Release Info

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

Code changes from version 1.2.1 to 1.3

Files changed (4) hide show
  1. installdeinstall.php +2 -5
  2. perpagehead.php +19 -13
  3. readme.txt +11 -4
  4. settings.php +25 -28
installdeinstall.php CHANGED
@@ -1,10 +1,6 @@
1
  <?php
 
2
  function PerPageATHInstallStep2(){
3
- $configdir = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig';
4
- $htmlfile = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig'.DIRECTORY_SEPARATOR.'everyheadpage.html';
5
- if(!is_dir($configdir)){
6
- mkdir($configdir, 0775);
7
- }
8
  if(!file_exists($htmlfile)){
9
  if($htmlcreatehandle = fopen($htmlfile, 'x')){
10
  fwrite($htmlcreatehandle, "");
@@ -26,6 +22,7 @@ function PerPageATHDeinstallStep2(){
26
  }
27
  delete_option('ppath_roles_allowed');
28
  delete_option('ppath_types_allowed');
 
29
  }
30
  function PerpageathConfigMgrDeleteConfigfile($filename){
31
  $configdir = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig';
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, "");
22
  }
23
  delete_option('ppath_roles_allowed');
24
  delete_option('ppath_types_allowed');
25
+ delete_option('ppath_head_every_page');
26
  }
27
  function PerpageathConfigMgrDeleteConfigfile($filename){
28
  $configdir = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig';
perpagehead.php CHANGED
@@ -4,12 +4,13 @@
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.2.1
8
  Author: Erik von Asmuth
9
  Author URI: http://evona.nl/about-me/
10
  License: GPLv2
11
  Text Domain: per-page-ath
12
  */
 
13
  load_plugin_textdomain('per-page-ath', false, basename( dirname( __FILE__ ) ) . '/languages' );
14
 
15
  //Add the meta box
@@ -84,8 +85,8 @@ function perpageath_save_postdata( $post_id ) {
84
  /* OK, its safe for us to save the data now. */
85
 
86
  // Sanitize user input.
87
- $mydata = esc_sql( str_replace(array("\r\n", "\r", "\n"), '%BREAK%',$_POST['per-page-ath']) );
88
-
89
  // Update the meta field in the database.
90
  update_post_meta( $post_id, 'per-page-ath-content', $mydata );
91
  }
@@ -93,16 +94,21 @@ add_action( 'save_post', 'perpageath_save_postdata' );
93
  //Now that's done. Let's add the meta field to the head
94
 
95
  function perpageath_display(){
96
- $pageid = get_queried_object_id();
97
- $htmlfile = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig'.DIRECTORY_SEPARATOR.'everyheadpage.html';
98
- if(file_exists($htmlfile)&& filesize($htmlfile) > 0){
99
- if($htmlhandle = fopen($htmlfile, 'r')){
100
- $html = fread($htmlhandle, filesize($htmlfile));
101
- fclose($htmlhandle);
102
- echo $html;
103
- }else{
104
- echo "<!-- ".printf( __( 'Error reading config file %s! Is this file readable by the webserver?', 'per-page-ath' ), $htmlfile )." -->";
105
- }
 
 
 
 
 
106
  }
107
  $addtoheadcontent = get_post_meta( $pageid, 'per-page-ath-content', true );
108
  if(!empty($addtoheadcontent)){
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
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
  //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)){
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.2.1
9
- Stable tag: 1.2.1
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
@@ -15,11 +15,11 @@ This plugin adds content between the head tags for specific WordPress posts, or
15
 
16
  == Description ==
17
 
18
- Ever got really annoyed how much effort it took to add style tags for just one page into the head section of a page, using WordPress? Well, I did. So I made this plugin for exactly that purpose. It just adds whatever you give it to the head tag. With a size of 8KB, and no use of any client side code, efficiency is taken care of. You can also use it to add meta tags, for SEO, auto-refresh, Google Analytics, or anything else you want to put in there.
19
 
20
  Of course, you can also use it to add your own stylesheets and JavaScript files. Anything that normally goes in the head section is fine.
21
 
22
- Add to head also features an option under settings to add some text inside head on every page. Ideal for favicons, Modern UI start screen icons, or style sheets if youre too lazy to make a child theme.
23
 
24
  Just install the plugin, activate it, make sure it is showing in your post editor by clicking screen options and checking add to head while editing a page, and add stuff!
25
 
@@ -35,6 +35,13 @@ 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.2.1 =
39
  - Fixed a critical installation error introduced in version 1.2
40
 
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
 
15
 
16
  == Description ==
17
 
18
+ Ever got really annoyed how much effort it took to add style tags for just one page into the head section of a page, using WordPress? Well, I did. So I made this plugin for exactly that purpose. It just adds whatever you give it to the head tag. With a small size and no use of any client side code, efficiency is taken care of. You can also use it to add meta tags, for SEO, auto-refresh, Google Analytics, or anything else you want to put in there.
19
 
20
  Of course, you can also use it to add your own stylesheets and JavaScript files. Anything that normally goes in the head section is fine.
21
 
22
+ Add to head also features an option under settings to add some text inside head on every page. Ideal for favicons, Modern UI start screen icons, or style sheets if you're too lazy to make a child theme.
23
 
24
  Just install the plugin, activate it, make sure it is showing in your post editor by clicking screen options and checking add to head while editing a page, and add stuff!
25
 
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)
41
+ **NOTE:** If you want to use the changed way of storing items, you need to update the fields you want to store that way (change something in them, then change it back)
42
+ - Blocks direct access to plugin files (unnecessary but asked for)
43
+ - Probably fixed problems with persons being redirected to the login page when making changes (can't verify because can't replicate)
44
+
45
  = 1.2.1 =
46
  - Fixed a critical installation error introduced in version 1.2
47
 
settings.php CHANGED
@@ -1,13 +1,6 @@
1
  <?php
 
2
  function perpageath_config(){
3
- $currenturl = 'http';
4
- if (isset($_SERVER['HTTPS']) && $_SERVER["HTTPS"] == "on") {$currenturl .= "s";}
5
- $currenturl .= "://";
6
- if ($_SERVER["SERVER_PORT"] != "80") {
7
- $currenturl .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
8
- } else {
9
- $currenturl .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
10
- }
11
  $htmlfile = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig'.DIRECTORY_SEPARATOR.'everyheadpage.html';
12
  ?>
13
 
@@ -16,33 +9,37 @@ function perpageath_config(){
16
  <h3><?php _e('Everything you put in here will be inserted into the &lt;head&gt; tag on every page. Ideal for favicons!', 'per-page-ath'); ?></h3>
17
 
18
  <?php
19
- if(!file_exists($htmlfile)){
20
- if($htmlcreatehandle = fopen($htmlfile, 'x')){
21
- fwrite($htmlcreatehandle, "");
22
- fclose($htmlcreatehandle);
 
 
 
 
 
 
 
23
  }else{
24
- printf(__("Error creating %s! Is the underlying folder writable?", 'per-page-ath'), $htmlfile);
25
  }
26
  }
27
- if($htmlhandle = fopen($htmlfile, 'r')){
28
- if(filesize($htmlfile) > 0){
29
- $html = fread($htmlhandle, filesize($htmlfile));
30
- }else{
31
- $html = "";
32
- }
33
- fclose($htmlhandle);
34
-
35
- }else{printf(__("Error reading HTML from file %s. Is this file readable?", 'per-page-ath'), $htmlfile);}
36
  if(isset($_POST['html']) && current_user_can('add-to-head')){
37
  $newhtml = stripslashes_deep($_POST['html']);
38
  if($newhtml == $html){
39
  _e('HTML not updated', 'per-page-ath');
40
- }elseif($htmlwritehandle = fopen($htmlfile, 'w')){
 
41
  $html = $newhtml;
42
- fwrite($htmlwritehandle, $html);
43
- fclose($htmlwritehandle);
44
- printf(__("Succesfully edited %s!", 'per-page-ath'), $htmlfile);
45
- }else{printf(__("Error writing HTML to %s. Is this file writable?", 'per-page-ath'), $htmlfile);}
 
 
 
 
 
46
  }
47
  global $wp_roles;
48
  $rolesallowednow = array();
@@ -107,7 +104,7 @@ function perpageath_config(){
107
  $typesupdated = false;
108
  }
109
  }
110
- ?><form method="post" action="<?php echo $currenturl; ?>"><?php
111
  if(current_user_can('add-to-head')|| current_user_can('manage_options')):
112
  if(isset($html)){
113
  ?><textarea style="white-space:pre; width:80%; min-width:600px; height:300px;" name="html"><?php echo $html; ?></textarea><?php
1
  <?php
2
+ defined( 'ABSPATH' ) or die( 'Direct access not allowed' );
3
  function perpageath_config(){
 
 
 
 
 
 
 
 
4
  $htmlfile = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig'.DIRECTORY_SEPARATOR.'everyheadpage.html';
5
  ?>
6
 
9
  <h3><?php _e('Everything you put in here will be inserted into the &lt;head&gt; tag on every page. Ideal for favicons!', 'per-page-ath'); ?></h3>
10
 
11
  <?php
12
+ $html = get_option('ppath_head_every_page', "");
13
+ if(empty($html)){
14
+ if(file_exists($htmlfile)){
15
+ if($htmlhandle = fopen($htmlfile, 'r')){
16
+ if(filesize($htmlfile) > 0){
17
+ $html = fread($htmlhandle, filesize($htmlfile));
18
+ }else{
19
+ $html = "";
20
+ }
21
+ fclose($htmlhandle);
22
+ }else{printf(__("Error reading HTML from file %s. Is this file readable?", 'per-page-ath'), $htmlfile);}
23
  }else{
24
+ $html = get_option('ppath_head_every_page', "");
25
  }
26
  }
 
 
 
 
 
 
 
 
 
27
  if(isset($_POST['html']) && current_user_can('add-to-head')){
28
  $newhtml = stripslashes_deep($_POST['html']);
29
  if($newhtml == $html){
30
  _e('HTML not updated', 'per-page-ath');
31
+ }else{
32
+ update_option("ppath_head_every_page", $newhtml, "yes");
33
  $html = $newhtml;
34
+ if(file_exists($htmlfile)){
35
+ unlink($htmlfile);
36
+ $configdir = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig';
37
+ $scanned_directory = array_diff(scandir($configdir), array('..', '.'));
38
+ if(empty($scanned_directory)){
39
+ rmdir($configdir);
40
+ }
41
+ }
42
+ }
43
  }
44
  global $wp_roles;
45
  $rolesallowednow = array();
104
  $typesupdated = false;
105
  }
106
  }
107
+ ?><form method="post"><?php
108
  if(current_user_can('add-to-head')|| current_user_can('manage_options')):
109
  if(isset($html)){
110
  ?><textarea style="white-space:pre; width:80%; min-width:600px; height:300px;" name="html"><?php echo $html; ?></textarea><?php