Per page add to head - Version 1.2

Version Description

  • Added support for user roles: you can prevent certain user roles from editing the head segment. Note: administrators can't be excluded, and edit the "add head to every page" segment.
  • Added support for custom post types. Note: only works when the post type is displayed "like a page" NOTE: when updating from an older version to version 1.2, make sure you go to settings -> per page add to head, and check the roles and post types you want to use after the update. New installations will have administrator, page and post checked automatically, old ones receiving an update won't
Download this release

Release Info

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

Code changes from version 1.1.2 to 1.2

installdeinstall.php CHANGED
@@ -11,6 +11,9 @@ function PerPageATHInstallStep2(){
11
  fclose($htmlcreatehandle);
12
  }
13
  }
 
 
 
14
  }
15
  function PerPageATHDeinstallStep2(){
16
  $configdir = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig';
@@ -20,6 +23,8 @@ function PerPageATHDeinstallStep2(){
20
  if(empty($scanned_directory)){
21
  rmdir($configdir);
22
  }
 
 
23
  }
24
  function PerpageathConfigMgrDeleteConfigfile($filename){
25
  $configdir = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig';
11
  fclose($htmlcreatehandle);
12
  }
13
  }
14
+ $roleobject = $wp_roles->get_role('administrator');
15
+ $roleobject->add_cap('add-to-head');
16
+ add_option('ppath_types_allowed', array('post', 'page'), '', 'no');
17
  }
18
  function PerPageATHDeinstallStep2(){
19
  $configdir = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig';
23
  if(empty($scanned_directory)){
24
  rmdir($configdir);
25
  }
26
+ delete_option('ppath_roles_allowed');
27
+ delete_option('ppath_types_allowed');
28
  }
29
  function PerpageathConfigMgrDeleteConfigfile($filename){
30
  $configdir = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig';
languages/per-page-ath-nl_NL.mo CHANGED
Binary file
languages/per-page-ath-nl_NL.po CHANGED
@@ -3,45 +3,45 @@
3
  msgid ""
4
  msgstr ""
5
  "Project-Id-Version: \n"
6
- "Report-Msgid-Bugs-To: http://wordpress.org/tag/per-page-add-to\n"
7
- "POT-Creation-Date: 2014-01-16 19:16:56+00:00\n"
 
 
 
 
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
- "PO-Revision-Date: 2014-01-16 21:02+0100\n"
12
- "Last-Translator: \n"
13
- "Language-Team: LANGUAGE <LL@li.org>\n"
14
- "X-Generator: Poedit 1.6.3\n"
15
  "Plural-Forms: nplurals=2; plural=(n != 1);\n"
16
- "Language: nl\n"
17
 
18
- #: perpagehead.php:16
19
  msgid "Add to head"
20
  msgstr "Voeg toe aan head tag"
21
 
22
- #: perpagehead.php:38
23
  msgid "Put your head html here"
24
  msgstr "Plaats je HTML voor de head tag hier"
25
 
26
- #: perpagehead.php:105
27
  msgid "Error reading config file %s! Is this file readable by the webserver?"
28
  msgstr ""
29
  "Fout bij het lezen van configuratiebestand %s! Is het bestand leesbaar door "
30
  "de webserver?"
31
 
32
- #: perpagehead.php:114
33
- msgid "Add &lt;head&gt; to every page"
34
- msgstr "Voeg &lt;head&gt; toe aan elke pagina"
35
 
36
- #: perpagehead.php:120
37
  msgid "You do not have sufficient permissions to access this page."
38
  msgstr "Je hebt niet genoeg rechten om bij deze pagina te kunnen"
39
 
40
- #: settings.php:14
41
  msgid "Insert HTML on every page"
42
  msgstr "Voeg HTML in op elke pagina"
43
 
44
- #: settings.php:15
45
  msgid ""
46
  "Everything you put in here will be inserted into the &lt;head&gt; tag on "
47
  "every page. Ideal for favicons!"
@@ -49,18 +49,92 @@ msgstr ""
49
  "Alles wat je hier toevoegd, zal in de &lt;head&gt; tag op elke pagina worden "
50
  "toegevoegd"
51
 
52
- #: settings.php:22
53
  msgid "Error creating %s! Is the underlying folder writable?"
54
  msgstr "Fout bij het maken van %s! Is de onderliggende map schrijfbaar?"
55
 
56
- #: settings.php:29
 
 
 
 
 
 
 
 
57
  msgid "Succesfully edited %s!"
58
  msgstr "%s succesvol bewerkt!"
59
 
60
- #: settings.php:30
61
  msgid "Error writing HTML to %s. Is this file writable?"
62
  msgstr "Fout bij het schrijven van HTML naar %s. Is dit bestand schrijfbaar?"
63
 
64
- #: settings.php:44
65
- msgid "Error reading HTML from file %s. Is this file readable?"
66
- msgstr "Fout bij het lezen van de HTML van %s. Is dit bestand leesbaar?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  msgid ""
4
  msgstr ""
5
  "Project-Id-Version: \n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/per-page-add-to\n"
7
+ "POT-Creation-Date: 2015-04-29 17:11:37+00:00\n"
8
+ "PO-Revision-Date: 2015-04-29 19:15+0100\n"
9
+ "Last-Translator: \n"
10
+ "Language-Team: \n"
11
+ "Language: nl\n"
12
  "MIME-Version: 1.0\n"
13
  "Content-Type: text/plain; charset=UTF-8\n"
14
  "Content-Transfer-Encoding: 8bit\n"
15
+ "X-Generator: Poedit 1.7.6\n"
 
 
 
16
  "Plural-Forms: nplurals=2; plural=(n != 1);\n"
 
17
 
18
+ #: perpagehead.php:18
19
  msgid "Add to head"
20
  msgstr "Voeg toe aan head tag"
21
 
22
+ #: perpagehead.php:41
23
  msgid "Put your head html here"
24
  msgstr "Plaats je HTML voor de head tag hier"
25
 
26
+ #: perpagehead.php:104
27
  msgid "Error reading config file %s! Is this file readable by the webserver?"
28
  msgstr ""
29
  "Fout bij het lezen van configuratiebestand %s! Is het bestand leesbaar door "
30
  "de webserver?"
31
 
32
+ #: perpagehead.php:118
33
+ msgid "Per Page Add To Head"
34
+ msgstr "Per Page Add To Head"
35
 
36
+ #: perpagehead.php:124
37
  msgid "You do not have sufficient permissions to access this page."
38
  msgstr "Je hebt niet genoeg rechten om bij deze pagina te kunnen"
39
 
40
+ #: settings.php:15
41
  msgid "Insert HTML on every page"
42
  msgstr "Voeg HTML in op elke pagina"
43
 
44
+ #: settings.php:16
45
  msgid ""
46
  "Everything you put in here will be inserted into the &lt;head&gt; tag on "
47
  "every page. Ideal for favicons!"
49
  "Alles wat je hier toevoegd, zal in de &lt;head&gt; tag op elke pagina worden "
50
  "toegevoegd"
51
 
52
+ #: settings.php:24
53
  msgid "Error creating %s! Is the underlying folder writable?"
54
  msgstr "Fout bij het maken van %s! Is de onderliggende map schrijfbaar?"
55
 
56
+ #: settings.php:35
57
+ msgid "Error reading HTML from file %s. Is this file readable?"
58
+ msgstr "Fout bij het lezen van de HTML van %s. Is dit bestand leesbaar?"
59
+
60
+ #: settings.php:39
61
+ msgid "HTML not updated"
62
+ msgstr "HTML niet bijgewerkt"
63
+
64
+ #: settings.php:44
65
  msgid "Succesfully edited %s!"
66
  msgstr "%s succesvol bewerkt!"
67
 
68
+ #: settings.php:45
69
  msgid "Error writing HTML to %s. Is this file writable?"
70
  msgstr "Fout bij het schrijven van HTML naar %s. Is dit bestand schrijfbaar?"
71
 
72
+ #: settings.php:116
73
+ msgid "Manage which users can access the plugin"
74
+ msgstr "Beheer gebruikers die toegang hebben tot de plugin"
75
+
76
+ #: settings.php:120
77
+ msgid "Succesfully updated user role support"
78
+ msgstr "Gebruikersrollen succesvol bijgewerkt"
79
+
80
+ #: settings.php:122
81
+ msgid "User role support not updated"
82
+ msgstr "Gebruikersrollen niet bijgewerkt"
83
+
84
+ #: settings.php:135
85
+ msgid "Manage post types that have the per page add to head box"
86
+ msgstr "Beheer pagina's die de per pagina toevoegen aan kop box hebben"
87
+
88
+ #: settings.php:136
89
+ msgid ""
90
+ "Note: only post types which have their own page (like posts or pages, but "
91
+ "not navigation menu items) are supported"
92
+ msgstr ""
93
+ "Noot: alleen berichttypen die hun eigen pagina hebben (zoals berichten en "
94
+ "pagina's, maar niet navigatiemenu-items) zijn ondersteund"
95
+
96
+ #: settings.php:140
97
+ msgid "Succesfully updated post type support"
98
+ msgstr "Berichttype ondersteuning succesvol bijgewerkt"
99
+
100
+ #: settings.php:142
101
+ msgid "Post type support not updated"
102
+ msgstr "Berichttypeondersteuning niet bijgewerkt"
103
+
104
+ #. Plugin Name of the plugin/theme
105
+ msgid "Per page head"
106
+ msgstr "Per Page Head"
107
+
108
+ #. Plugin URI of the plugin/theme
109
+ msgid "http://www.evona.nl/plugins/per-page-head"
110
+ msgstr "http://www.evona.nl/plugins/per-page-head"
111
+
112
+ #. Description of the plugin/theme
113
+ msgid ""
114
+ "Allows you to add content into the &lt;head&gt; section for a specific page, "
115
+ "like custom JS or custom HTML, using post meta. Also allows you to add "
116
+ "content for every page, under Settings -> add &lt;head&gt; to every page"
117
+ msgstr ""
118
+
119
+ #. Author of the plugin/theme
120
+ msgid "Erik von Asmuth"
121
+ msgstr "Erik von Asmuth"
122
+
123
+ #. Author URI of the plugin/theme
124
+ msgid "http://evona.nl/about-me/"
125
+ msgstr "http://evona.nl/over-mij/"
126
+
127
+ #~ msgid "Succesfully updated role support"
128
+ #~ msgstr "Gebruikersrollen succesvol bijgewerkt"
129
+
130
+ #~ msgid "Role support not updated"
131
+ #~ msgstr "Gebruikersrollen niet bijgewerkt"
132
+
133
+ #~ msgid "Succesfully updated type support"
134
+ #~ msgstr "Berichttype ondersteuning succesvol bijgewerkt"
135
+
136
+ #~ msgid "type support not updated"
137
+ #~ msgstr "Berichttypeondersteuning niet bijgewerkt"
138
+
139
+ #~ msgid "Add &lt;head&gt; to every page"
140
+ #~ msgstr "Voeg &lt;head&gt; toe aan elke pagina"
languages/per-page-ath.pot CHANGED
@@ -1,59 +1,116 @@
1
- # Copyright (C) 2014
2
- # This file is distributed under the same license as the package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: \n"
6
- "Report-Msgid-Bugs-To: http://wordpress.org/tag/per-page-add-to\n"
7
- "POT-Creation-Date: 2014-01-16 19:16:56+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
- "PO-Revision-Date: 2014-MO-DA HO:MI+ZONE\n"
12
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
  "Language-Team: LANGUAGE <LL@li.org>\n"
14
 
15
- #: perpagehead.php:16
16
  msgid "Add to head"
17
  msgstr ""
18
 
19
- #: perpagehead.php:38
20
  msgid "Put your head html here"
21
  msgstr ""
22
 
23
- #: perpagehead.php:105
24
  msgid "Error reading config file %s! Is this file readable by the webserver?"
25
  msgstr ""
26
 
27
- #: perpagehead.php:114
28
- msgid "Add &lt;head&gt; to every page"
29
  msgstr ""
30
 
31
- #: perpagehead.php:120
32
  msgid "You do not have sufficient permissions to access this page."
33
  msgstr ""
34
 
35
- #: settings.php:14
36
  msgid "Insert HTML on every page"
37
  msgstr ""
38
 
39
- #: settings.php:15
40
  msgid ""
41
  "Everything you put in here will be inserted into the &lt;head&gt; tag on "
42
  "every page. Ideal for favicons!"
43
  msgstr ""
44
 
45
- #: settings.php:22
46
  msgid "Error creating %s! Is the underlying folder writable?"
47
  msgstr ""
48
 
49
- #: settings.php:29
 
 
 
 
 
 
 
 
50
  msgid "Succesfully edited %s!"
51
  msgstr ""
52
 
53
- #: settings.php:30
54
  msgid "Error writing HTML to %s. Is this file writable?"
55
  msgstr ""
56
 
57
- #: settings.php:44
58
- msgid "Error reading HTML from file %s. Is this file readable?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  msgstr ""
1
+ # Copyright (C) 2015 Per page head
2
+ # This file is distributed under the same license as the Per page head package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: Per page head 1.2\n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/per-page-add-to\n"
7
+ "POT-Creation-Date: 2015-04-29 17:11:37+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n"
12
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
  "Language-Team: LANGUAGE <LL@li.org>\n"
14
 
15
+ #: perpagehead.php:18
16
  msgid "Add to head"
17
  msgstr ""
18
 
19
+ #: perpagehead.php:41
20
  msgid "Put your head html here"
21
  msgstr ""
22
 
23
+ #: perpagehead.php:104
24
  msgid "Error reading config file %s! Is this file readable by the webserver?"
25
  msgstr ""
26
 
27
+ #: perpagehead.php:118
28
+ msgid "Per Page Add To Head"
29
  msgstr ""
30
 
31
+ #: perpagehead.php:124
32
  msgid "You do not have sufficient permissions to access this page."
33
  msgstr ""
34
 
35
+ #: settings.php:15
36
  msgid "Insert HTML on every page"
37
  msgstr ""
38
 
39
+ #: settings.php:16
40
  msgid ""
41
  "Everything you put in here will be inserted into the &lt;head&gt; tag on "
42
  "every page. Ideal for favicons!"
43
  msgstr ""
44
 
45
+ #: settings.php:24
46
  msgid "Error creating %s! Is the underlying folder writable?"
47
  msgstr ""
48
 
49
+ #: settings.php:35
50
+ msgid "Error reading HTML from file %s. Is this file readable?"
51
+ msgstr ""
52
+
53
+ #: settings.php:39
54
+ msgid "HTML not updated"
55
+ msgstr ""
56
+
57
+ #: settings.php:44
58
  msgid "Succesfully edited %s!"
59
  msgstr ""
60
 
61
+ #: settings.php:45
62
  msgid "Error writing HTML to %s. Is this file writable?"
63
  msgstr ""
64
 
65
+ #: settings.php:116
66
+ msgid "Manage which users can access the plugin"
67
+ msgstr ""
68
+
69
+ #: settings.php:120
70
+ msgid "Succesfully updated user role support"
71
+ msgstr ""
72
+
73
+ #: settings.php:122
74
+ msgid "User role support not updated"
75
+ msgstr ""
76
+
77
+ #: settings.php:135
78
+ msgid "Manage post types that have the per page add to head box"
79
+ msgstr ""
80
+
81
+ #: settings.php:136
82
+ msgid ""
83
+ "Note: only post types which have their own page (like posts or pages, but "
84
+ "not navigation menu items) are supported"
85
+ msgstr ""
86
+
87
+ #: settings.php:140
88
+ msgid "Succesfully updated post type support"
89
+ msgstr ""
90
+
91
+ #: settings.php:142
92
+ msgid "Post type support not updated"
93
+ msgstr ""
94
+
95
+ #. Plugin Name of the plugin/theme
96
+ msgid "Per page head"
97
+ msgstr ""
98
+
99
+ #. Plugin URI of the plugin/theme
100
+ msgid "http://www.evona.nl/plugins/per-page-head"
101
+ msgstr ""
102
+
103
+ #. Description of the plugin/theme
104
+ msgid ""
105
+ "Allows you to add content into the &lt;head&gt; section for a specific page, "
106
+ "like custom JS or custom HTML, using post meta. Also allows you to add "
107
+ "content for every page, under Settings -> add &lt;head&gt; to every page"
108
+ msgstr ""
109
+
110
+ #. Author of the plugin/theme
111
+ msgid "Erik von Asmuth"
112
+ msgstr ""
113
+
114
+ #. Author URI of the plugin/theme
115
+ msgid "http://evona.nl/about-me/"
116
  msgstr ""
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 &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.1.2
8
  Author: Erik von Asmuth
9
  Author URI: http://evona.nl/about-me/
10
  License: GPLv2
@@ -14,12 +14,14 @@ load_plugin_textdomain('per-page-ath', false, basename( dirname( __FILE__ ) ) .
14
 
15
  //Add the meta box
16
  function perpageathaddbox() {
17
- $addtohead = __('Add to head', 'per-page-ath');
18
- $screens = array( 'post', 'page' );
19
- foreach ( $screens as $screen ) {
20
- add_meta_box( 'per-page-ath', $addtohead, 'athcallback', $screen, 'normal',
21
- 'default', null );
22
- }
 
 
23
  }
24
 
25
  add_action( 'add_meta_boxes', 'perpageathaddbox' );
@@ -113,7 +115,7 @@ add_action('wp_head', 'perpageath_display', 1000);
113
  //Create a menu
114
  //Load in the option page
115
  function EvonaCreateATHMenu() {
116
- $menuname = __('Add &lt;head&gt; to every page', 'per-page-ath');
117
  add_options_page( $menuname, $menuname, 'manage_options', 'perpageath-every-page', 'PerPageATHSettings' );
118
  }
119
 
@@ -140,4 +142,4 @@ function PerPageATHDeinstallStep1(){
140
  PerPageATHDeinstallStep2();
141
  }
142
  register_uninstall_hook( __FILE__, 'PerPageATHDeinstallStep1');
143
- ?>
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.2
8
  Author: Erik von Asmuth
9
  Author URI: http://evona.nl/about-me/
10
  License: GPLv2
14
 
15
  //Add the meta box
16
  function perpageathaddbox() {
17
+ if(current_user_can('add-to-head')||current_user_can('manage_options')){
18
+ $addtohead = __('Add to head', 'per-page-ath');
19
+ $screens = get_option('ppath_types_allowed', array('post', 'page'));
20
+ foreach ( $screens as $screen ) {
21
+ add_meta_box( 'per-page-ath', $addtohead, 'athcallback', $screen, 'normal',
22
+ 'default', null );
23
+ }
24
+ }
25
  }
26
 
27
  add_action( 'add_meta_boxes', 'perpageathaddbox' );
115
  //Create a menu
116
  //Load in the option page
117
  function EvonaCreateATHMenu() {
118
+ $menuname = __('Per Page Add To Head', 'per-page-ath');
119
  add_options_page( $menuname, $menuname, 'manage_options', 'perpageath-every-page', 'PerPageATHSettings' );
120
  }
121
 
142
  PerPageATHDeinstallStep2();
143
  }
144
  register_uninstall_hook( __FILE__, 'PerPageATHDeinstallStep1');
145
+ ?>
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.1
9
- Stable tag: 1.1.2
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
@@ -17,7 +17,7 @@ This plugin adds content between the head tags for specific WordPress posts, or
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
 
@@ -32,20 +32,25 @@ Installation is plain and simple
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
  = 1.1.2 =
40
  - Changes the output order to global content first, then page specific content.
41
  - Moves the per page add to head output down the queue on the wp_head hook, so the content is inserted at the end of the head tag
42
 
43
  = 1.1.1 =
44
- - Includes spanish translation thanks to Andrew Kurtis from WebHostingHub
45
 
46
  = 1.1 =
47
  - Now supports l18n!
48
- - Includes dutch translation.
49
 
50
  = 1.0 =
51
  - Now uses $_SERVER superglobal to locate current page url
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
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
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 you�re too lazy to make a child theme.
23
 
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 -> per page add to head
36
 
37
  == Changelog ==
38
 
39
+ = 1.2 =
40
+ - Added support for user roles: you can prevent certain user roles from editing the head segment. Note: administrators can't be excluded, and edit the "add head to every page" segment.
41
+ - Added support for custom post types. Note: only works when the post type is displayed "like a page"
42
+ **NOTE: when updating from an older version to version 1.2, make sure you go to settings -> per page add to head, and check the roles and post types you want to use after the update. New installations will have administrator, page and post checked automatically, old ones receiving an update won't**
43
+
44
  = 1.1.2 =
45
  - Changes the output order to global content first, then page specific content.
46
  - Moves the per page add to head output down the queue on the wp_head hook, so the content is inserted at the end of the head tag
47
 
48
  = 1.1.1 =
49
+ - Includes Spanish translation thanks to Andrew Kurtis from WebHostingHub
50
 
51
  = 1.1 =
52
  - Now supports l18n!
53
+ - Includes Dutch translation.
54
 
55
  = 1.0 =
56
  - Now uses $_SERVER superglobal to locate current page url
settings.php CHANGED
@@ -10,9 +10,11 @@ function perpageath_config(){
10
  }
11
  $htmlfile = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig'.DIRECTORY_SEPARATOR.'everyheadpage.html';
12
  ?>
 
13
  <div class="wrap">
14
  <h2><?php _e('Insert HTML on every page', 'per-page-ath'); ?></h2>
15
  <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>
 
16
  <?php
17
  if(!file_exists($htmlfile)){
18
  if($htmlcreatehandle = fopen($htmlfile, 'x')){
@@ -22,13 +24,6 @@ function perpageath_config(){
22
  printf(__("Error creating %s! Is the underlying folder writable?", 'per-page-ath'), $htmlfile);
23
  }
24
  }
25
- if(isset($_POST['html'])){
26
- if($htmlwritehandle = fopen($htmlfile, 'w')){
27
- fwrite($htmlwritehandle, stripslashes_deep($_POST['html']));
28
- fclose($htmlwritehandle);
29
- printf(__("Succesfully edited %s!", 'per-page-ath'), $htmlfile);
30
- }else{printf(__("Error writing HTML to %s. Is this file writable?", 'per-page-ath'), $htmlfile);}
31
- }
32
  if($htmlhandle = fopen($htmlfile, 'r')){
33
  if(filesize($htmlfile) > 0){
34
  $html = fread($htmlhandle, filesize($htmlfile));
@@ -36,12 +31,131 @@ function perpageath_config(){
36
  $html = "";
37
  }
38
  fclose($htmlhandle);
39
- ?>
40
- <form method="post" action="<?php echo $currenturl; ?>">
41
- <textarea style="white-space:pre; width:80%; min-width:600px; height:300px;" name="html"><?php echo $html; ?></textarea>
42
- <?php
43
- submit_button();
44
  }else{printf(__("Error reading HTML from file %s. Is this file readable?", 'per-page-ath'), $htmlfile);}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  echo "</form></div>";
46
  }
47
  ?>
10
  }
11
  $htmlfile = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'evonapluginconfig'.DIRECTORY_SEPARATOR.'everyheadpage.html';
12
  ?>
13
+
14
  <div class="wrap">
15
  <h2><?php _e('Insert HTML on every page', 'per-page-ath'); ?></h2>
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')){
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));
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();
49
+ foreach($wp_roles->get_names() as $role_slug => $role_name){
50
+ $roleobject = $wp_roles->get_role($role_slug);
51
+ if(isset($roleobject->capabilities['add-to-head']) && $roleobject->capabilities['add-to-head']==1){
52
+ $rolesallowednow[] = $role_slug;
53
+ }
54
+ }
55
+ if(!in_array('administrator',$rolesallowednow)){
56
+ $roleobject = $wp_roles->get_role('administrator');
57
+ $roleobject->add_cap('add-to-head');
58
+ $rolesallowednow[]='administrator';
59
+ }
60
+ $posttypesallowednow = get_option('ppath_types_allowed', array('post', 'page'));
61
+
62
+ if(isset($_POST['submit'])){
63
+ //Role management
64
+ //Check if all values are really roles
65
+ $optionroles = array('administrator');
66
+ if(isset($_POST['rolesallowed'])&& is_array($_POST['rolesallowed'])){
67
+ foreach($_POST['rolesallowed'] as $roleallowed){
68
+ if($wp_roles->is_role($roleallowed)){
69
+ $optionroles[]=$roleallowed;
70
+ }
71
+ }
72
+ }
73
+ //If changed, update roles
74
+ if($optionroles != $rolesallowednow){
75
+ if(current_user_can('manage_options')){
76
+ foreach($optionroles as $role){
77
+ $roleobject = $wp_roles->get_role($role);
78
+ $roleobject->add_cap('add-to-head');
79
+ }
80
+ $revokedroles = array_diff($rolesallowednow, $optionroles);
81
+ if(!empty($revokedroles)){
82
+ foreach($revokedroles as $role){
83
+ $roleobject = $wp_roles->get_role($role);
84
+ $roleobject->remove_cap('add-to-head');
85
+ }
86
+ }
87
+ $rolesallowednow = $optionroles;
88
+ $rolesupdated = true;
89
+ }
90
+ }else{
91
+ $rolesupdated = false;
92
+ }
93
+ //Post type management
94
+ $newposttypes = array();
95
+ if(isset($_POST['typeallowed'])&& is_array($_POST['typeallowed'])){
96
+ foreach($_POST['typeallowed'] as $newposttype){
97
+ if(post_type_exists($newposttype)){
98
+ $newposttypes[]= $newposttype;
99
+ }
100
+ }
101
+ }
102
+ if($newposttypes != $posttypesallowednow && current_user_can('add-to-head')){
103
+ update_option('ppath_types_allowed', $newposttypes);
104
+ $posttypesallowednow = $newposttypes;
105
+ $typesupdated = true;
106
+ }else{
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
114
+ }
115
+ ?><br />
116
+ <h3><?php _e('Manage which users can access the plugin', 'per-page-ath');?></h3>
117
+ <?php
118
+ if(isset($rolesupdated)){
119
+ if($rolesupdated){
120
+ _e('Succesfully updated user role support', 'per-page-ath');
121
+ }else{
122
+ _e('User role support not updated', 'per-page-ath');
123
+ }
124
+ }
125
+ ?>
126
+ <table>
127
+ <?php
128
+ foreach($wp_roles->get_names() as $role_slug => $role_name){
129
+ ?><tr><td><?php echo translate_user_role($role_name);?></td><td><input type="checkbox" name="rolesallowed[]" value="<?php echo $role_slug; ?>" <?php if(in_array($role_slug, $rolesallowednow)){ echo ' checked="checked"';} if($role_slug == 'administrator'){echo ' disabled="disabled"';}?> /></td></tr>
130
+ <?php
131
+ }
132
+ ?>
133
+ </table>
134
+ <br />
135
+ <h3><?php _e('Manage post types that have the per page add to head box', 'per-page-ath');?></h3>
136
+ <p><?php _e('Note: only post types which have their own page (like posts or pages, but not navigation menu items) are supported' , 'per-page-ath'); ?></p>
137
+ <?php
138
+ if(isset($typesupdated)){
139
+ if($typesupdated){
140
+ _e('Succesfully updated post type support', 'per-page-ath');
141
+ }else{
142
+ _e('Post type support not updated', 'per-page-ath');
143
+ }
144
+ }
145
+ ?>
146
+ <table>
147
+ <?php
148
+ $post_types = get_post_types('', 'names');
149
+ foreach($post_types as $post_type){
150
+ $post_type_object = get_post_type_object( $post_type );
151
+ ?><tr><td><?php echo $post_type_object->labels->name;?></td><td><input type="checkbox" name="typeallowed[]" value="<?php echo $post_type; ?>" <?php if(in_array($post_type, $posttypesallowednow)){ echo ' checked="checked"';} ?> /></td></tr>
152
+ <?php
153
+ }
154
+ ?>
155
+ </table>
156
+ <?php
157
+ submit_button();
158
+ endif;
159
  echo "</form></div>";
160
  }
161
  ?>