Per page add to head - Version 1.0

Version Description

  • Now uses $_SERVER superglobal to locate current page url
  • Now properly preserves whitespace. Whitespace is visible in the source code, as well as in the meta box of the posts
  • Compatibility with Evona Config Manager (to be released, allows you to keep this plugin from removing its config files upon deinstallation).
Download this release

Release Info

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

Code changes from version 0.3 to 1.0

Files changed (4) hide show
  1. installdeinstall.php +32 -1
  2. perpagehead.php +5 -5
  3. readme.txt +8 -3
  4. settings.php +8 -2
installdeinstall.php CHANGED
@@ -15,10 +15,41 @@ function PerPageATHInstallStep2(){
15
  function PerPageATHDeinstallStep2(){
16
  $configdir = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig';
17
  $htmlfile = $configdir.DIRECTORY_SEPARATOR.'everyheadpage.html';
18
- unlink($htmlfile);
19
  $scanned_directory = array_diff(scandir($configdir), array('..', '.'));
20
  if(empty($scanned_directory)){
21
  rmdir($configdir);
22
  }
23
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  ?>
15
  function PerPageATHDeinstallStep2(){
16
  $configdir = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig';
17
  $htmlfile = $configdir.DIRECTORY_SEPARATOR.'everyheadpage.html';
18
+ PerpageathConfigMgrDeleteConfigfile($htmlfile);
19
  $scanned_directory = array_diff(scandir($configdir), array('..', '.'));
20
  if(empty($scanned_directory)){
21
  rmdir($configdir);
22
  }
23
  }
24
+ function PerpageathConfigMgrDeleteConfigfile($filename){
25
+ $configdir = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig';
26
+ $keepfileindex = $configdir.DIRECTORY_SEPARATOR.'keepfiles.txt';
27
+ $neverdelete = $configdir.DIRECTORY_SEPARATOR.'neverdelete.txt';
28
+ if(is_file($configdir .DIRECTORY_SEPARATOR. basename($filename))){
29
+ //File exists and is inside the config dir
30
+ if(!is_file($neverdelete)){
31
+ //never delete is not set
32
+ if(is_file($keepfileindex)){
33
+ //There is a keep file index
34
+ $tokeep = file($keepfileindex, FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES);
35
+ if(!in_array($basename($filename),$tokeep)){
36
+ //but the file to delete isn't in it
37
+ return unlink($filename);
38
+ }else{
39
+ //The file is in the keep file index, do not delete
40
+ return false;
41
+ }
42
+ }else{
43
+ //There is no keep file index, delete
44
+ return unlink($filename);
45
+ }
46
+ }else{
47
+ //Never delete is set, do not delete
48
+ return false;
49
+ }
50
+ }else{
51
+ //The file is invalid, do not delete (but can't delete anyway)
52
+ return false;
53
+ }
54
+ }
55
  ?>
perpagehead.php CHANGED
@@ -3,8 +3,8 @@
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 <head> section for a specific page, like custom JS or custom HTML
7
- Version: 0.3
8
  Author: Erik von Asmuth
9
  Author URI: http://evona.nl/over-mij/ (Dutch)
10
  License: GPLv2
@@ -35,7 +35,7 @@ function athcallback($post){
35
  echo '<label for="per-page-ath">';
36
  _e( "Put your head html here", 'per-page-ath' );
37
  echo '</label><br/> ';
38
- echo '<textarea id="perpageathtextbox" style="width:100%;" name="per-page-ath">'.esc_attr(stripslashes_deep( $value )).'</textarea>';
39
  }
40
 
41
  /**
@@ -79,7 +79,7 @@ function perpageath_save_postdata( $post_id ) {
79
  /* OK, its safe for us to save the data now. */
80
 
81
  // Sanitize user input.
82
- $mydata = esc_sql( str_replace(array("\r\n", "\r", "\n"), '',$_POST['per-page-ath']) );
83
 
84
  // Update the meta field in the database.
85
  update_post_meta( $post_id, 'per-page-ath-content', $mydata );
@@ -91,7 +91,7 @@ function perpageath_display(){
91
  $pageid = get_queried_object_id();
92
  $addtoheadcontent = get_post_meta( $pageid, 'per-page-ath-content', true );
93
  if(!empty($addtoheadcontent)){
94
- echo stripslashes_deep($addtoheadcontent);
95
  }
96
  $htmlfile = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig'.DIRECTORY_SEPARATOR.'everyheadpage.html';
97
  if(file_exists($htmlfile)&& filesize($htmlfile) > 0){
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 -> add &lt;head&gt; to every page
7
+ Version: 1.0
8
  Author: Erik von Asmuth
9
  Author URI: http://evona.nl/over-mij/ (Dutch)
10
  License: GPLv2
35
  echo '<label for="per-page-ath">';
36
  _e( "Put your head html here", 'per-page-ath' );
37
  echo '</label><br/> ';
38
+ 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>';
39
  }
40
 
41
  /**
79
  /* OK, its safe for us to save the data now. */
80
 
81
  // Sanitize user input.
82
+ $mydata = esc_sql( str_replace(array("\r\n", "\r", "\n"), '%BREAK%',$_POST['per-page-ath']) );
83
 
84
  // Update the meta field in the database.
85
  update_post_meta( $post_id, 'per-page-ath-content', $mydata );
91
  $pageid = get_queried_object_id();
92
  $addtoheadcontent = get_post_meta( $pageid, 'per-page-ath-content', true );
93
  if(!empty($addtoheadcontent)){
94
+ echo str_replace('%BREAK%', "\n", stripslashes_deep($addtoheadcontent));
95
  }
96
  $htmlfile = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig'.DIRECTORY_SEPARATOR.'everyheadpage.html';
97
  if(file_exists($htmlfile)&& filesize($htmlfile) > 0){
readme.txt CHANGED
@@ -5,8 +5,8 @@ Tags: head, css, favicon
5
  Author URI: http://evona.com/over-mij
6
  Author: Erik von Asmuth (Erikvona)
7
  Requires at least: 3.5
8
- Tested up to: 3.6
9
- Stable tag: 0.3
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
@@ -23,7 +23,7 @@ Add to head also features an option under settings to add some text inside <head
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
 
26
- **Warning:** Don't put stuff in the head tags that shouldn't be there! This plugin does not validate anything, and it is really easy to invalidate your HTML by making mistakes in your head tag
27
 
28
  == Installation ==
29
 
@@ -36,6 +36,11 @@ Installation is plain and simple
36
 
37
  == Changelog ==
38
 
 
 
 
 
 
39
  = 0.3 =
40
  Fixed an issue that could occur when WordPress was hosted inside a subfolder of the domain
41
 
5
  Author URI: http://evona.com/over-mij
6
  Author: Erik von Asmuth (Erikvona)
7
  Requires at least: 3.5
8
+ Tested up to: 3.6.1
9
+ Stable tag: 1.0
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
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
 
26
+ **Warning:** Don't put stuff in the head tags that shouldn't be there! This plugin does not validate anything, and it is really easy to invalidate your HTML by making mistakes in your head tag. Don't forget to add <style> or <script> tags
27
 
28
  == Installation ==
29
 
36
 
37
  == Changelog ==
38
 
39
+ = 1.0 =
40
+ - Now uses $_SERVER superglobal to locate current page url
41
+ - Now properly preserves whitespace. Whitespace is visible in the source code, as well as in the meta box of the posts
42
+ - Compatibility with Evona Config Manager (to be released, allows you to keep this plugin from removing its config files upon deinstallation).
43
+
44
  = 0.3 =
45
  Fixed an issue that could occur when WordPress was hosted inside a subfolder of the domain
46
 
settings.php CHANGED
@@ -1,7 +1,13 @@
1
  <?php
2
  function perpageath_config(){
3
- $request_uri_array = explode("/", $_SERVER['REQUEST_URI']);
4
- $currenturl = htmlentities(get_site_url(NULL, "/". $request_uri_array[count($request_uri_array)-2]."/" .end($request_uri_array)));
 
 
 
 
 
 
5
  $htmlfile = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig'.DIRECTORY_SEPARATOR.'everyheadpage.html';
6
  ?>
7
  <div class="wrap">
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
  <div class="wrap">