Per page add to head - Version 0.2-beta

Version Description

Download this release

Release Info

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

Version 0.2-beta

trunk/installdeinstall.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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, "");
11
+ fclose($htmlcreatehandle);
12
+ }
13
+ }
14
+ }
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
+ ?>
trunk/perpagehead.php ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 <head> section for a specific page, like custom JS or custom HTML
7
+ Version: 0.2 beta
8
+ Author: Erik von Asmuth
9
+ Author URI: http://evona.nl/over-mij/ (Dutch)
10
+ License: GPLv2
11
+ */
12
+
13
+ //Add the meta box
14
+ function perpageathaddbox() {
15
+ $screens = array( 'post', 'page' );
16
+ foreach ( $screens as $screen ) {
17
+ add_meta_box( 'per-page-ath', 'Add to head', 'athcallback', $screen, 'normal',
18
+ 'default', null );
19
+ }
20
+ }
21
+
22
+ add_action( 'add_meta_boxes', 'perpageathaddbox' );
23
+
24
+ function athcallback($post){
25
+
26
+ // Add an nonce field so we can check for it later.
27
+ wp_nonce_field( 'athcallback', 'athcontent' );
28
+
29
+ /*
30
+ * Use get_post_meta() to retrieve an existing value
31
+ * from the database and use the value for the form.
32
+ */
33
+ $value = get_post_meta( $post->ID, 'per-page-ath-content', true );
34
+
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
+ /**
42
+ * When the post is saved, saves our custom data.
43
+ *
44
+ * @param int $post_id The ID of the post being saved.
45
+ */
46
+ function perpageath_save_postdata( $post_id ) {
47
+
48
+ /*
49
+ * We need to verify this came from the our screen and with proper authorization,
50
+ * because save_post can be triggered at other times.
51
+ */
52
+
53
+ // Check if our nonce is set.
54
+ if ( ! isset( $_POST['athcontent'] ) )
55
+ return $post_id;
56
+
57
+ $nonce = $_POST['athcontent'];
58
+
59
+ // Verify that the nonce is valid.
60
+ if ( ! wp_verify_nonce( $nonce, 'athcallback' ) )
61
+ return $post_id;
62
+
63
+ // If this is an autosave, our form has not been submitted, so we don't want to do anything.
64
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
65
+ return $post_id;
66
+
67
+ // Check the user's permissions.
68
+ if ( 'page' == $_POST['post_type'] ) {
69
+
70
+ if ( ! current_user_can( 'edit_page', $post_id ) )
71
+ return $post_id;
72
+
73
+ } else {
74
+
75
+ if ( ! current_user_can( 'edit_post', $post_id ) )
76
+ return $post_id;
77
+ }
78
+
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 );
86
+ }
87
+ add_action( 'save_post', 'perpageath_save_postdata' );
88
+ //Now that's done. Let's add the meta field to the head
89
+
90
+ 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){
98
+ if($htmlhandle = fopen($htmlfile, 'r')){
99
+ $html = fread($htmlhandle, filesize($htmlfile));
100
+ fclose($htmlhandle);
101
+ echo $html;
102
+ }else{
103
+ echo "<!-- Error reading ".$htmlfile."! Is the file readable? -->";
104
+ }
105
+ }
106
+ }
107
+ add_action('wp_head', 'perpageath_display');
108
+
109
+ //Create a menu
110
+ //Load in the option page
111
+ function EvonaCreateATHMenu() {
112
+ add_options_page( 'Add &lt;head&gt; to every page', 'Add &lt;head&gt; to every page', 'manage_options', 'perpageath-every-page', 'PerPageATHSettings' );
113
+ }
114
+
115
+ function PerPageATHSettings(){
116
+ if ( !current_user_can( 'manage_options' ) ) {
117
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
118
+ }
119
+ include_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'settings.php');
120
+ perpageath_config();
121
+ }
122
+
123
+ //Create the option menu, and load admin CSS to it
124
+ add_action( 'admin_menu', 'EvonaCreateATHMenu' );
125
+
126
+ //Installation
127
+ function PerPageATHInstallStep1(){
128
+ include_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'installdeinstall.php');
129
+ PerPageATHInstallStep2();
130
+ }
131
+ register_activation_hook( __FILE__, 'PerPageATHInstallStep1');
132
+ //Deinstallation
133
+ function PerPageATHDeinstallStep1(){
134
+ include_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'installdeinstall.php');
135
+ PerPageATHDeinstallStep2();
136
+ }
137
+ register_uninstall_hook( __FILE__, 'PerPageATHDeinstallStep1');
138
+ ?>
trunk/readme.txt ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Per page add to head ===
2
+ Contributors: Erikvona
3
+ Plugin Name: Per page add to head
4
+ Tags: head, css, favicon
5
+ Author URI: http://erikvona.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.2 beta
10
+ License: GPLv2 or later
11
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
+
13
+
14
+ This plugin adds content between the head tags for specific WordPress posts, or every WordPress post.
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
+ Offcourse, 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
+
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
+
30
+ Installation is plain and simple
31
+
32
+ 1. Add the plugin to WordPress by searching and installing, uploading a zip, FTP copy, or some other way, and activate it
33
+ 1. Make sure the add to head box is visible, by checking add to head in screen options within the plugin/post editor
34
+ 1. Add your head stuff to the posts!
35
+ 1. You can also add head to all posts! Just use settings -> add head to every page
36
+
37
+ == Changelog ==
38
+
39
+ = 0.2 beta =
40
+ Initial release for the WordPress plugin repository
41
+
42
+
trunk/settings.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ function perpageath_config(){
3
+ $htmlfile = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig'.DIRECTORY_SEPARATOR.'everyheadpage.html';
4
+ ?>
5
+ <div class="wrap">
6
+ <h2>Insert HTML on every page</h2>
7
+ <h3>Everything you put in here will be inserted into the &lt;head&gt; tag on every page. Ideal for favicons!</h3>
8
+ <?php
9
+ if(!file_exists($htmlfile)){
10
+ if($htmlcreatehandle = fopen($htmlfile, 'x')){
11
+ fwrite($htmlcreatehandle, "");
12
+ fclose($htmlcreatehandle);
13
+ }else{
14
+ echo "Error creating ".$htmlfile." ! Is the underlying folder writable?";
15
+ }
16
+ }
17
+ if(isset($_POST['html'])){
18
+ if($htmlwritehandle = fopen($htmlfile, 'w')){
19
+ fwrite($htmlwritehandle, stripslashes_deep($_POST['html']));
20
+ fclose($htmlwritehandle);
21
+ echo "<p>Succesfully edited ".$htmlfile."!</p>";
22
+ }else{echo "Error writing HTML to ".$htmlfile.". Is this file writable?";}
23
+ }
24
+ if($htmlhandle = fopen($htmlfile, 'r')){
25
+ if(filesize($htmlfile) > 0){
26
+ $html = fread($htmlhandle, filesize($htmlfile));
27
+ }else{
28
+ $html = "";
29
+ }
30
+ fclose($htmlhandle);
31
+ ?>
32
+ <form method="post" action="<?php echo htmlentities(get_site_url(NULL, $_SERVER["REQUEST_URI"])); ?>">
33
+ <textarea style="white-space:pre; width:80%; min-width:600px; height:300px;" name="html"><?php echo $html; ?></textarea>
34
+ <?php
35
+ submit_button();
36
+ }else{echo "Failed reading HTML file".$htmlfile.". Is the file readable?";}
37
+ echo "</form></div>";
38
+ }
39
+ ?>