Version Description
Download this release
Release Info
Developer | urkekg |
Plugin | Head & Footer Code |
Version | 1.3.0 |
Comparing to | |
See all releases |
Code changes from version 1.2.4 to 1.3.0
- assets/css/admin.css +0 -2
- assets/css/admin.css.map +0 -7
- assets/css/admin.min.css +2 -0
- assets/css/admin.min.css.map +9 -0
- assets/css/admin.scss +11 -15
- assets/img/paypal.png +0 -0
- head-footer-code.php +12 -7
- inc/auhfc-category-meta-box.php +115 -0
- inc/class-auhfc-meta-box.php +27 -18
- inc/front.php +108 -74
- inc/helpers.php +142 -80
- inc/posts-custom-columns.php +34 -10
- inc/settings.php +174 -115
- inc/update.php +41 -16
- index.php +6 -1
- readme.txt +84 -44
- templates/settings.php +25 -10
- uninstall.php +25 -10
assets/css/admin.css
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
#head_footer_code_settings .head_footer_code_wrapper{display:table;width:100%}#head_footer_code_settings .head_footer_code_wrapper .content_cell{display:table-cell}#head_footer_code_settings .head_footer_code_wrapper .sidebar_container{display:table-cell;padding:0 0 0 20px;width:25%}#head_footer_code_settings .head_footer_code_wrapper .sidebar_container .auhfc-button{display:block;background:#fff;border-radius:7px;border:1px solid rgba(0,0,0,0.1);box-shadow:0 0 0 5px rgba(0,0,0,0.1);padding:11px 15px;white-space:nowrap;line-height:18px;color:#bdbdbd;text-shadow:1px 1px #fff;text-decoration:none;position:relative;min-width:120px}#head_footer_code_settings .head_footer_code_wrapper .sidebar_container .auhfc-button:hover{color:#6796a9;background-color:#c2edff}#head_footer_code_settings .head_footer_code_wrapper .sidebar_container .auhfc-button.paypal_donate:after{content:' ';background-image:url(../img/paypal.png);background-repeat:no-repeat;background-position:center right;width:62px;height:100%;display:inline-block;position:absolute;right:15px;top:0;bottom:0}.fixed .column-hfc{width:14%}.fixed .column-hfc .n-a{opacity:0.5;cursor:help}.fixed .column-hfc .badge{padding:.1rem .5rem;font-weight:600;font-size:.6rem;margin:.5rem .5rem 0 0;display:inline-block;background:transparent}.fixed .column-hfc .badge.blue{border:1px solid #bfe7f3}.fixed .column-hfc .badge.blue:hover{border-color:#007cba}
|
2 |
-
/*# sourceMappingURL=admin.css.map */
|
|
|
|
assets/css/admin.css.map
DELETED
@@ -1,7 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"version": 3,
|
3 |
-
"mappings": "AACI,oDAA0B,CACtB,OAAO,CAAE,KAAK,CACd,KAAK,CAAE,IAAI,CAEX,kEAAc,CACV,OAAO,CAAE,UAAU,CAGvB,uEAAmB,CACf,OAAO,CAAE,UAAU,CACnB,OAAO,CAAE,UAAU,CACnB,KAAK,CAAE,GAAG,CAEV,qFAAc,CACV,OAAO,CAAE,KAAK,CACd,UAAU,CAAE,IAAI,CAChB,aAAa,CAAE,GAAG,CAClB,MAAM,CAAE,yBAAyB,CACjC,UAAU,CAAE,yBAAyB,CACrC,OAAO,CAAE,SAAS,CAClB,WAAW,CAAE,MAAM,CACnB,WAAW,CAAE,IAAI,CACjB,KAAK,CAAE,OAAO,CACd,WAAW,CAAE,YAAY,CACzB,eAAe,CAAE,IAAI,CACrB,QAAQ,CAAE,QAAQ,CAClB,SAAS,CAAE,KAAK,CAEhB,2FAAQ,CACJ,KAAK,CAAE,OAAO,CACd,gBAAgB,CAAE,OAAO,CAG7B,yGAAsB,CAClB,OAAO,CAAE,GAAG,CACZ,gBAAgB,CAAE,sBAAsB,CACxC,iBAAiB,CAAE,SAAS,CAC5B,mBAAmB,CAAE,YAAY,CACjC,KAAK,CAAE,IAAI,CACX,MAAM,CAAE,IAAI,CACZ,OAAO,CAAE,YAAY,CACrB,QAAQ,CAAE,QAAQ,CAClB,KAAK,CAAE,IAAI,CACX,GAAG,CAAE,CAAC,CACN,MAAM,CAAE,CAAC,CAM7B,kBAAmB,CACf,KAAK,CAAE,GAAG,CACV,uBAAK,CACD,OAAO,CAAE,GAAG,CACZ,MAAM,CAAE,IAAI,CAKhB,yBAAO,CACH,OAAO,CAAE,WAAW,CACpB,WAAW,CAAE,GAAG,CAChB,SAAS,CAAE,KAAK,CAChB,MAAM,CAAE,eAAe,CACvB,OAAO,CAAE,YAAY,CACrB,UAAU,CAAE,WAAW,CAEvB,8BAAO,CACH,MAAM,CAAE,iBAAiB,CACzB,oCAAQ,CACJ,YAAY,CAAE,OAAO",
|
4 |
-
"sources": ["admin.scss"],
|
5 |
-
"names": [],
|
6 |
-
"file": "admin.css"
|
7 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assets/css/admin.min.css
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
#head_footer_code_settings .head_footer_code_wrapper{display:table;width:100%}#head_footer_code_settings .head_footer_code_wrapper .content_cell{display:table-cell}#head_footer_code_settings .head_footer_code_wrapper .sidebar_container{display:table-cell;padding:0 0 0 20px;width:25%}#head_footer_code_settings .head_footer_code_wrapper .sidebar_container .auhfc-button{display:block;background:#fff;border-radius:7px;border:1px solid rgba(0,0,0,0.1);-webkit-box-shadow:0 0 0 5px rgba(0,0,0,0.1);box-shadow:0 0 0 5px rgba(0,0,0,0.1);padding:11px 15px;white-space:nowrap;line-height:18px;color:#bdbdbd;text-shadow:1px 1px #fff;text-decoration:none;position:relative;min-width:120px}#head_footer_code_settings .head_footer_code_wrapper .sidebar_container .auhfc-button:hover{color:#6796a9;background-color:#c2edff}#head_footer_code_settings .head_footer_code_wrapper .sidebar_container .auhfc-button.paypal em{font-weight:500;font-style:italic}#head_footer_code_settings .head_footer_code_wrapper .sidebar_container .auhfc-button.paypal em i{color:#003087}#head_footer_code_settings .head_footer_code_wrapper .sidebar_container .auhfc-button.paypal em i+i{color:#009cde}.fixed .column-hfc{width:14%}.fixed .column-hfc .n-a{opacity:0.5;cursor:help}.fixed .column-hfc .badge{padding:.1rem .5rem;font-weight:600;font-size:.6rem;margin:.5rem .5rem 0 0;display:inline-block;background:transparent}.fixed .column-hfc .badge.blue{border:1px solid #bfe7f3}.fixed .column-hfc .badge.blue:hover{border-color:#007cba}
|
2 |
+
/*# sourceMappingURL=admin.min.css.map */
|
assets/css/admin.min.css.map
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"version": 3,
|
3 |
+
"mappings": "AAAA,AACI,0BADsB,CACtB,yBAAyB,AAAC,CACtB,OAAO,CAAE,KAAK,CACd,KAAK,CAAE,IAAI,CA4Cd,AA/CL,AAKQ,0BALkB,CACtB,yBAAyB,CAIrB,aAAa,AAAC,CACV,OAAO,CAAE,UAAU,CACtB,AAPT,AASQ,0BATkB,CACtB,yBAAyB,CAQrB,kBAAkB,AAAC,CACf,OAAO,CAAE,UAAU,CACnB,OAAO,CAAE,UAAU,CACnB,KAAK,CAAE,GAAG,CAkCb,AA9CT,AAcY,0BAdc,CACtB,yBAAyB,CAQrB,kBAAkB,CAKd,aAAa,AAAC,CACV,OAAO,CAAE,KAAK,CACd,UAAU,CAAE,IAAI,CAChB,aAAa,CAAE,GAAG,CAClB,MAAM,CAAE,GAAG,CAAC,KAAK,CAAC,eAAe,CACjC,UAAU,CAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,eAAe,CACrC,OAAO,CAAE,SAAS,CAClB,WAAW,CAAE,MAAM,CACnB,WAAW,CAAE,IAAI,CACjB,KAAK,CAAE,OAAO,CACd,WAAW,CAAE,YAAY,CACzB,eAAe,CAAE,IAAI,CACrB,QAAQ,CAAE,QAAQ,CAClB,SAAS,CAAE,KAAK,CAkBnB,AA7Cb,AA6BgB,0BA7BU,CACtB,yBAAyB,CAQrB,kBAAkB,CAKd,aAAa,AAeR,MAAM,AAAC,CACJ,KAAK,CAAE,OAAO,CACd,gBAAgB,CAAE,OAAO,CAC5B,AAhCjB,AAiCgB,0BAjCU,CACtB,yBAAyB,CAQrB,kBAAkB,CAKd,aAAa,AAmBR,OAAO,CAAC,EAAE,AAAC,CACR,WAAW,CAAE,GAAG,CAChB,UAAU,CAAE,MAAM,CASrB,AA5CjB,AAqCoB,0BArCM,CACtB,yBAAyB,CAQrB,kBAAkB,CAKd,aAAa,AAmBR,OAAO,CAAC,EAAE,CAIP,CAAC,AAAC,CACE,KAAK,CAAE,OAAO,CAKjB,AA3CrB,AAwCwB,0BAxCE,CACtB,yBAAyB,CAQrB,kBAAkB,CAKd,aAAa,AAmBR,OAAO,CAAC,EAAE,CAIP,CAAC,CAGK,CAAC,AAAC,CACA,KAAK,CAAE,OACX,CAAC,AAQzB,AAAA,MAAM,CAAC,WAAW,AAAC,CACf,KAAK,CAAE,GAAG,CAoBb,AArBD,AAEI,MAFE,CAAC,WAAW,CAEd,IAAI,AAAC,CACD,OAAO,CAAE,GAAG,CACZ,MAAM,CAAE,IAAI,CACf,AALL,AAMI,MANE,CAAC,WAAW,CAMd,MAAM,AAAC,CACH,OAAO,CAAE,WAAW,CACpB,WAAW,CAAE,GAAG,CAChB,SAAS,CAAE,KAAK,CAChB,MAAM,CAAE,eAAe,CACvB,OAAO,CAAE,YAAY,CACrB,UAAU,CAAE,WAAW,CAQ1B,AApBL,AAcQ,MAdF,CAAC,WAAW,CAMd,MAAM,AAQD,KAAK,AAAC,CACH,MAAM,CAAE,iBAAiB,CAI5B,AAnBT,AAgBY,MAhBN,CAAC,WAAW,CAMd,MAAM,AAQD,KAAK,AAED,MAAM,AAAC,CACJ,YAAY,CAAE,OAAO,CACxB",
|
4 |
+
"sources": [
|
5 |
+
"admin.scss"
|
6 |
+
],
|
7 |
+
"names": [],
|
8 |
+
"file": "admin.min.css"
|
9 |
+
}
|
assets/css/admin.scss
CHANGED
@@ -31,33 +31,29 @@
|
|
31 |
color: #6796a9;
|
32 |
background-color: #c2edff;
|
33 |
}
|
|
|
|
|
|
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
display: inline-block;
|
43 |
-
position: absolute;
|
44 |
-
right: 15px;
|
45 |
-
top: 0;
|
46 |
-
bottom: 0;
|
47 |
}
|
48 |
}
|
49 |
}
|
50 |
}
|
51 |
}
|
|
|
52 |
.fixed .column-hfc {
|
53 |
width: 14%;
|
54 |
.n-a {
|
55 |
opacity: 0.5;
|
56 |
cursor: help;
|
57 |
}
|
58 |
-
// .label {
|
59 |
-
// cursor: pointer;
|
60 |
-
// }
|
61 |
.badge {
|
62 |
padding: .1rem .5rem;
|
63 |
font-weight: 600;
|
31 |
color: #6796a9;
|
32 |
background-color: #c2edff;
|
33 |
}
|
34 |
+
&.paypal em {
|
35 |
+
font-weight: 500;
|
36 |
+
font-style: italic;
|
37 |
|
38 |
+
i {
|
39 |
+
color: #003087;
|
40 |
+
|
41 |
+
&+i {
|
42 |
+
color: #009cde
|
43 |
+
}
|
44 |
+
}
|
|
|
|
|
|
|
|
|
|
|
45 |
}
|
46 |
}
|
47 |
}
|
48 |
}
|
49 |
}
|
50 |
+
|
51 |
.fixed .column-hfc {
|
52 |
width: 14%;
|
53 |
.n-a {
|
54 |
opacity: 0.5;
|
55 |
cursor: help;
|
56 |
}
|
|
|
|
|
|
|
57 |
.badge {
|
58 |
padding: .1rem .5rem;
|
59 |
font-weight: 600;
|
assets/img/paypal.png
DELETED
Binary file
|
head-footer-code.php
CHANGED
@@ -1,19 +1,24 @@
|
|
1 |
<?php
|
2 |
/**
|
|
|
|
|
3 |
* @link https://urosevic.net/
|
4 |
* @since 1.0.0
|
5 |
* @package Head_Footer_Code
|
6 |
*
|
7 |
-
* @wordpress-plugin
|
8 |
* Plugin Name: Head & Footer Code
|
9 |
* Plugin URI: https://urosevic.net/wordpress/plugins/head-footer-code/
|
10 |
-
* Description: Easy add site-wide
|
11 |
-
* Version: 1.
|
12 |
-
* Author: Aleksandar
|
13 |
* Author URI: https://urosevic.net/
|
14 |
* License: GPLv3
|
15 |
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt
|
16 |
* Text Domain: head-footer-code
|
|
|
|
|
|
|
|
|
17 |
*/
|
18 |
|
19 |
// If this file is called directly, abort.
|
@@ -21,10 +26,10 @@ if ( ! defined( 'WPINC' ) ) {
|
|
21 |
die;
|
22 |
}
|
23 |
|
24 |
-
define( 'WPAU_HEAD_FOOTER_CODE_VER', '1.
|
25 |
-
define( 'WPAU_HEAD_FOOTER_CODE_DB_VER', '
|
26 |
define( 'WPAU_HEAD_FOOTER_CODE_FILE', __FILE__ );
|
27 |
-
define( 'WPAU_HEAD_FOOTER_CODE_DIR', dirname( WPAU_HEAD_FOOTER_CODE_FILE ) . '/');
|
28 |
define( 'WPAU_HEAD_FOOTER_CODE_INC', WPAU_HEAD_FOOTER_CODE_DIR . 'inc/' );
|
29 |
|
30 |
// Load files.
|
1 |
<?php
|
2 |
/**
|
3 |
+
* Head & Footer Code plugin for WordPress
|
4 |
+
*
|
5 |
* @link https://urosevic.net/
|
6 |
* @since 1.0.0
|
7 |
* @package Head_Footer_Code
|
8 |
*
|
|
|
9 |
* Plugin Name: Head & Footer Code
|
10 |
* Plugin URI: https://urosevic.net/wordpress/plugins/head-footer-code/
|
11 |
+
* Description: Easy add site-wide, category or article specific custom code before the closing <strong></head></strong> and <strong></body></strong> or after opening <strong><body></strong> HTML tag.
|
12 |
+
* Version: 1.3.0
|
13 |
+
* Author: Aleksandar Urošević
|
14 |
* Author URI: https://urosevic.net/
|
15 |
* License: GPLv3
|
16 |
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt
|
17 |
* Text Domain: head-footer-code
|
18 |
+
* Domain Path: /languages
|
19 |
+
* Requires at elast: 4.9
|
20 |
+
* Tested up to: 6.0
|
21 |
+
* Requires PHP: 5.6
|
22 |
*/
|
23 |
|
24 |
// If this file is called directly, abort.
|
26 |
die;
|
27 |
}
|
28 |
|
29 |
+
define( 'WPAU_HEAD_FOOTER_CODE_VER', '1.3.0' );
|
30 |
+
define( 'WPAU_HEAD_FOOTER_CODE_DB_VER', '7' );
|
31 |
define( 'WPAU_HEAD_FOOTER_CODE_FILE', __FILE__ );
|
32 |
+
define( 'WPAU_HEAD_FOOTER_CODE_DIR', dirname( WPAU_HEAD_FOOTER_CODE_FILE ) . '/' );
|
33 |
define( 'WPAU_HEAD_FOOTER_CODE_INC', WPAU_HEAD_FOOTER_CODE_DIR . 'inc/' );
|
34 |
|
35 |
// Load files.
|
inc/auhfc-category-meta-box.php
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Routine to handle Category metabox for Head & Footer Code
|
4 |
+
*
|
5 |
+
* @package Head_Footer_Code
|
6 |
+
* @since 1.3.0
|
7 |
+
*/
|
8 |
+
|
9 |
+
// Inject Head & Footer Code to Category Edit form.
|
10 |
+
add_action( 'category_edit_form', 'auhfc_category_form_fields', 10, 1 );
|
11 |
+
|
12 |
+
// Save changes when a category is updated/edited.
|
13 |
+
add_action( 'edit_category', 'auhfc_category_save', 10, 1 );
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Function to render Category metabox fields for Head & Footer Code
|
17 |
+
*
|
18 |
+
* @param object $term_object Taxonomy term object.
|
19 |
+
*/
|
20 |
+
function auhfc_category_form_fields( $term_object ) {
|
21 |
+
// Get existing HFC meta for known Category or use defaults.
|
22 |
+
if ( ! empty( $term_object->term_id ) ) {
|
23 |
+
$auhfc = get_term_meta( $term_object->term_id, '_auhfc', true );
|
24 |
+
} else {
|
25 |
+
$auhfc = array(
|
26 |
+
'init' => 'default',
|
27 |
+
'behavior' => 'append',
|
28 |
+
'head' => '',
|
29 |
+
'body' => '',
|
30 |
+
'footer' => '',
|
31 |
+
);
|
32 |
+
}
|
33 |
+
?>
|
34 |
+
<h2><?php esc_html_e( 'Head & Footer Code', 'head-footer-code' ); ?></h2>
|
35 |
+
<p>
|
36 |
+
<?php
|
37 |
+
printf(
|
38 |
+
/* translators: 1: </head>, 2: <body>, 3 </body>, 4: link to Head & Footer Code Settings page */
|
39 |
+
esc_html__( 'Here you can insert category specific code for Head (before the %1$s), Body (after the %2$s) and Footer (before the %3$s) sections. They work in exactly the same way as site-wide code, which you can configure under %5$s. Please note, if you leave empty any of category-specific fields and choose replace behavior, site-wide code will not be removed until you add empty space or empty HTML comment %4$s here.', 'head-footer-code' ),
|
40 |
+
'<code></head></code>',
|
41 |
+
'<code><body></code>',
|
42 |
+
'<code></body></code>',
|
43 |
+
'<code><!-- --></code>',
|
44 |
+
sprintf(
|
45 |
+
'<a href="tools.php?page=head_footer_code">%s</a>',
|
46 |
+
esc_html__( 'Tools / Head & Footer Code', 'head-footer-code' )
|
47 |
+
)
|
48 |
+
);
|
49 |
+
?>
|
50 |
+
</p>
|
51 |
+
|
52 |
+
<table class="form-table" role="presentation">
|
53 |
+
<tbody>
|
54 |
+
<tr class="form-field term-auhfc-behavior">
|
55 |
+
<th scope="row">
|
56 |
+
<label for="auhfc_behavior"><?php esc_html_e( 'Behavior', 'head-footer-code' ); ?></label>
|
57 |
+
</th>
|
58 |
+
<td>
|
59 |
+
<select name="auhfc[behavior]" id="auhfc_behavior">
|
60 |
+
<option value="append" <?php echo ( ! empty( $auhfc['behavior'] ) && 'append' === $auhfc['behavior'] ) ? 'selected' : ''; ?>><?php esc_html_e( 'Append to the site-wide code', 'head-footer-code' ); ?></option>
|
61 |
+
<option value="replace" <?php echo ( ! empty( $auhfc['behavior'] ) && 'replace' === $auhfc['behavior'] ) ? 'selected' : ''; ?>><?php esc_html_e( 'Replace the site-wide code', 'head-footer-code' ); ?></option>
|
62 |
+
</select>
|
63 |
+
</td>
|
64 |
+
</tr>
|
65 |
+
|
66 |
+
<tr class="form-field term-auhfc-head">
|
67 |
+
<th scope="row">
|
68 |
+
<label for="auhfc_head"><?php esc_html_e( 'Head Code', 'head-footer-code' ); ?></label>
|
69 |
+
</th>
|
70 |
+
<td>
|
71 |
+
<textarea name="auhfc[head]" id="auhfc_head" class="widefat code" rows="5"><?php echo ! empty( $auhfc['head'] ) ? $auhfc['head'] : ''; ?></textarea>
|
72 |
+
<p class="description"><?php esc_html_e( 'Example', 'head-footer-code' ); ?>: <code><link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/style.css" type="text/css" media="all"></code></p>
|
73 |
+
</td>
|
74 |
+
</tr>
|
75 |
+
<tr class="form-field term-auhfc-body">
|
76 |
+
<th scope="row">
|
77 |
+
<label for="auhfc_body"><?php esc_html_e( 'Body Code', 'head-footer-code' ); ?></label>
|
78 |
+
</th>
|
79 |
+
<td>
|
80 |
+
<textarea name="auhfc[body]" id="auhfc_body" class="widefat code" rows="5"><?php echo ! empty( $auhfc['body'] ) ? $auhfc['body'] : ''; ?></textarea>
|
81 |
+
<p class="description"><?php esc_html_e( 'Example', 'head-footer-code' ); ?>: <code><script type="text/javascript" src="<?php echo get_stylesheet_directory_uri(); ?>/body-start.js" type="text/css" media="all"></script></code></p>
|
82 |
+
</td>
|
83 |
+
</tr>
|
84 |
+
<tr class="form-field term-auhfc-footer">
|
85 |
+
<th scope="row">
|
86 |
+
<label for="auhfc_footer"><?php esc_html_e( 'Footer Code', 'head-footer-code' ); ?></label>
|
87 |
+
</th>
|
88 |
+
<td>
|
89 |
+
<textarea name="auhfc[footer]" id="auhfc_footer" class="widefat code" rows="5"><?php echo ! empty( $auhfc['footer'] ) ? $auhfc['footer'] : ''; ?></textarea>
|
90 |
+
<p class="description"><?php esc_html_e( 'Example', 'head-footer-code' ); ?>: <code><script type="text/javascript" src="<?php echo get_stylesheet_directory_uri(); ?>/script.js"></script></code></p>
|
91 |
+
</td>
|
92 |
+
</tr>
|
93 |
+
</tbody>
|
94 |
+
</table>
|
95 |
+
|
96 |
+
<?php
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Function to update category meta
|
101 |
+
*/
|
102 |
+
function auhfc_category_save() {
|
103 |
+
// Escape if our value is ot present in $_POST array.
|
104 |
+
if ( empty( $_POST['auhfc'] ) || ! current_user_can( 'manage_categories' ) ) {
|
105 |
+
return null;
|
106 |
+
}
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Save category metabox form values using update_term_meta()
|
110 |
+
* https://developer.wordpress.org/reference/functions/update_term_meta/
|
111 |
+
*
|
112 |
+
* The term_id of Category is provided in $_POST key `tag_ID`
|
113 |
+
*/
|
114 |
+
update_term_meta( $_POST['tag_ID'], '_auhfc', $_POST['auhfc'] );
|
115 |
+
}
|
inc/class-auhfc-meta-box.php
CHANGED
@@ -1,9 +1,18 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
// If this file is called directly, abort.
|
3 |
if ( ! defined( 'WPINC' ) ) {
|
4 |
die;
|
5 |
}
|
6 |
|
|
|
|
|
|
|
7 |
abstract class AUHfc_Meta_Box {
|
8 |
|
9 |
/**
|
@@ -20,7 +29,7 @@ abstract class AUHfc_Meta_Box {
|
|
20 |
add_meta_box(
|
21 |
'auhfc-head-footer-code',
|
22 |
esc_html__( 'Head & Footer Code', 'head-footer-code' ),
|
23 |
-
|
24 |
$post_type,
|
25 |
'normal',
|
26 |
'low'
|
@@ -32,7 +41,7 @@ abstract class AUHfc_Meta_Box {
|
|
32 |
/**
|
33 |
* Save meta box content.
|
34 |
*
|
35 |
-
* @param int $post_id Post ID
|
36 |
*/
|
37 |
public static function save( $post_id ) {
|
38 |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
@@ -61,25 +70,25 @@ abstract class AUHfc_Meta_Box {
|
|
61 |
|
62 |
/**
|
63 |
* Meta box display callback.
|
64 |
-
*
|
65 |
-
* @param WP_Post $post Current post object.
|
66 |
*/
|
67 |
-
public static function html(
|
68 |
wp_nonce_field( '_head_footer_code_nonce', 'head_footer_code_nonce' ); ?>
|
69 |
-
<p
|
|
|
70 |
printf(
|
71 |
-
/* translators:
|
72 |
-
%2$s will be
|
73 |
-
%3$s will be replaced with preformatted HTML tag </body>
|
74 |
-
%4$s will be replaced with a link to Head & Footer Code Settings page */
|
75 |
-
esc_html__( 'Here you can insert article specific code for Head (before the %1$s), Body (after the %2$s) and Footer (before the %3$s) sections. They work in exactly the same way as site-wide code, which you can configure under %4$s.', 'head-footer-code'),
|
76 |
'<code></head></code>',
|
77 |
'<code><body></code>',
|
78 |
'<code></body></code>',
|
79 |
-
|
|
|
|
|
|
|
80 |
)
|
81 |
);
|
82 |
-
|
|
|
83 |
<label><?php esc_html_e( 'Behavior', 'head-footer-code' ); ?></label><br />
|
84 |
<select name="auhfc[behavior]" id="auhfc_behavior">
|
85 |
<option value="append" <?php echo ( 'append' === auhfc_get_meta( 'behavior' ) ) ? 'selected' : ''; ?>><?php esc_html_e( 'Append to the site-wide code', 'head-footer-code' ); ?></option>
|
@@ -88,15 +97,15 @@ abstract class AUHfc_Meta_Box {
|
|
88 |
<br /><br />
|
89 |
<label for="auhfc_head"><?php esc_html_e( 'Head Code', 'head-footer-code' ); ?></label><br />
|
90 |
<textarea name="auhfc[head]" id="auhfc_head" class="widefat code" rows="5"><?php echo auhfc_get_meta( 'head' ); ?></textarea>
|
91 |
-
<p class="description"><?php esc_html_e( 'Example', 'head-footer-code'); ?>: <code><link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/style.css" type="text/css" media="all"></code></p>
|
92 |
<br />
|
93 |
<label for="auhfc_body"><?php esc_html_e( 'Body Code', 'head-footer-code' ); ?></label><br />
|
94 |
<textarea name="auhfc[body]" id="auhfc_body" class="widefat code" rows="5"><?php echo auhfc_get_meta( 'body' ); ?></textarea>
|
95 |
-
<p class="description"><?php esc_html_e( 'Example', 'head-footer-code'); ?>: <code><script type="text/javascript" src="<?php echo get_stylesheet_directory_uri(); ?>/body-start.js" type="text/css" media="all"></script></code></p>
|
96 |
<br />
|
97 |
<label for="auhfc_footer"><?php esc_html_e( 'Footer Code', 'head-footer-code' ); ?></label><br />
|
98 |
<textarea name="auhfc[footer]" id="auhfc_footer" class="widefat code" rows="5"><?php echo auhfc_get_meta( 'footer' ); ?></textarea>
|
99 |
-
<p class="description"><?php esc_html_e( 'Example', 'head-footer-code'); ?>: <code><script type="text/javascript" src="<?php echo get_stylesheet_directory_uri(); ?>/script.js"></script></code></p>
|
100 |
<?php
|
101 |
} // END public static function html()
|
102 |
|
@@ -106,8 +115,8 @@ abstract class AUHfc_Meta_Box {
|
|
106 |
* Initialize metabox on proper backend screens
|
107 |
*/
|
108 |
function auhfc_init_meta_boxes() {
|
109 |
-
add_action( 'add_meta_boxes',
|
110 |
-
add_action( 'save_post',
|
111 |
}
|
112 |
if ( is_admin() ) {
|
113 |
add_action( 'load-post.php', 'auhfc_init_meta_boxes' );
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Class for Head & Footer Code article metabox
|
4 |
+
*
|
5 |
+
* @package Head_Footer_Code
|
6 |
+
*/
|
7 |
+
|
8 |
// If this file is called directly, abort.
|
9 |
if ( ! defined( 'WPINC' ) ) {
|
10 |
die;
|
11 |
}
|
12 |
|
13 |
+
/**
|
14 |
+
* Class to compose Head & Footer article metabox
|
15 |
+
*/
|
16 |
abstract class AUHfc_Meta_Box {
|
17 |
|
18 |
/**
|
29 |
add_meta_box(
|
30 |
'auhfc-head-footer-code',
|
31 |
esc_html__( 'Head & Footer Code', 'head-footer-code' ),
|
32 |
+
array( self::class, 'html' ),
|
33 |
$post_type,
|
34 |
'normal',
|
35 |
'low'
|
41 |
/**
|
42 |
* Save meta box content.
|
43 |
*
|
44 |
+
* @param int $post_id Post ID.
|
45 |
*/
|
46 |
public static function save( $post_id ) {
|
47 |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
70 |
|
71 |
/**
|
72 |
* Meta box display callback.
|
|
|
|
|
73 |
*/
|
74 |
+
public static function html() {
|
75 |
wp_nonce_field( '_head_footer_code_nonce', 'head_footer_code_nonce' ); ?>
|
76 |
+
<p>
|
77 |
+
<?php
|
78 |
printf(
|
79 |
+
/* translators: 1: </head>, 2: <body>, 3: </body>, 4 link to Head & Footer Code Settings page */
|
80 |
+
esc_html__( 'Here you can insert article specific code for Head (before the %1$s), Body (after the %2$s) and Footer (before the %3$s) sections. They work in exactly the same way as site-wide code, which you can configure under %5$s. Please note, if you leave empty any of article-specific fields and choose replace behavior, site-wide code will not be removed until you add empty space or empty HTML comment %4$s here.', 'head-footer-code' ),
|
|
|
|
|
|
|
81 |
'<code></head></code>',
|
82 |
'<code><body></code>',
|
83 |
'<code></body></code>',
|
84 |
+
'<code><!-- --></code>',
|
85 |
+
sprintf(
|
86 |
+
'<a href="tools.php?page=head_footer_code">%s</a>',
|
87 |
+
esc_html__( 'Tools / Head & Footer Code', 'head-footer-code' )
|
88 |
)
|
89 |
);
|
90 |
+
?>
|
91 |
+
</p>
|
92 |
<label><?php esc_html_e( 'Behavior', 'head-footer-code' ); ?></label><br />
|
93 |
<select name="auhfc[behavior]" id="auhfc_behavior">
|
94 |
<option value="append" <?php echo ( 'append' === auhfc_get_meta( 'behavior' ) ) ? 'selected' : ''; ?>><?php esc_html_e( 'Append to the site-wide code', 'head-footer-code' ); ?></option>
|
97 |
<br /><br />
|
98 |
<label for="auhfc_head"><?php esc_html_e( 'Head Code', 'head-footer-code' ); ?></label><br />
|
99 |
<textarea name="auhfc[head]" id="auhfc_head" class="widefat code" rows="5"><?php echo auhfc_get_meta( 'head' ); ?></textarea>
|
100 |
+
<p class="description"><?php esc_html_e( 'Example', 'head-footer-code' ); ?>: <code><link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/style.css" type="text/css" media="all"></code></p>
|
101 |
<br />
|
102 |
<label for="auhfc_body"><?php esc_html_e( 'Body Code', 'head-footer-code' ); ?></label><br />
|
103 |
<textarea name="auhfc[body]" id="auhfc_body" class="widefat code" rows="5"><?php echo auhfc_get_meta( 'body' ); ?></textarea>
|
104 |
+
<p class="description"><?php esc_html_e( 'Example', 'head-footer-code' ); ?>: <code><script type="text/javascript" src="<?php echo get_stylesheet_directory_uri(); ?>/body-start.js" type="text/css" media="all"></script></code></p>
|
105 |
<br />
|
106 |
<label for="auhfc_footer"><?php esc_html_e( 'Footer Code', 'head-footer-code' ); ?></label><br />
|
107 |
<textarea name="auhfc[footer]" id="auhfc_footer" class="widefat code" rows="5"><?php echo auhfc_get_meta( 'footer' ); ?></textarea>
|
108 |
+
<p class="description"><?php esc_html_e( 'Example', 'head-footer-code' ); ?>: <code><script type="text/javascript" src="<?php echo get_stylesheet_directory_uri(); ?>/script.js"></script></code></p>
|
109 |
<?php
|
110 |
} // END public static function html()
|
111 |
|
115 |
* Initialize metabox on proper backend screens
|
116 |
*/
|
117 |
function auhfc_init_meta_boxes() {
|
118 |
+
add_action( 'add_meta_boxes', array( 'AUHfc_Meta_Box', 'add' ) );
|
119 |
+
add_action( 'save_post', array( 'AUHfc_Meta_Box', 'save' ) );
|
120 |
}
|
121 |
if ( is_admin() ) {
|
122 |
add_action( 'load-post.php', 'auhfc_init_meta_boxes' );
|
inc/front.php
CHANGED
@@ -1,4 +1,10 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
// If this file is called directly, abort.
|
3 |
if ( ! defined( 'WPINC' ) ) {
|
4 |
die;
|
@@ -8,7 +14,6 @@ if ( ! defined( 'WPINC' ) ) {
|
|
8 |
* Inject site-wide code to head, body and footer with custom priorty.
|
9 |
*/
|
10 |
$auhfc_settings = auhfc_settings();
|
11 |
-
|
12 |
if ( empty( $auhfc_settings['sitewide']['priority_h'] ) ) {
|
13 |
$auhfc_settings['sitewide']['priority_h'] = 10;
|
14 |
}
|
@@ -18,7 +23,8 @@ if ( empty( $auhfc_settings['sitewide']['priority_b'] ) ) {
|
|
18 |
if ( empty( $auhfc_settings['sitewide']['priority_f'] ) ) {
|
19 |
$auhfc_settings['sitewide']['priority_f'] = 10;
|
20 |
}
|
21 |
-
|
|
|
22 |
add_action( 'wp_head', 'auhfc_wp_head', $auhfc_settings['sitewide']['priority_h'] );
|
23 |
add_action( 'wp_body_open', 'auhfc_wp_body', $auhfc_settings['sitewide']['priority_b'] );
|
24 |
add_action( 'wp_footer', 'auhfc_wp_footer', $auhfc_settings['sitewide']['priority_f'] );
|
@@ -28,34 +34,39 @@ add_action( 'wp_footer', 'auhfc_wp_footer', $auhfc_settings['sitewide']['priorit
|
|
28 |
*/
|
29 |
function auhfc_wp_head() {
|
30 |
|
31 |
-
// Get post type.
|
32 |
-
$auhfc_post_type = auhfc_get_post_type();
|
33 |
-
|
34 |
// Get variables to test.
|
35 |
$auhfc_settings = auhfc_settings();
|
|
|
36 |
$is_homepage_blog_posts = auhfc_is_homepage_blog_posts();
|
37 |
-
$
|
38 |
-
$
|
39 |
|
40 |
// Get meta for post only if it's singular.
|
41 |
-
if ( 'not singular' !== $auhfc_post_type && in_array( $auhfc_post_type, $auhfc_settings['article']['post_types'] ) ) {
|
42 |
-
$
|
43 |
-
$
|
44 |
-
$dbg_set
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
} else {
|
46 |
-
$
|
47 |
-
$article_behavior = '';
|
48 |
-
$dbg_set = $auhfc_post_type;
|
49 |
// Get meta for homepage.
|
50 |
if ( $is_homepage_blog_posts ) {
|
51 |
-
$
|
52 |
-
$
|
53 |
-
$dbg_set
|
54 |
}
|
55 |
}
|
56 |
|
57 |
// If no code to inject, simply exit.
|
58 |
-
if ( empty( $auhfc_settings['sitewide']['head'] ) && empty( $
|
59 |
return;
|
60 |
}
|
61 |
|
@@ -65,21 +76,24 @@ function auhfc_wp_head() {
|
|
65 |
// Inject site-wide head code.
|
66 |
if (
|
67 |
! empty( $auhfc_settings['sitewide']['head'] ) &&
|
68 |
-
auhfc_print_sitewide( $
|
69 |
) {
|
70 |
$out .= auhfc_out( 's', 'h', $dbg_set, $auhfc_settings['sitewide']['head'] );
|
71 |
}
|
72 |
|
73 |
-
// Inject head code for Homepage in Blog Posts
|
74 |
-
if (
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
78 |
}
|
79 |
|
80 |
// Print prepared code.
|
81 |
-
echo $out;
|
82 |
-
// echo ( 'y' === $auhfc_settings['sitewide']['do_shortcode'] ) ? do_shortcode( $out ) : $out;
|
83 |
|
84 |
} // END function auhfc_wp_head()
|
85 |
|
@@ -88,34 +102,39 @@ function auhfc_wp_head() {
|
|
88 |
*/
|
89 |
function auhfc_wp_body() {
|
90 |
|
91 |
-
// Get post type.
|
92 |
-
$auhfc_post_type = auhfc_get_post_type();
|
93 |
-
|
94 |
// Get variables to test.
|
95 |
$auhfc_settings = auhfc_settings();
|
|
|
96 |
$is_homepage_blog_posts = auhfc_is_homepage_blog_posts();
|
97 |
-
$
|
98 |
-
$
|
99 |
|
100 |
// Get meta for post only if it's singular.
|
101 |
-
if ( 'not singular' !== $auhfc_post_type && in_array( $auhfc_post_type, $auhfc_settings['article']['post_types'] ) ) {
|
102 |
-
$
|
103 |
-
$
|
104 |
-
$dbg_set
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
} else {
|
106 |
-
$
|
107 |
-
$article_behavior = '';
|
108 |
-
$dbg_set = $auhfc_post_type;
|
109 |
// Get meta for homepage.
|
110 |
if ( $is_homepage_blog_posts ) {
|
111 |
-
$
|
112 |
-
$
|
113 |
-
$dbg_set
|
114 |
}
|
115 |
}
|
116 |
|
117 |
// If no code to inject, simple exit.
|
118 |
-
if ( empty( $auhfc_settings['sitewide']['body'] ) && empty( $
|
119 |
return;
|
120 |
}
|
121 |
|
@@ -125,21 +144,24 @@ function auhfc_wp_body() {
|
|
125 |
// Inject site-wide body code.
|
126 |
if (
|
127 |
! empty( $auhfc_settings['sitewide']['body'] ) &&
|
128 |
-
auhfc_print_sitewide( $
|
129 |
) {
|
130 |
$out .= auhfc_out( 's', 'b', $dbg_set, $auhfc_settings['sitewide']['body'] );
|
131 |
}
|
132 |
|
133 |
-
// Inject
|
134 |
-
if (
|
135 |
-
|
136 |
-
|
137 |
-
|
|
|
|
|
|
|
|
|
138 |
}
|
139 |
|
140 |
// Print prepared code.
|
141 |
-
echo $out;
|
142 |
-
// echo ( 'y' === $auhfc_settings['sitewide']['do_shortcode'] ) ? do_shortcode( $out ) : $out;
|
143 |
|
144 |
} // END function auhfc_wp_body()
|
145 |
|
@@ -148,57 +170,66 @@ function auhfc_wp_body() {
|
|
148 |
*/
|
149 |
function auhfc_wp_footer() {
|
150 |
|
151 |
-
// Get post type.
|
152 |
-
$auhfc_post_type = auhfc_get_post_type();
|
153 |
-
|
154 |
// Get variables to test.
|
155 |
$auhfc_settings = auhfc_settings();
|
|
|
156 |
$is_homepage_blog_posts = auhfc_is_homepage_blog_posts();
|
157 |
-
$
|
158 |
-
$
|
159 |
|
160 |
// Get meta for post only if it's singular.
|
161 |
-
if ( 'not singular' !== $auhfc_post_type && in_array( $auhfc_post_type, $auhfc_settings['article']['post_types'] ) ) {
|
162 |
-
$
|
163 |
-
$
|
164 |
-
$dbg_set
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
} else {
|
166 |
-
$
|
167 |
-
$article_behavior = '';
|
168 |
-
$dbg_set = $auhfc_post_type;
|
169 |
// Get meta for homepage.
|
170 |
if ( $is_homepage_blog_posts ) {
|
171 |
-
$
|
172 |
-
$
|
173 |
-
$dbg_set
|
174 |
}
|
175 |
}
|
176 |
|
177 |
// If no code to inject, simple exit.
|
178 |
-
if ( empty( $auhfc_settings['sitewide']['footer'] ) && empty( $
|
179 |
return;
|
180 |
}
|
181 |
|
182 |
// Prepare code output.
|
183 |
$out = '';
|
184 |
|
185 |
-
// Inject site-wide
|
186 |
if (
|
187 |
! empty( $auhfc_settings['sitewide']['footer'] ) &&
|
188 |
-
auhfc_print_sitewide( $
|
189 |
) {
|
190 |
$out .= auhfc_out( 's', 'f', $dbg_set, $auhfc_settings['sitewide']['footer'] );
|
191 |
}
|
192 |
|
193 |
-
// Inject
|
194 |
-
if (
|
195 |
-
|
196 |
-
|
197 |
-
|
|
|
|
|
|
|
|
|
198 |
}
|
199 |
|
200 |
// Print prepared code.
|
201 |
-
echo ( 'y' === $auhfc_settings['sitewide']['
|
202 |
|
203 |
} // END function auhfc_wp_footer()
|
204 |
|
@@ -206,6 +237,9 @@ function auhfc_wp_footer() {
|
|
206 |
* Add `wp_body_open` backward compatibility for WordPress installations prior 5.2
|
207 |
*/
|
208 |
if ( ! function_exists( 'wp_body_open' ) ) {
|
|
|
|
|
|
|
209 |
function wp_body_open() {
|
210 |
do_action( 'wp_body_open' );
|
211 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Frontend magic for Head & Footer Code
|
4 |
+
*
|
5 |
+
* @package Head_Footer_Code
|
6 |
+
*/
|
7 |
+
|
8 |
// If this file is called directly, abort.
|
9 |
if ( ! defined( 'WPINC' ) ) {
|
10 |
die;
|
14 |
* Inject site-wide code to head, body and footer with custom priorty.
|
15 |
*/
|
16 |
$auhfc_settings = auhfc_settings();
|
|
|
17 |
if ( empty( $auhfc_settings['sitewide']['priority_h'] ) ) {
|
18 |
$auhfc_settings['sitewide']['priority_h'] = 10;
|
19 |
}
|
23 |
if ( empty( $auhfc_settings['sitewide']['priority_f'] ) ) {
|
24 |
$auhfc_settings['sitewide']['priority_f'] = 10;
|
25 |
}
|
26 |
+
|
27 |
+
// Define actions for HEAD and FOOTER.
|
28 |
add_action( 'wp_head', 'auhfc_wp_head', $auhfc_settings['sitewide']['priority_h'] );
|
29 |
add_action( 'wp_body_open', 'auhfc_wp_body', $auhfc_settings['sitewide']['priority_b'] );
|
30 |
add_action( 'wp_footer', 'auhfc_wp_footer', $auhfc_settings['sitewide']['priority_f'] );
|
34 |
*/
|
35 |
function auhfc_wp_head() {
|
36 |
|
|
|
|
|
|
|
37 |
// Get variables to test.
|
38 |
$auhfc_settings = auhfc_settings();
|
39 |
+
$auhfc_post_type = auhfc_get_post_type();
|
40 |
$is_homepage_blog_posts = auhfc_is_homepage_blog_posts();
|
41 |
+
$head_behavior = 'none';
|
42 |
+
$head_code = '';
|
43 |
|
44 |
// Get meta for post only if it's singular.
|
45 |
+
if ( 'not singular' !== $auhfc_post_type && in_array( $auhfc_post_type, $auhfc_settings['article']['post_types'], true ) ) {
|
46 |
+
$head_behavior = auhfc_get_meta( 'behavior' );
|
47 |
+
$head_code = auhfc_get_meta( 'head' );
|
48 |
+
$dbg_set = "type: {$auhfc_post_type}; bahavior: {$head_behavior}; priority: {$auhfc_settings['sitewide']['priority_h']}; do_shortcode_h: {$auhfc_settings['sitewide']['do_shortcode_h']}";
|
49 |
+
} elseif ( is_category() ) {
|
50 |
+
// Get category (term) meta with get_term_meta().
|
51 |
+
$category = get_queried_object();
|
52 |
+
$auhfc_cat = get_term_meta( $category->term_id, '_auhfc', true );
|
53 |
+
if ( ! empty( $auhfc_cat ) ) {
|
54 |
+
$head_behavior = $auhfc_cat['behavior'];
|
55 |
+
$head_code = $auhfc_cat['head'];
|
56 |
+
}
|
57 |
+
$dbg_set = "type: category; bahavior: {$head_behavior}; priority: {$auhfc_settings['sitewide']['priority_h']}; do_shortcode_h: {$auhfc_settings['sitewide']['do_shortcode_h']}";
|
58 |
} else {
|
59 |
+
$dbg_set = $auhfc_post_type;
|
|
|
|
|
60 |
// Get meta for homepage.
|
61 |
if ( $is_homepage_blog_posts ) {
|
62 |
+
$head_behavior = $auhfc_settings['homepage']['behavior'];
|
63 |
+
$head_code = $auhfc_settings['homepage']['head'];
|
64 |
+
$dbg_set = "type: homepage; bahavior: {$head_behavior}; priority: {$auhfc_settings['sitewide']['priority_h']}; do_shortcode_h: {$auhfc_settings['sitewide']['do_shortcode_h']}";
|
65 |
}
|
66 |
}
|
67 |
|
68 |
// If no code to inject, simply exit.
|
69 |
+
if ( empty( $auhfc_settings['sitewide']['head'] ) && empty( $head_code ) ) {
|
70 |
return;
|
71 |
}
|
72 |
|
76 |
// Inject site-wide head code.
|
77 |
if (
|
78 |
! empty( $auhfc_settings['sitewide']['head'] ) &&
|
79 |
+
auhfc_print_sitewide( $head_behavior, $head_code, $auhfc_post_type, $auhfc_settings['article']['post_types'], is_category() )
|
80 |
) {
|
81 |
$out .= auhfc_out( 's', 'h', $dbg_set, $auhfc_settings['sitewide']['head'] );
|
82 |
}
|
83 |
|
84 |
+
// Inject head code for Homepage in Blog Posts mode OR article specific (for allowed post_type) head code OR category head code.
|
85 |
+
if ( ! empty( $head_code ) ) {
|
86 |
+
if ( $is_homepage_blog_posts ) {
|
87 |
+
$out .= auhfc_out( 'h', 'h', $dbg_set, $head_code );
|
88 |
+
} elseif ( in_array( $auhfc_post_type, $auhfc_settings['article']['post_types'], true ) ) {
|
89 |
+
$out .= auhfc_out( 'a', 'h', $dbg_set, $head_code );
|
90 |
+
} else {
|
91 |
+
$out .= auhfc_out( 'c', 'h', $dbg_set, $head_code );
|
92 |
+
}
|
93 |
}
|
94 |
|
95 |
// Print prepared code.
|
96 |
+
echo ( 'y' === $auhfc_settings['sitewide']['do_shortcode_h'] ) ? do_shortcode( $out ) : $out;
|
|
|
97 |
|
98 |
} // END function auhfc_wp_head()
|
99 |
|
102 |
*/
|
103 |
function auhfc_wp_body() {
|
104 |
|
|
|
|
|
|
|
105 |
// Get variables to test.
|
106 |
$auhfc_settings = auhfc_settings();
|
107 |
+
$auhfc_post_type = auhfc_get_post_type();
|
108 |
$is_homepage_blog_posts = auhfc_is_homepage_blog_posts();
|
109 |
+
$body_behavior = 'none';
|
110 |
+
$body_code = '';
|
111 |
|
112 |
// Get meta for post only if it's singular.
|
113 |
+
if ( 'not singular' !== $auhfc_post_type && in_array( $auhfc_post_type, $auhfc_settings['article']['post_types'], true ) ) {
|
114 |
+
$body_behavior = auhfc_get_meta( 'behavior' );
|
115 |
+
$body_code = auhfc_get_meta( 'body' );
|
116 |
+
$dbg_set = "type: {$auhfc_post_type}; bahavior: {$body_behavior}; priority: {$auhfc_settings['sitewide']['priority_b']}; do_shortcode_b: {$auhfc_settings['sitewide']['do_shortcode_b']}";
|
117 |
+
} elseif ( is_category() ) {
|
118 |
+
// Get category (term) meta with get_term_meta().
|
119 |
+
$category = get_queried_object();
|
120 |
+
$auhfc_cat = get_term_meta( $category->term_id, '_auhfc', true );
|
121 |
+
if ( ! empty( $auhfc_cat ) ) {
|
122 |
+
$body_behavior = $auhfc_cat['behavior'];
|
123 |
+
$body_code = $auhfc_cat['body'];
|
124 |
+
}
|
125 |
+
$dbg_set = "type: category; bahavior: {$body_behavior}; priority: {$auhfc_settings['sitewide']['priority_b']}; do_shortcode_b: {$auhfc_settings['sitewide']['do_shortcode_b']}";
|
126 |
} else {
|
127 |
+
$dbg_set = $auhfc_post_type;
|
|
|
|
|
128 |
// Get meta for homepage.
|
129 |
if ( $is_homepage_blog_posts ) {
|
130 |
+
$body_behavior = $auhfc_settings['homepage']['behavior'];
|
131 |
+
$body_code = $auhfc_settings['homepage']['body'];
|
132 |
+
$dbg_set = "type: homepage; bahavior: {$body_behavior}; priority: {$auhfc_settings['sitewide']['priority_b']}; do_shortcode_b: {$auhfc_settings['sitewide']['do_shortcode_b']}";
|
133 |
}
|
134 |
}
|
135 |
|
136 |
// If no code to inject, simple exit.
|
137 |
+
if ( empty( $auhfc_settings['sitewide']['body'] ) && empty( $body_code ) ) {
|
138 |
return;
|
139 |
}
|
140 |
|
144 |
// Inject site-wide body code.
|
145 |
if (
|
146 |
! empty( $auhfc_settings['sitewide']['body'] ) &&
|
147 |
+
auhfc_print_sitewide( $body_behavior, $body_code, $auhfc_post_type, $auhfc_settings['article']['post_types'], is_category() )
|
148 |
) {
|
149 |
$out .= auhfc_out( 's', 'b', $dbg_set, $auhfc_settings['sitewide']['body'] );
|
150 |
}
|
151 |
|
152 |
+
// Inject body code for Homepage in Blog Posts mode OR article specific (for allowed post_type) body code OR category body code.
|
153 |
+
if ( ! empty( $body_code ) ) {
|
154 |
+
if ( $is_homepage_blog_posts ) {
|
155 |
+
$out .= auhfc_out( 'h', 'b', $dbg_set, $body_code );
|
156 |
+
} elseif ( in_array( $auhfc_post_type, $auhfc_settings['article']['post_types'], true ) ) {
|
157 |
+
$out .= auhfc_out( 'a', 'b', $dbg_set, $body_code );
|
158 |
+
} else {
|
159 |
+
$out .= auhfc_out( 'c', 'b', $dbg_set, $body_code );
|
160 |
+
}
|
161 |
}
|
162 |
|
163 |
// Print prepared code.
|
164 |
+
echo ( 'y' === $auhfc_settings['sitewide']['do_shortcode_b'] ) ? do_shortcode( $out ) : $out;
|
|
|
165 |
|
166 |
} // END function auhfc_wp_body()
|
167 |
|
170 |
*/
|
171 |
function auhfc_wp_footer() {
|
172 |
|
|
|
|
|
|
|
173 |
// Get variables to test.
|
174 |
$auhfc_settings = auhfc_settings();
|
175 |
+
$auhfc_post_type = auhfc_get_post_type();
|
176 |
$is_homepage_blog_posts = auhfc_is_homepage_blog_posts();
|
177 |
+
$footer_behavior = 'none';
|
178 |
+
$footer_code = '';
|
179 |
|
180 |
// Get meta for post only if it's singular.
|
181 |
+
if ( 'not singular' !== $auhfc_post_type && in_array( $auhfc_post_type, $auhfc_settings['article']['post_types'], true ) ) {
|
182 |
+
$footer_code = auhfc_get_meta( 'footer' );
|
183 |
+
$footer_behavior = auhfc_get_meta( 'behavior' );
|
184 |
+
$dbg_set = "type: {$auhfc_post_type}; bahavior: {$footer_behavior}; priority: {$auhfc_settings['sitewide']['priority_f']}; do_shortcode_f: {$auhfc_settings['sitewide']['do_shortcode_f']}";
|
185 |
+
} elseif ( is_category() ) {
|
186 |
+
// Get category (term) meta with get_term_meta().
|
187 |
+
$category = get_queried_object();
|
188 |
+
$auhfc_cat = get_term_meta( $category->term_id, '_auhfc', true );
|
189 |
+
if ( ! empty( $auhfc_cat ) ) {
|
190 |
+
$footer_behavior = $auhfc_cat['behavior'];
|
191 |
+
$footer_code = $auhfc_cat['footer'];
|
192 |
+
}
|
193 |
+
$dbg_set = "type: category; bahavior: {$footer_behavior}; priority: {$auhfc_settings['sitewide']['priority_f']}; do_shortcode_f: {$auhfc_settings['sitewide']['do_shortcode_f']}";
|
194 |
} else {
|
195 |
+
$dbg_set = $auhfc_post_type;
|
|
|
|
|
196 |
// Get meta for homepage.
|
197 |
if ( $is_homepage_blog_posts ) {
|
198 |
+
$footer_code = $auhfc_settings['homepage']['footer'];
|
199 |
+
$footer_behavior = $auhfc_settings['homepage']['behavior'];
|
200 |
+
$dbg_set = "type: homepage; bahavior: {$footer_behavior}; priority: {$auhfc_settings['sitewide']['priority_f']}; do_shortcode_f: {$auhfc_settings['sitewide']['do_shortcode_f']}";
|
201 |
}
|
202 |
}
|
203 |
|
204 |
// If no code to inject, simple exit.
|
205 |
+
if ( empty( $auhfc_settings['sitewide']['footer'] ) && empty( $footer_code ) ) {
|
206 |
return;
|
207 |
}
|
208 |
|
209 |
// Prepare code output.
|
210 |
$out = '';
|
211 |
|
212 |
+
// Inject site-wide footer code.
|
213 |
if (
|
214 |
! empty( $auhfc_settings['sitewide']['footer'] ) &&
|
215 |
+
auhfc_print_sitewide( $footer_behavior, $footer_code, $auhfc_post_type, $auhfc_settings['article']['post_types'], is_category() )
|
216 |
) {
|
217 |
$out .= auhfc_out( 's', 'f', $dbg_set, $auhfc_settings['sitewide']['footer'] );
|
218 |
}
|
219 |
|
220 |
+
// Inject footer code for Homepage in Blog Posts mode OR article specific (for allowed post_type) footer code OR category footer code.
|
221 |
+
if ( ! empty( $footer_code ) ) {
|
222 |
+
if ( $is_homepage_blog_posts ) {
|
223 |
+
$out .= auhfc_out( 'h', 'f', $dbg_set, $footer_code );
|
224 |
+
} elseif ( in_array( $auhfc_post_type, $auhfc_settings['article']['post_types'], true ) ) {
|
225 |
+
$out .= auhfc_out( 'a', 'f', $dbg_set, $footer_code );
|
226 |
+
} else {
|
227 |
+
$out .= auhfc_out( 'c', 'f', $dbg_set, $footer_code );
|
228 |
+
}
|
229 |
}
|
230 |
|
231 |
// Print prepared code.
|
232 |
+
echo ( 'y' === $auhfc_settings['sitewide']['do_shortcode_f'] ) ? do_shortcode( $out ) : $out;
|
233 |
|
234 |
} // END function auhfc_wp_footer()
|
235 |
|
237 |
* Add `wp_body_open` backward compatibility for WordPress installations prior 5.2
|
238 |
*/
|
239 |
if ( ! function_exists( 'wp_body_open' ) ) {
|
240 |
+
/**
|
241 |
+
* Fire the wp_body_open action.
|
242 |
+
*/
|
243 |
function wp_body_open() {
|
244 |
do_action( 'wp_body_open' );
|
245 |
}
|
inc/helpers.php
CHANGED
@@ -1,4 +1,10 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
// If this file is called directly, abort.
|
3 |
if ( ! defined( 'WPINC' ) ) {
|
4 |
die;
|
@@ -9,6 +15,7 @@ if ( is_admin() ) {
|
|
9 |
require_once WPAU_HEAD_FOOTER_CODE_INC . 'settings.php';
|
10 |
require_once WPAU_HEAD_FOOTER_CODE_INC . 'posts-custom-columns.php';
|
11 |
require_once WPAU_HEAD_FOOTER_CODE_INC . 'class-auhfc-meta-box.php';
|
|
|
12 |
} else {
|
13 |
require_once WPAU_HEAD_FOOTER_CODE_INC . 'front.php';
|
14 |
}
|
@@ -19,8 +26,8 @@ register_activation_hook( WPAU_HEAD_FOOTER_CODE_FILE, 'auhfc_activate' );
|
|
19 |
*/
|
20 |
function auhfc_activate() {
|
21 |
global $wp_version;
|
22 |
-
$php_req = '5.6'; // Minimum version of PHP required for this plugin
|
23 |
-
$wp_req = '4.9'; // Minimum version of WordPress required for this plugin
|
24 |
|
25 |
if ( version_compare( PHP_VERSION, $php_req, '<' ) ) {
|
26 |
$flag = 'PHP';
|
@@ -29,24 +36,22 @@ function auhfc_activate() {
|
|
29 |
} else {
|
30 |
return;
|
31 |
}
|
32 |
-
$version = 'PHP'
|
33 |
deactivate_plugins( WPAU_HEAD_FOOTER_CODE_FILE );
|
34 |
|
35 |
wp_die(
|
36 |
'<p>' . sprintf(
|
37 |
-
/* translators:
|
38 |
-
%2$s will be replaced with related software name (PHP or WordPress)
|
39 |
-
%3$s will be replaved with minimal version of related software required to plugin work properly */
|
40 |
esc_html__( 'The %1$s plugin requires %2$s version %3$s or greater.', 'head-footer-code' ),
|
41 |
sprintf( '<strong>%s</strong>', esc_html__( 'Head & Footer Code', 'head-footer-code' ) ),
|
42 |
$flag,
|
43 |
$version
|
44 |
) . '</p>',
|
45 |
esc_html__( 'Plugin Activation Error', 'head-footer-code' ),
|
46 |
-
|
47 |
'response' => 200,
|
48 |
'back_link' => true,
|
49 |
-
|
50 |
);
|
51 |
|
52 |
// Trigger updater function.
|
@@ -55,6 +60,9 @@ function auhfc_activate() {
|
|
55 |
|
56 |
// Regular update trigger.
|
57 |
add_action( 'plugins_loaded', 'auhfc_maybe_update' );
|
|
|
|
|
|
|
58 |
function auhfc_maybe_update() {
|
59 |
// Bail if this plugin data doesn't need updating.
|
60 |
if ( get_option( 'auhfc_db_ver' ) >= WPAU_HEAD_FOOTER_CODE_DB_VER ) {
|
@@ -69,21 +77,22 @@ function auhfc_maybe_update() {
|
|
69 |
add_action( 'admin_enqueue_scripts', 'auhfc_admin_enqueue_scripts' );
|
70 |
/**
|
71 |
* Enqueue admin styles and scripts to enable code editor in plugin settings and custom column on article listing
|
72 |
-
*
|
|
|
73 |
*/
|
74 |
function auhfc_admin_enqueue_scripts( $hook ) {
|
75 |
// Admin Stylesheet.
|
76 |
-
if ( in_array( $hook,
|
77 |
wp_enqueue_style(
|
78 |
'head-footer-code-admin',
|
79 |
-
plugin_dir_url( __FILE__ ) . '../assets/css/admin.css',
|
80 |
-
|
81 |
WPAU_HEAD_FOOTER_CODE_VER
|
82 |
);
|
83 |
}
|
84 |
// Codemirror Assets.
|
85 |
if ( 'tools_page_head_footer_code' === $hook ) {
|
86 |
-
$cm_settings['codeEditor'] = wp_enqueue_code_editor(
|
87 |
wp_localize_script( 'code-editor', 'cm_settings', $cm_settings );
|
88 |
wp_enqueue_style( 'wp-codemirror' );
|
89 |
wp_enqueue_script( 'wp-codemirror' );
|
@@ -93,45 +102,49 @@ function auhfc_admin_enqueue_scripts( $hook ) {
|
|
93 |
|
94 |
/**
|
95 |
* Provide global defaults
|
96 |
-
*
|
|
|
97 |
*/
|
98 |
function auhfc_settings() {
|
99 |
|
100 |
-
$defaults
|
101 |
-
'sitewide' =>
|
102 |
-
'head'
|
103 |
-
'body'
|
104 |
-
'footer'
|
105 |
-
'priority_h'
|
106 |
-
'priority_b'
|
107 |
-
'priority_f'
|
108 |
-
'
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
'
|
114 |
-
'
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
|
|
120 |
$auhfc_settings_sitewide = get_option( 'auhfc_settings_sitewide', $defaults['sitewide'] );
|
121 |
-
$defaults['sitewide']
|
122 |
$auhfc_settings_homepage = get_option( 'auhfc_settings_homepage', $defaults['homepage'] );
|
123 |
-
$defaults['homepage']
|
124 |
-
$auhfc_settings_article
|
125 |
-
$defaults['article']
|
126 |
|
127 |
return $defaults;
|
128 |
} // END function auhfc_settings()
|
129 |
|
130 |
/**
|
131 |
* Get values of metabox fields
|
132 |
-
*
|
133 |
-
* @param string $
|
134 |
-
* @
|
|
|
135 |
*/
|
136 |
function auhfc_get_meta( $field_name = '', $post_id = null ) {
|
137 |
|
@@ -139,11 +152,11 @@ function auhfc_get_meta( $field_name = '', $post_id = null ) {
|
|
139 |
return false;
|
140 |
}
|
141 |
|
142 |
-
if ( empty( $post_id ) || $post_id
|
143 |
if ( is_admin() ) {
|
144 |
global $post;
|
145 |
|
146 |
-
// If $post has not an object, return false
|
147 |
if ( empty( $post ) || ! is_object( $post ) ) {
|
148 |
return false;
|
149 |
}
|
@@ -169,7 +182,7 @@ function auhfc_get_meta( $field_name = '', $post_id = null ) {
|
|
169 |
|
170 |
if ( ! empty( $field ) && is_array( $field ) && ! empty( $field[ $field_name ] ) ) {
|
171 |
return stripslashes_deep( $field[ $field_name ] );
|
172 |
-
} elseif ( 'behavior'
|
173 |
return 'append';
|
174 |
} else {
|
175 |
return false;
|
@@ -178,17 +191,18 @@ function auhfc_get_meta( $field_name = '', $post_id = null ) {
|
|
178 |
|
179 |
/**
|
180 |
* Return debugging string if WP_DEBUG constant is true.
|
181 |
-
*
|
182 |
-
* @param string $
|
183 |
-
* @param string $
|
184 |
-
* @param string $
|
185 |
-
* @
|
|
|
186 |
*/
|
187 |
function auhfc_out( $scope = null, $location = null, $message = null, $code = null ) {
|
188 |
if ( ! WP_DEBUG ) {
|
189 |
return $code;
|
190 |
}
|
191 |
-
if ( null
|
192 |
return;
|
193 |
}
|
194 |
switch ( $scope ) {
|
@@ -201,6 +215,9 @@ function auhfc_out( $scope = null, $location = null, $message = null, $code = nu
|
|
201 |
case 'a':
|
202 |
$scope = 'Article specific';
|
203 |
break;
|
|
|
|
|
|
|
204 |
default:
|
205 |
$scope = 'Unknown';
|
206 |
}
|
@@ -228,72 +245,117 @@ function auhfc_out( $scope = null, $location = null, $message = null, $code = nu
|
|
228 |
);
|
229 |
} // END function auhfc_out( $scope = null, $location = null, $message = null, $code = null )
|
230 |
|
|
|
|
|
|
|
231 |
function auhfc_get_post_type() {
|
232 |
$auhfc_post_type = 'not singular';
|
233 |
// Get post type.
|
234 |
if ( is_singular() ) {
|
235 |
global $wp_the_query;
|
236 |
$auhfc_query = $wp_the_query->get_queried_object();
|
237 |
-
if (is_object($auhfc_query)) {
|
238 |
$auhfc_post_type = $auhfc_query->post_type;
|
239 |
}
|
240 |
}
|
241 |
return $auhfc_post_type;
|
242 |
} // END function auhfc_get_post_type()
|
243 |
|
|
|
|
|
|
|
244 |
function auhfc_is_homepage_blog_posts() {
|
245 |
-
if ( is_home() && 'posts'
|
246 |
return true;
|
247 |
}
|
248 |
return false;
|
249 |
} // END function auhfc_is_homepage_blog_posts()
|
250 |
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
esc_html__( 'Usage of this hook should be reserved for output of %1$s like %2$s tags or additional metadata. It should not be used to add arbitrary HTML content to a page that %
|
258 |
'<em>' . esc_html__( 'unseen elements', 'head-footer-code' ) . '</em>',
|
259 |
-
'<em>' . esc_html__( 'could break layouts or lead to unexpected situations', 'head-footer-code' ) . '</em>',
|
260 |
auhfc_html2code( '<script>' ),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
'<a href="https://developer.wordpress.org/reference/hooks/wp_body_open/" target="_hook">wp_body_open</a>'
|
262 |
) . '</p>';
|
263 |
}
|
264 |
|
|
|
|
|
|
|
|
|
|
|
265 |
function auhfc_html2code( $text ) {
|
266 |
return '<code>' . htmlspecialchars( $text ) . '</code>';
|
267 |
} // END function auhfc_html2code( $text )
|
268 |
|
269 |
/**
|
270 |
* Determine should we print site-wide code
|
271 |
-
* or it should be replaced with homepage/article code.
|
272 |
-
*
|
273 |
-
* @param string $
|
274 |
-
* @param
|
275 |
-
* @param string $
|
276 |
-
* @param
|
277 |
-
* @param
|
278 |
-
* @return boolean
|
279 |
*/
|
280 |
function auhfc_print_sitewide(
|
281 |
-
$
|
282 |
-
$
|
283 |
-
$
|
284 |
-
$
|
285 |
-
$
|
286 |
-
$homepage_code = null
|
287 |
) {
|
|
|
|
|
288 |
$is_homepage_blog_posts = auhfc_is_homepage_blog_posts();
|
289 |
-
if (
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
) {
|
296 |
return true;
|
297 |
}
|
|
|
298 |
return false;
|
299 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Various helpers for Head & Footer Code
|
4 |
+
*
|
5 |
+
* @package Head_Footer_Code
|
6 |
+
*/
|
7 |
+
|
8 |
// If this file is called directly, abort.
|
9 |
if ( ! defined( 'WPINC' ) ) {
|
10 |
die;
|
15 |
require_once WPAU_HEAD_FOOTER_CODE_INC . 'settings.php';
|
16 |
require_once WPAU_HEAD_FOOTER_CODE_INC . 'posts-custom-columns.php';
|
17 |
require_once WPAU_HEAD_FOOTER_CODE_INC . 'class-auhfc-meta-box.php';
|
18 |
+
require_once WPAU_HEAD_FOOTER_CODE_INC . 'auhfc-category-meta-box.php';
|
19 |
} else {
|
20 |
require_once WPAU_HEAD_FOOTER_CODE_INC . 'front.php';
|
21 |
}
|
26 |
*/
|
27 |
function auhfc_activate() {
|
28 |
global $wp_version;
|
29 |
+
$php_req = '5.6'; // Minimum version of PHP required for this plugin.
|
30 |
+
$wp_req = '4.9'; // Minimum version of WordPress required for this plugin.
|
31 |
|
32 |
if ( version_compare( PHP_VERSION, $php_req, '<' ) ) {
|
33 |
$flag = 'PHP';
|
36 |
} else {
|
37 |
return;
|
38 |
}
|
39 |
+
$version = 'PHP' === $flag ? $php_req : $wp_req;
|
40 |
deactivate_plugins( WPAU_HEAD_FOOTER_CODE_FILE );
|
41 |
|
42 |
wp_die(
|
43 |
'<p>' . sprintf(
|
44 |
+
/* translators: 1: Head & Footer Code, 2: PHP or WordPress, 3: min version of PHP or WordPress */
|
|
|
|
|
45 |
esc_html__( 'The %1$s plugin requires %2$s version %3$s or greater.', 'head-footer-code' ),
|
46 |
sprintf( '<strong>%s</strong>', esc_html__( 'Head & Footer Code', 'head-footer-code' ) ),
|
47 |
$flag,
|
48 |
$version
|
49 |
) . '</p>',
|
50 |
esc_html__( 'Plugin Activation Error', 'head-footer-code' ),
|
51 |
+
array(
|
52 |
'response' => 200,
|
53 |
'back_link' => true,
|
54 |
+
)
|
55 |
);
|
56 |
|
57 |
// Trigger updater function.
|
60 |
|
61 |
// Regular update trigger.
|
62 |
add_action( 'plugins_loaded', 'auhfc_maybe_update' );
|
63 |
+
/**
|
64 |
+
* Function to check and run if update has to be done
|
65 |
+
*/
|
66 |
function auhfc_maybe_update() {
|
67 |
// Bail if this plugin data doesn't need updating.
|
68 |
if ( get_option( 'auhfc_db_ver' ) >= WPAU_HEAD_FOOTER_CODE_DB_VER ) {
|
77 |
add_action( 'admin_enqueue_scripts', 'auhfc_admin_enqueue_scripts' );
|
78 |
/**
|
79 |
* Enqueue admin styles and scripts to enable code editor in plugin settings and custom column on article listing
|
80 |
+
*
|
81 |
+
* @param string $hook Current page hook.
|
82 |
*/
|
83 |
function auhfc_admin_enqueue_scripts( $hook ) {
|
84 |
// Admin Stylesheet.
|
85 |
+
if ( in_array( $hook, array( 'edit.php', 'tools_page_head_footer_code' ), true ) ) {
|
86 |
wp_enqueue_style(
|
87 |
'head-footer-code-admin',
|
88 |
+
plugin_dir_url( __FILE__ ) . '../assets/css/admin.min.css',
|
89 |
+
array(),
|
90 |
WPAU_HEAD_FOOTER_CODE_VER
|
91 |
);
|
92 |
}
|
93 |
// Codemirror Assets.
|
94 |
if ( 'tools_page_head_footer_code' === $hook ) {
|
95 |
+
$cm_settings['codeEditor'] = wp_enqueue_code_editor( array( 'type' => 'text/html' ) );
|
96 |
wp_localize_script( 'code-editor', 'cm_settings', $cm_settings );
|
97 |
wp_enqueue_style( 'wp-codemirror' );
|
98 |
wp_enqueue_script( 'wp-codemirror' );
|
102 |
|
103 |
/**
|
104 |
* Provide global defaults
|
105 |
+
*
|
106 |
+
* @return array Arary of defined global values.
|
107 |
*/
|
108 |
function auhfc_settings() {
|
109 |
|
110 |
+
$defaults = array(
|
111 |
+
'sitewide' => array(
|
112 |
+
'head' => '',
|
113 |
+
'body' => '',
|
114 |
+
'footer' => '',
|
115 |
+
'priority_h' => 10,
|
116 |
+
'priority_b' => 10,
|
117 |
+
'priority_f' => 10,
|
118 |
+
'do_shortcode_h' => 'n',
|
119 |
+
'do_shortcode_b' => 'n',
|
120 |
+
'do_shortcode_f' => 'n',
|
121 |
+
),
|
122 |
+
'homepage' => array(
|
123 |
+
'head' => '',
|
124 |
+
'body' => '',
|
125 |
+
'footer' => '',
|
126 |
+
'behavior' => 'append',
|
127 |
+
),
|
128 |
+
'article' => array(
|
129 |
+
'post_types' => array(),
|
130 |
+
),
|
131 |
+
);
|
132 |
$auhfc_settings_sitewide = get_option( 'auhfc_settings_sitewide', $defaults['sitewide'] );
|
133 |
+
$defaults['sitewide'] = wp_parse_args( $auhfc_settings_sitewide, $defaults['sitewide'] );
|
134 |
$auhfc_settings_homepage = get_option( 'auhfc_settings_homepage', $defaults['homepage'] );
|
135 |
+
$defaults['homepage'] = wp_parse_args( $auhfc_settings_homepage, $defaults['homepage'] );
|
136 |
+
$auhfc_settings_article = get_option( 'auhfc_settings_article', $defaults['article'] );
|
137 |
+
$defaults['article'] = wp_parse_args( $auhfc_settings_article, $defaults['article'] );
|
138 |
|
139 |
return $defaults;
|
140 |
} // END function auhfc_settings()
|
141 |
|
142 |
/**
|
143 |
* Get values of metabox fields
|
144 |
+
*
|
145 |
+
* @param string $field_name Post meta field key.
|
146 |
+
* @param string $post_id Post ID (optional).
|
147 |
+
* @return string Post meta field value.
|
148 |
*/
|
149 |
function auhfc_get_meta( $field_name = '', $post_id = null ) {
|
150 |
|
152 |
return false;
|
153 |
}
|
154 |
|
155 |
+
if ( empty( $post_id ) || intval( $post_id ) !== $post_id ) {
|
156 |
if ( is_admin() ) {
|
157 |
global $post;
|
158 |
|
159 |
+
// If $post has not an object, return false.
|
160 |
if ( empty( $post ) || ! is_object( $post ) ) {
|
161 |
return false;
|
162 |
}
|
182 |
|
183 |
if ( ! empty( $field ) && is_array( $field ) && ! empty( $field[ $field_name ] ) ) {
|
184 |
return stripslashes_deep( $field[ $field_name ] );
|
185 |
+
} elseif ( 'behavior' === $field_name ) {
|
186 |
return 'append';
|
187 |
} else {
|
188 |
return false;
|
191 |
|
192 |
/**
|
193 |
* Return debugging string if WP_DEBUG constant is true.
|
194 |
+
*
|
195 |
+
* @param string $scope Scope of output (s - SITE WIDE, a - ARTICLE SPECIFIC, h - HOMEPAGE).
|
196 |
+
* @param string $location Location of output (h - HEAD, b - BODY, f - FOOTER).
|
197 |
+
* @param string $message Output message.
|
198 |
+
* @param string $code Code for output.
|
199 |
+
* @return string Composed string.
|
200 |
*/
|
201 |
function auhfc_out( $scope = null, $location = null, $message = null, $code = null ) {
|
202 |
if ( ! WP_DEBUG ) {
|
203 |
return $code;
|
204 |
}
|
205 |
+
if ( null === $scope || null === $location || null === $message ) {
|
206 |
return;
|
207 |
}
|
208 |
switch ( $scope ) {
|
215 |
case 'a':
|
216 |
$scope = 'Article specific';
|
217 |
break;
|
218 |
+
case 'c':
|
219 |
+
$scope = 'Category specific';
|
220 |
+
break;
|
221 |
default:
|
222 |
$scope = 'Unknown';
|
223 |
}
|
245 |
);
|
246 |
} // END function auhfc_out( $scope = null, $location = null, $message = null, $code = null )
|
247 |
|
248 |
+
/**
|
249 |
+
* Function to get Post Type
|
250 |
+
*/
|
251 |
function auhfc_get_post_type() {
|
252 |
$auhfc_post_type = 'not singular';
|
253 |
// Get post type.
|
254 |
if ( is_singular() ) {
|
255 |
global $wp_the_query;
|
256 |
$auhfc_query = $wp_the_query->get_queried_object();
|
257 |
+
if ( is_object( $auhfc_query ) ) {
|
258 |
$auhfc_post_type = $auhfc_query->post_type;
|
259 |
}
|
260 |
}
|
261 |
return $auhfc_post_type;
|
262 |
} // END function auhfc_get_post_type()
|
263 |
|
264 |
+
/**
|
265 |
+
* Function to check if homepage uses Blog mode
|
266 |
+
*/
|
267 |
function auhfc_is_homepage_blog_posts() {
|
268 |
+
if ( is_home() && 'posts' === get_option( 'show_on_front', false ) ) {
|
269 |
return true;
|
270 |
}
|
271 |
return false;
|
272 |
} // END function auhfc_is_homepage_blog_posts()
|
273 |
|
274 |
+
/**
|
275 |
+
* Function to print note for head section
|
276 |
+
*/
|
277 |
+
function auhfc_head_note() {
|
278 |
+
return '<p class="notice"><strong>' . esc_html__( 'IMPORTANT!', 'head-footer-code' ) . '</strong> ' . sprintf(
|
279 |
+
/* translators: 1: italicized 'unseen elements', 2: <script>, 3: <style>, 4: italicized sentence 'could break layouts or lead to unexpected situations' */
|
280 |
+
esc_html__( 'Usage of this hook should be reserved for output of %1$s like %2$s and %3$s tags or additional metadata. It should not be used to add arbitrary HTML content to a page that %4$s.', 'head-footer-code' ),
|
281 |
'<em>' . esc_html__( 'unseen elements', 'head-footer-code' ) . '</em>',
|
|
|
282 |
auhfc_html2code( '<script>' ),
|
283 |
+
auhfc_html2code( '<style>' ),
|
284 |
+
'<em>' . esc_html__( 'could break layouts or lead to unexpected situations', 'head-footer-code' ) . '</em>'
|
285 |
+
) . '</p>';
|
286 |
+
}
|
287 |
+
|
288 |
+
/**
|
289 |
+
* Function to print note for body section
|
290 |
+
*/
|
291 |
+
function auhfc_body_note() {
|
292 |
+
return '<p class="notice"><strong>' . esc_html__( 'IMPORTANT!', 'head-footer-code' ) . '</strong> ' . sprintf(
|
293 |
+
/* translators: %s will be replaced with a link to wp_body_open page on WordPress.org */
|
294 |
+
esc_html__( 'Make sure that your active theme support %s hook.', 'head-footer-code' ),
|
295 |
'<a href="https://developer.wordpress.org/reference/hooks/wp_body_open/" target="_hook">wp_body_open</a>'
|
296 |
) . '</p>';
|
297 |
}
|
298 |
|
299 |
+
/**
|
300 |
+
* Function to convert code to HTML special chars
|
301 |
+
*
|
302 |
+
* @param string $text RAW content.
|
303 |
+
*/
|
304 |
function auhfc_html2code( $text ) {
|
305 |
return '<code>' . htmlspecialchars( $text ) . '</code>';
|
306 |
} // END function auhfc_html2code( $text )
|
307 |
|
308 |
/**
|
309 |
* Determine should we print site-wide code
|
310 |
+
* or it should be replaced with homepage/article/category code.
|
311 |
+
*
|
312 |
+
* @param string $behavior Behavior for article specific code (replace/append).
|
313 |
+
* @param string $code Article specific custom code.
|
314 |
+
* @param string $post_type Post type of current article.
|
315 |
+
* @param array $post_types Array of post types where article specific code is enabled.
|
316 |
+
* @param boolean $is_category Indicate if current displayed page is category or not.
|
317 |
+
* @return boolean Boolean that determine should site-wide code be printed (true) or not (false).
|
318 |
*/
|
319 |
function auhfc_print_sitewide(
|
320 |
+
$behavior = 'append',
|
321 |
+
$code = '',
|
322 |
+
$post_type = null,
|
323 |
+
$post_types = array(),
|
324 |
+
$is_category = false
|
|
|
325 |
) {
|
326 |
+
|
327 |
+
// On homepage print site wide if...
|
328 |
$is_homepage_blog_posts = auhfc_is_homepage_blog_posts();
|
329 |
+
if ( $is_homepage_blog_posts ) {
|
330 |
+
// ... homepage behavior is not replace, or...
|
331 |
+
// ... homepage behavior is replace but homepage code is empty.
|
332 |
+
if (
|
333 |
+
'replace' !== $behavior ||
|
334 |
+
( 'replace' === $behavior && empty( $code ) )
|
335 |
+
) { return true; }
|
336 |
+
}
|
337 |
+
// On category page print site wide if...
|
338 |
+
else if ( $is_category ) {
|
339 |
+
// ... behavior is not replace, or...
|
340 |
+
// ... behavior is replace but category content is empty.
|
341 |
+
if (
|
342 |
+
'replace' !== $behavior ||
|
343 |
+
( 'replace' === $behavior && empty( $code ) )
|
344 |
+
) {
|
345 |
+
return true;
|
346 |
+
}
|
347 |
+
}
|
348 |
+
// On Blog Post or Custom Post Type ...
|
349 |
+
else if (
|
350 |
+
// ... article behavior is not replace, or...
|
351 |
+
// ... article behavior is replace but current Post Type is not in allowed Post Types, or...
|
352 |
+
// ... article behavior is replace and current Post Type is in allowed Post Types but article code is empty.
|
353 |
+
'replace' !== $behavior ||
|
354 |
+
( 'replace' === $behavior && ! in_array( $post_type, $post_types ) ) ||
|
355 |
+
( 'replace' === $behavior && in_array( $post_type, $post_types ) && empty( $code ) )
|
356 |
) {
|
357 |
return true;
|
358 |
}
|
359 |
+
|
360 |
return false;
|
361 |
}
|
inc/posts-custom-columns.php
CHANGED
@@ -1,4 +1,10 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
// If this file is called directly, abort.
|
3 |
if ( ! defined( 'WPINC' ) ) {
|
4 |
die;
|
@@ -11,34 +17,50 @@ if ( ! is_admin() ) {
|
|
11 |
|
12 |
// And do this only for post types enabled on plugin settings page.
|
13 |
$auhfc_settings = auhfc_settings();
|
14 |
-
if ( isset($auhfc_settings['article']['post_types'] ) ) {
|
15 |
-
foreach ($auhfc_settings['article']['post_types'] as $post_type) {
|
16 |
// Add the custom column to the all post types that have enabled support for custom code.
|
17 |
add_filter( 'manage_' . $post_type . '_posts_columns', 'auhfc_posts_columns' );
|
18 |
// And make that column sortable.
|
19 |
add_filter( 'manage_edit-' . $post_type . '_sortable_columns', 'auhfc_posts_sortable_columns' );
|
20 |
// Add the data to the custom column for each enabled post types.
|
21 |
-
add_action( 'manage_' . $post_type . '_posts_custom_column'
|
22 |
}
|
23 |
}
|
24 |
|
|
|
|
|
|
|
|
|
|
|
25 |
function auhfc_posts_columns( $columns ) {
|
26 |
$columns['hfc'] = __( 'Head & Footer Code', 'head-footer-code' );
|
27 |
return $columns;
|
28 |
} // END function auhfc_posts_columns( $columns )
|
29 |
|
|
|
|
|
|
|
|
|
|
|
30 |
function auhfc_posts_sortable_columns( $columns ) {
|
31 |
$columns['hfc'] = 'hfc';
|
32 |
return $columns;
|
33 |
} // END function auhfc_posts_sortable_columns( $columns )
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
function auhfc_posts_custom_columns( $column, $post_id ) {
|
36 |
if ( 'hfc' !== $column ) {
|
37 |
return;
|
38 |
}
|
39 |
|
40 |
-
$sections =
|
41 |
-
if ( !empty( auhfc_get_meta('head', $post_id) ) ) {
|
42 |
$sections[] = sprintf(
|
43 |
'<a href="post.php?post=%1$s&action=edit#auhfc_%2$s" class="badge blue %2$s" title="%3$s">%4$s</a>',
|
44 |
$post_id,
|
@@ -47,7 +69,7 @@ function auhfc_posts_custom_columns( $column, $post_id ) {
|
|
47 |
esc_html__( 'HEAD', 'head-footer-code' )
|
48 |
);
|
49 |
}
|
50 |
-
if ( !empty( auhfc_get_meta('body', $post_id) ) ) {
|
51 |
$sections[] = sprintf(
|
52 |
'<a href="post.php?post=%1$s&action=edit#auhfc_%2$s" class="badge blue %2$s" title="%3$s">%4$s</a>',
|
53 |
$post_id,
|
@@ -56,7 +78,7 @@ function auhfc_posts_custom_columns( $column, $post_id ) {
|
|
56 |
esc_html__( 'BODY', 'head-footer-code' )
|
57 |
);
|
58 |
}
|
59 |
-
if ( !empty( auhfc_get_meta('footer', $post_id) ) ) {
|
60 |
$sections[] = sprintf(
|
61 |
'<a href="post.php?post=%1$s&action=edit#auhfc_%2$s" class="badge blue %2$s" title="%3$s">%4$s</a>',
|
62 |
$post_id,
|
@@ -75,8 +97,9 @@ function auhfc_posts_custom_columns( $column, $post_id ) {
|
|
75 |
);
|
76 |
} else {
|
77 |
$mode = auhfc_get_meta( 'behavior', $post_id );
|
78 |
-
if ( 'append'
|
79 |
-
printf(
|
|
|
80 |
$post_id,
|
81 |
'behavior',
|
82 |
/* translators: This is description for article specific mode label 'Append' */
|
@@ -86,7 +109,8 @@ function auhfc_posts_custom_columns( $column, $post_id ) {
|
|
86 |
implode( '', $sections )
|
87 |
);
|
88 |
} else {
|
89 |
-
printf(
|
|
|
90 |
$post_id,
|
91 |
'behavior',
|
92 |
/* translators: This is description for article specific mode label 'Replace' */
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Generate Head & Footer Code indicator columns on article listing
|
4 |
+
*
|
5 |
+
* @package Head_Footer_Code
|
6 |
+
*/
|
7 |
+
|
8 |
// If this file is called directly, abort.
|
9 |
if ( ! defined( 'WPINC' ) ) {
|
10 |
die;
|
17 |
|
18 |
// And do this only for post types enabled on plugin settings page.
|
19 |
$auhfc_settings = auhfc_settings();
|
20 |
+
if ( isset( $auhfc_settings['article']['post_types'] ) ) {
|
21 |
+
foreach ( $auhfc_settings['article']['post_types'] as $post_type ) {
|
22 |
// Add the custom column to the all post types that have enabled support for custom code.
|
23 |
add_filter( 'manage_' . $post_type . '_posts_columns', 'auhfc_posts_columns' );
|
24 |
// And make that column sortable.
|
25 |
add_filter( 'manage_edit-' . $post_type . '_sortable_columns', 'auhfc_posts_sortable_columns' );
|
26 |
// Add the data to the custom column for each enabled post types.
|
27 |
+
add_action( 'manage_' . $post_type . '_posts_custom_column', 'auhfc_posts_custom_columns', 10, 2 );
|
28 |
}
|
29 |
}
|
30 |
|
31 |
+
/**
|
32 |
+
* Register Head & Footer Code column for posts table
|
33 |
+
*
|
34 |
+
* @param array $columns Array of existing columns for table.
|
35 |
+
*/
|
36 |
function auhfc_posts_columns( $columns ) {
|
37 |
$columns['hfc'] = __( 'Head & Footer Code', 'head-footer-code' );
|
38 |
return $columns;
|
39 |
} // END function auhfc_posts_columns( $columns )
|
40 |
|
41 |
+
/**
|
42 |
+
* Make Head & Footer Code column sortable
|
43 |
+
*
|
44 |
+
* @param array $columns Array of existing columns for table.
|
45 |
+
*/
|
46 |
function auhfc_posts_sortable_columns( $columns ) {
|
47 |
$columns['hfc'] = 'hfc';
|
48 |
return $columns;
|
49 |
} // END function auhfc_posts_sortable_columns( $columns )
|
50 |
|
51 |
+
/**
|
52 |
+
* Populate Head & Footer Code column with indicators
|
53 |
+
*
|
54 |
+
* @param string $column Table column name.
|
55 |
+
* @param integer $post_id Current article ID.
|
56 |
+
*/
|
57 |
function auhfc_posts_custom_columns( $column, $post_id ) {
|
58 |
if ( 'hfc' !== $column ) {
|
59 |
return;
|
60 |
}
|
61 |
|
62 |
+
$sections = array();
|
63 |
+
if ( ! empty( auhfc_get_meta( 'head', $post_id ) ) ) {
|
64 |
$sections[] = sprintf(
|
65 |
'<a href="post.php?post=%1$s&action=edit#auhfc_%2$s" class="badge blue %2$s" title="%3$s">%4$s</a>',
|
66 |
$post_id,
|
69 |
esc_html__( 'HEAD', 'head-footer-code' )
|
70 |
);
|
71 |
}
|
72 |
+
if ( ! empty( auhfc_get_meta( 'body', $post_id ) ) ) {
|
73 |
$sections[] = sprintf(
|
74 |
'<a href="post.php?post=%1$s&action=edit#auhfc_%2$s" class="badge blue %2$s" title="%3$s">%4$s</a>',
|
75 |
$post_id,
|
78 |
esc_html__( 'BODY', 'head-footer-code' )
|
79 |
);
|
80 |
}
|
81 |
+
if ( ! empty( auhfc_get_meta( 'footer', $post_id ) ) ) {
|
82 |
$sections[] = sprintf(
|
83 |
'<a href="post.php?post=%1$s&action=edit#auhfc_%2$s" class="badge blue %2$s" title="%3$s">%4$s</a>',
|
84 |
$post_id,
|
97 |
);
|
98 |
} else {
|
99 |
$mode = auhfc_get_meta( 'behavior', $post_id );
|
100 |
+
if ( 'append' === $mode ) {
|
101 |
+
printf(
|
102 |
+
'<a href="post.php?post=%1$s&action=edit#auhfc_%2$s" class="label" title="%3$s">%4$s</a><br />%5$s',
|
103 |
$post_id,
|
104 |
'behavior',
|
105 |
/* translators: This is description for article specific mode label 'Append' */
|
109 |
implode( '', $sections )
|
110 |
);
|
111 |
} else {
|
112 |
+
printf(
|
113 |
+
'<a href="post.php?post=%1$s&action=edit#auhfc_%2$s" class="label" title="%3$s">%4$s</a><br />%5$s',
|
114 |
$post_id,
|
115 |
'behavior',
|
116 |
/* translators: This is description for article specific mode label 'Replace' */
|
inc/settings.php
CHANGED
@@ -1,4 +1,10 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
// If this file is called directly, abort.
|
3 |
if ( ! defined( 'WPINC' ) ) {
|
4 |
die;
|
@@ -21,15 +27,13 @@ add_filter( 'plugin_row_meta', 'auhfc_add_plugin_meta_links', 10, 2 );
|
|
21 |
*/
|
22 |
function auhfc_add_admin_menu() {
|
23 |
|
24 |
-
// add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function )
|
25 |
-
// add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function, $position )
|
26 |
add_submenu_page(
|
27 |
-
'tools.php',
|
28 |
-
'Head & Footer Code',
|
29 |
-
'Head & Footer Code',
|
30 |
-
'manage_options',
|
31 |
-
'head_footer_code',
|
32 |
-
'auhfc_options_page'
|
33 |
);
|
34 |
|
35 |
}
|
@@ -43,10 +47,11 @@ function auhfc_settings_init() {
|
|
43 |
/**
|
44 |
* Get settings from options table
|
45 |
*/
|
46 |
-
$auhfc_settings
|
47 |
-
$auhfc_homepage_blog_posts = 'posts'
|
48 |
-
$wp52note
|
49 |
-
$
|
|
|
50 |
|
51 |
/**
|
52 |
* Settings Sections are the groups of settings you see on WordPress settings pages
|
@@ -55,12 +60,11 @@ function auhfc_settings_init() {
|
|
55 |
* simpler to maintain and creates less new pages for users to learn.
|
56 |
* You just tell them to change your setting on the relevant existing page.
|
57 |
*/
|
58 |
-
// add_settings_section( $id, $title, $callback, $page )
|
59 |
add_settings_section(
|
60 |
-
'head_footer_code_settings_sitewide',
|
61 |
-
esc_html__( 'Site-wide head, body and footer code', 'head-footer-code' ),
|
62 |
-
'auhfc_sitewide_settings_section_description',
|
63 |
-
'head_footer_code'
|
64 |
);
|
65 |
|
66 |
/**
|
@@ -69,24 +73,23 @@ function auhfc_settings_init() {
|
|
69 |
* wp-admin settings pages by registering your settings and using a few
|
70 |
* callbacks to control the output.
|
71 |
*/
|
72 |
-
// add_settings_field( $id, $title, $callback, $page, $section, $args )
|
73 |
add_settings_field(
|
74 |
-
'auhfc_head_code',
|
75 |
-
__( 'HEAD Code', 'head-footer-code' ),
|
76 |
-
'auhfc_textarea_field_render',
|
77 |
-
'head_footer_code',
|
78 |
-
'head_footer_code_settings_sitewide',
|
79 |
-
|
80 |
'field' => 'auhfc_settings_sitewide[head]',
|
81 |
'value' => $auhfc_settings['sitewide']['head'],
|
82 |
-
'description' => sprintf(
|
83 |
/* translators: %s will be replaced with preformatted HTML tag </head> */
|
84 |
esc_html__( 'Code to enqueue in HEAD section (before the %s).', 'head-footer-code' ),
|
85 |
auhfc_html2code( '</head>' )
|
86 |
),
|
87 |
'field_class' => 'widefat code codeEditor',
|
88 |
'rows' => 7,
|
89 |
-
|
90 |
);
|
91 |
|
92 |
add_settings_field(
|
@@ -95,12 +98,11 @@ function auhfc_settings_init() {
|
|
95 |
'auhfc_number_field_render',
|
96 |
'head_footer_code',
|
97 |
'head_footer_code_settings_sitewide',
|
98 |
-
|
99 |
'field' => 'auhfc_settings_sitewide[priority_h]',
|
100 |
'value' => $auhfc_settings['sitewide']['priority_h'],
|
101 |
'description' => sprintf(
|
102 |
-
/* translators:
|
103 |
-
%2$s will be replaced with preformatted HTML tag </head> */
|
104 |
esc_html__( 'Priority for enqueued HEAD code. Default is %1$d. Larger number inject code closer to %2$s.', 'head-footer-code' ),
|
105 |
10,
|
106 |
auhfc_html2code( '</head>' )
|
@@ -109,7 +111,25 @@ function auhfc_settings_init() {
|
|
109 |
'min' => 1,
|
110 |
'max' => 1000,
|
111 |
'step' => 1,
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
);
|
114 |
|
115 |
add_settings_field(
|
@@ -118,7 +138,7 @@ function auhfc_settings_init() {
|
|
118 |
'auhfc_textarea_field_render',
|
119 |
'head_footer_code',
|
120 |
'head_footer_code_settings_sitewide',
|
121 |
-
|
122 |
'field' => 'auhfc_settings_sitewide[body]',
|
123 |
'value' => $auhfc_settings['sitewide']['body'],
|
124 |
'description' => $body_note . sprintf(
|
@@ -128,7 +148,7 @@ function auhfc_settings_init() {
|
|
128 |
) . $wp52note,
|
129 |
'field_class' => 'widefat code codeEditor',
|
130 |
'rows' => 7,
|
131 |
-
|
132 |
);
|
133 |
|
134 |
add_settings_field(
|
@@ -137,12 +157,11 @@ function auhfc_settings_init() {
|
|
137 |
'auhfc_number_field_render',
|
138 |
'head_footer_code',
|
139 |
'head_footer_code_settings_sitewide',
|
140 |
-
|
141 |
'field' => 'auhfc_settings_sitewide[priority_b]',
|
142 |
'value' => $auhfc_settings['sitewide']['priority_b'],
|
143 |
'description' => sprintf(
|
144 |
-
/* translators:
|
145 |
-
%2$s will be replaced with preformatted HTML tag <body> */
|
146 |
esc_html__(
|
147 |
'Priority for enqueued BODY code. Default is %1$d. Smaller number inject code closer to %2$s.',
|
148 |
'head-footer-code'
|
@@ -155,7 +174,25 @@ function auhfc_settings_init() {
|
|
155 |
'min' => 1,
|
156 |
'max' => 1000,
|
157 |
'step' => 1,
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
);
|
160 |
|
161 |
add_settings_field(
|
@@ -164,7 +201,7 @@ function auhfc_settings_init() {
|
|
164 |
'auhfc_textarea_field_render',
|
165 |
'head_footer_code',
|
166 |
'head_footer_code_settings_sitewide',
|
167 |
-
|
168 |
'field' => 'auhfc_settings_sitewide[footer]',
|
169 |
'value' => $auhfc_settings['sitewide']['footer'],
|
170 |
'description' => sprintf(
|
@@ -174,7 +211,7 @@ function auhfc_settings_init() {
|
|
174 |
),
|
175 |
'field_class' => 'widefat code codeEditor',
|
176 |
'rows' => 7,
|
177 |
-
|
178 |
);
|
179 |
|
180 |
add_settings_field(
|
@@ -183,12 +220,11 @@ function auhfc_settings_init() {
|
|
183 |
'auhfc_number_field_render',
|
184 |
'head_footer_code',
|
185 |
'head_footer_code_settings_sitewide',
|
186 |
-
|
187 |
'field' => 'auhfc_settings_sitewide[priority_f]',
|
188 |
'value' => $auhfc_settings['sitewide']['priority_f'],
|
189 |
'description' => sprintf(
|
190 |
-
/* translators:
|
191 |
-
%2$s will be replaced with preformatted HTML tag </body> */
|
192 |
esc_html__( 'Priority for enqueued FOOTER code. Default is %1$d. Larger number inject code closer to %2$s.', 'head-footer-code' ),
|
193 |
10,
|
194 |
auhfc_html2code( '</body>' )
|
@@ -197,25 +233,25 @@ function auhfc_settings_init() {
|
|
197 |
'min' => 1,
|
198 |
'max' => 1000,
|
199 |
'step' => 1,
|
200 |
-
|
201 |
);
|
202 |
|
203 |
add_settings_field(
|
204 |
-
'
|
205 |
-
__( 'Process Shortcodes', 'head-footer-code' ),
|
206 |
'auhfc_select_field_render',
|
207 |
'head_footer_code',
|
208 |
'head_footer_code_settings_sitewide',
|
209 |
-
|
210 |
-
'field' => 'auhfc_settings_sitewide[
|
211 |
-
'items' =>
|
212 |
'y' => __( 'Enable', 'head-footer-code' ),
|
213 |
'n' => __( 'Disable', 'head-footer-code' ),
|
214 |
-
|
215 |
-
'value' => $auhfc_settings['sitewide']['
|
216 |
-
'description' => esc_html__( 'If you wish to process shortcodes in FOOTER section, enable this option.
|
217 |
'class' => 'regular-text',
|
218 |
-
|
219 |
);
|
220 |
|
221 |
/**
|
@@ -224,8 +260,10 @@ function auhfc_settings_init() {
|
|
224 |
* wp-admin settings pages by registering your settings and using a few
|
225 |
* callbacks to control the output.
|
226 |
*/
|
227 |
-
|
228 |
-
|
|
|
|
|
229 |
|
230 |
/**
|
231 |
* Add section for Homepage if show_on_front is set to Blog Posts
|
@@ -239,12 +277,11 @@ function auhfc_settings_init() {
|
|
239 |
* simpler to maintain and creates less new pages for users to learn.
|
240 |
* You just tell them to change your setting on the relevant existing page.
|
241 |
*/
|
242 |
-
// add_settings_section( $id, $title, $callback, $page )
|
243 |
add_settings_section(
|
244 |
-
'head_footer_code_settings_homepage',
|
245 |
-
esc_html__( 'Head, body and footer code on Homepage in Blog Posts mode', 'head-footer-code' ),
|
246 |
-
'auhfc_homepage_settings_section_description',
|
247 |
-
'head_footer_code'
|
248 |
);
|
249 |
|
250 |
/**
|
@@ -253,24 +290,23 @@ function auhfc_settings_init() {
|
|
253 |
* wp-admin settings pages by registering your settings and using a few
|
254 |
* callbacks to control the output.
|
255 |
*/
|
256 |
-
// add_settings_field( $id, $title, $callback, $page, $section, $args )
|
257 |
add_settings_field(
|
258 |
-
'auhfc_homepage_head_code',
|
259 |
-
__( 'Homepage HEAD Code', 'head-footer-code' ),
|
260 |
-
'auhfc_textarea_field_render',
|
261 |
-
'head_footer_code',
|
262 |
-
'head_footer_code_settings_homepage',
|
263 |
-
|
264 |
'field' => 'auhfc_settings_homepage[head]',
|
265 |
'value' => $auhfc_settings['homepage']['head'],
|
266 |
-
'description' => sprintf(
|
267 |
/* translators: %s will be replaced with preformatted HTML tag </head> */
|
268 |
esc_html__( 'Code to enqueue in HEAD section (before the %s) on Homepage.', 'head-footer-code' ),
|
269 |
auhfc_html2code( '</head>' )
|
270 |
),
|
271 |
'field_class' => 'widefat code codeEditor',
|
272 |
'rows' => 5,
|
273 |
-
|
274 |
);
|
275 |
|
276 |
add_settings_field(
|
@@ -279,17 +315,17 @@ function auhfc_settings_init() {
|
|
279 |
'auhfc_textarea_field_render',
|
280 |
'head_footer_code',
|
281 |
'head_footer_code_settings_homepage',
|
282 |
-
|
283 |
'field' => 'auhfc_settings_homepage[body]',
|
284 |
'value' => $auhfc_settings['homepage']['body'],
|
285 |
'description' => $body_note . sprintf(
|
286 |
-
/* translators: %s
|
287 |
esc_html__( 'Code to enqueue in BODY section (after the %s) on Homepage.', 'head-footer-code' ),
|
288 |
auhfc_html2code( '<body>' )
|
289 |
) . $wp52note,
|
290 |
'field_class' => 'widefat code codeEditor',
|
291 |
'rows' => 5,
|
292 |
-
|
293 |
);
|
294 |
|
295 |
add_settings_field(
|
@@ -298,7 +334,7 @@ function auhfc_settings_init() {
|
|
298 |
'auhfc_textarea_field_render',
|
299 |
'head_footer_code',
|
300 |
'head_footer_code_settings_homepage',
|
301 |
-
|
302 |
'field' => 'auhfc_settings_homepage[footer]',
|
303 |
'value' => $auhfc_settings['homepage']['footer'],
|
304 |
'description' => sprintf(
|
@@ -308,7 +344,7 @@ function auhfc_settings_init() {
|
|
308 |
),
|
309 |
'field_class' => 'widefat code codeEditor',
|
310 |
'rows' => 5,
|
311 |
-
|
312 |
);
|
313 |
|
314 |
add_settings_field(
|
@@ -317,16 +353,16 @@ function auhfc_settings_init() {
|
|
317 |
'auhfc_select_field_render',
|
318 |
'head_footer_code',
|
319 |
'head_footer_code_settings_homepage',
|
320 |
-
|
321 |
'field' => 'auhfc_settings_homepage[behavior]',
|
322 |
-
'items' =>
|
323 |
'append' => esc_html__( 'Append to the site-wide code', 'head-footer-code' ),
|
324 |
'replace' => esc_html__( 'Replace the site-wide code', 'head-footer-code' ),
|
325 |
-
|
326 |
'value' => $auhfc_settings['homepage']['behavior'],
|
327 |
'description' => esc_html__( 'Chose how the Homepage specific code will be enqueued in relation to site-wide code.', 'head-footer-code' ),
|
328 |
'class' => 'regular-text',
|
329 |
-
|
330 |
);
|
331 |
|
332 |
/**
|
@@ -335,8 +371,10 @@ function auhfc_settings_init() {
|
|
335 |
* wp-admin settings pages by registering your settings and using a few
|
336 |
* callbacks to control the output.
|
337 |
*/
|
338 |
-
|
339 |
-
|
|
|
|
|
340 |
|
341 |
} // END if ( $auhfc_homepage_blog_posts )
|
342 |
|
@@ -347,17 +385,16 @@ function auhfc_settings_init() {
|
|
347 |
* simpler to maintain and creates less new pages for users to learn.
|
348 |
* You just tell them to change your setting on the relevant existing page.
|
349 |
*/
|
350 |
-
// add_settings_section( $id, $title, $callback, $page )
|
351 |
add_settings_section(
|
352 |
-
'head_footer_code_settings_article',
|
353 |
-
esc_html__( 'Article specific settings', 'head-footer-code' ),
|
354 |
-
'auhfc_article_settings_section_description',
|
355 |
-
'head_footer_code'
|
356 |
);
|
357 |
|
358 |
-
// Prepare clean list of post types w/o attachment
|
359 |
-
$public_post_types = get_post_types(
|
360 |
-
$clean_post_types
|
361 |
foreach ( $public_post_types as $public_post_type => $public_post_object ) {
|
362 |
if ( 'attachment' === $public_post_type ) {
|
363 |
continue;
|
@@ -365,20 +402,19 @@ function auhfc_settings_init() {
|
|
365 |
$clean_post_types[ $public_post_type ] = "{$public_post_object->label} ({$public_post_type})";
|
366 |
}
|
367 |
|
368 |
-
// add_settings_field( $id, $title, $callback, $page, $section, $args )
|
369 |
add_settings_field(
|
370 |
-
'auhfc_post_types',
|
371 |
-
__( 'Post Types', 'head-footer-code' ),
|
372 |
-
'auhfc_checkbox_group_field_render',
|
373 |
-
'head_footer_code',
|
374 |
-
'head_footer_code_settings_article',
|
375 |
-
|
376 |
'field' => 'auhfc_settings_article[post_types]',
|
377 |
'items' => $clean_post_types,
|
378 |
'value' => $auhfc_settings['article']['post_types'],
|
379 |
'description' => esc_html__( 'Select which post types will have Article specific section. Please note, even if you have Head/Footer Code set per article and then you disable that post type, article specific code will not be printed but only site-wide code.', 'head-footer-code' ),
|
380 |
'class' => 'checkbox',
|
381 |
-
|
382 |
);
|
383 |
|
384 |
/**
|
@@ -387,13 +423,17 @@ function auhfc_settings_init() {
|
|
387 |
* wp-admin settings pages by registering your settings and using a few
|
388 |
* callbacks to control the output.
|
389 |
*/
|
390 |
-
|
391 |
-
|
|
|
|
|
392 |
|
393 |
} // END function auhfc_settings_init()
|
394 |
|
395 |
/**
|
396 |
* This function provides textarea for settings fields
|
|
|
|
|
397 |
*/
|
398 |
function auhfc_textarea_field_render( $args ) {
|
399 |
if ( empty( $args['rows'] ) ) {
|
@@ -412,22 +452,26 @@ function auhfc_textarea_field_render( $args ) {
|
|
412 |
|
413 |
/**
|
414 |
* This function provides number input for settings fields
|
|
|
|
|
415 |
*/
|
416 |
function auhfc_number_field_render( $args ) {
|
417 |
printf(
|
418 |
'<input type="number" name="%1$s" id="%1$s" value="%2$s" class="%3$s" min="%4$s" max="%5$s" step="%6$s" /><p class="description">%7$s</p>',
|
419 |
-
$args['field'], // name/id
|
420 |
-
$args['value'], // value
|
421 |
-
$args['class'], // class
|
422 |
-
$args['min'], // min
|
423 |
-
$args['max'], // max
|
424 |
-
$args['step'], // step
|
425 |
-
$args['description'] // description
|
426 |
);
|
427 |
} // END function auhfc_number_field_render( $args )
|
428 |
|
429 |
/**
|
430 |
* This function provides checkbox group for settings fields
|
|
|
|
|
431 |
*/
|
432 |
function auhfc_checkbox_group_field_render( $args ) {
|
433 |
|
@@ -438,7 +482,7 @@ function auhfc_checkbox_group_field_render( $args ) {
|
|
438 |
|
439 |
$checked = '';
|
440 |
if ( ! empty( $args['value'] ) ) {
|
441 |
-
$checked = ( in_array( $key, $args['value'] ) ) ? 'checked="checked"' : '';
|
442 |
}
|
443 |
|
444 |
$out .= sprintf(
|
@@ -466,7 +510,8 @@ function auhfc_checkbox_group_field_render( $args ) {
|
|
466 |
|
467 |
/**
|
468 |
* This function provides select for settings fields
|
469 |
-
*
|
|
|
470 |
*/
|
471 |
function auhfc_select_field_render( $args ) {
|
472 |
if ( empty( $args['class'] ) ) {
|
@@ -478,7 +523,7 @@ function auhfc_select_field_render( $args ) {
|
|
478 |
sanitize_html_class( $args['class'] )
|
479 |
);
|
480 |
foreach ( $args['items'] as $key => $val ) {
|
481 |
-
$selected = ( $args['value']
|
482 |
printf(
|
483 |
'<option %1$s value="%2$s">%3$s</option>',
|
484 |
esc_attr( $selected ), // 1
|
@@ -490,20 +535,23 @@ function auhfc_select_field_render( $args ) {
|
|
490 |
'</select><p class="description">%s</p>',
|
491 |
wp_kses(
|
492 |
$args['description'],
|
493 |
-
|
494 |
-
'a' =>
|
495 |
-
'href' =>
|
496 |
-
'target' =>
|
497 |
-
|
498 |
'strong',
|
499 |
'em',
|
500 |
'pre',
|
501 |
'code',
|
502 |
-
|
503 |
)
|
504 |
);
|
505 |
} // END function auhfc_select_field_render( $args )
|
506 |
|
|
|
|
|
|
|
507 |
function auhfc_sitewide_settings_section_description() {
|
508 |
printf(
|
509 |
'<p>%s</p>',
|
@@ -511,6 +559,9 @@ function auhfc_sitewide_settings_section_description() {
|
|
511 |
);
|
512 |
} // END function auhfc_sitewide_settings_section_description()
|
513 |
|
|
|
|
|
|
|
514 |
function auhfc_homepage_settings_section_description() {
|
515 |
printf(
|
516 |
'<p>%s</p>',
|
@@ -518,6 +569,9 @@ function auhfc_homepage_settings_section_description() {
|
|
518 |
);
|
519 |
} // END function auhfc_homepage_settings_section_description()
|
520 |
|
|
|
|
|
|
|
521 |
function auhfc_article_settings_section_description() {
|
522 |
printf(
|
523 |
'<p>%s</p>',
|
@@ -525,6 +579,9 @@ function auhfc_article_settings_section_description() {
|
|
525 |
);
|
526 |
} // END function auhfc_article_settings_section_description()
|
527 |
|
|
|
|
|
|
|
528 |
function auhfc_options_page() {
|
529 |
if ( ! current_user_can( 'manage_options' ) ) {
|
530 |
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'head-footer-code' ) );
|
@@ -535,6 +592,7 @@ function auhfc_options_page() {
|
|
535 |
|
536 |
/**
|
537 |
* Generate Settings link on Plugins page listing
|
|
|
538 |
* @param array $links Array of existing plugin row links.
|
539 |
* @return array Updated array of plugin row links with link to Settings page
|
540 |
*/
|
@@ -546,7 +604,8 @@ function auhfc_plugin_settings_link( $links ) {
|
|
546 |
|
547 |
/**
|
548 |
* Add link to official plugin pages
|
549 |
-
*
|
|
|
550 |
* @param string $file Path of current plugin file.
|
551 |
* @return array Array of updated plugin row links
|
552 |
*/
|
@@ -554,7 +613,7 @@ function auhfc_add_plugin_meta_links( $links, $file ) {
|
|
554 |
if ( 'head-footer-code/head-footer-code.php' === $file ) {
|
555 |
return array_merge(
|
556 |
$links,
|
557 |
-
|
558 |
sprintf(
|
559 |
'<a href="https://wordpress.org/support/plugin/head-footer-code" target="_blank">%s</a>',
|
560 |
__( 'Support', 'head-footer-code' )
|
@@ -563,7 +622,7 @@ function auhfc_add_plugin_meta_links( $links, $file ) {
|
|
563 |
'<a href="https://urosevic.net/wordpress/donate/?donate_for=head-footer-code" target="_blank">%s</a>',
|
564 |
__( 'Donate', 'head-footer-code' )
|
565 |
),
|
566 |
-
|
567 |
);
|
568 |
}
|
569 |
return $links;
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Settings page for Head & Footer Code plugin
|
4 |
+
*
|
5 |
+
* @package Head_Footer_Code
|
6 |
+
*/
|
7 |
+
|
8 |
// If this file is called directly, abort.
|
9 |
if ( ! defined( 'WPINC' ) ) {
|
10 |
die;
|
27 |
*/
|
28 |
function auhfc_add_admin_menu() {
|
29 |
|
|
|
|
|
30 |
add_submenu_page(
|
31 |
+
'tools.php', // Parent Slug.
|
32 |
+
'Head & Footer Code', // Page Title.
|
33 |
+
'Head & Footer Code', // Menu Title.
|
34 |
+
'manage_options', // Capability.
|
35 |
+
'head_footer_code', // Menu Slug.
|
36 |
+
'auhfc_options_page' // Position.
|
37 |
);
|
38 |
|
39 |
}
|
47 |
/**
|
48 |
* Get settings from options table
|
49 |
*/
|
50 |
+
$auhfc_settings = auhfc_settings();
|
51 |
+
$auhfc_homepage_blog_posts = 'posts' === get_option( 'show_on_front', false ) ? true : false;
|
52 |
+
$wp52note = version_compare( get_bloginfo( 'version' ), '5.2', '<' ) ? ' ' . esc_html__( 'Requires WordPress 5.2 or later.', 'head-footer-code' ) : '';
|
53 |
+
$head_note = auhfc_head_note();
|
54 |
+
$body_note = auhfc_body_note();
|
55 |
|
56 |
/**
|
57 |
* Settings Sections are the groups of settings you see on WordPress settings pages
|
60 |
* simpler to maintain and creates less new pages for users to learn.
|
61 |
* You just tell them to change your setting on the relevant existing page.
|
62 |
*/
|
|
|
63 |
add_settings_section(
|
64 |
+
'head_footer_code_settings_sitewide', // Id.
|
65 |
+
esc_html__( 'Site-wide head, body and footer code', 'head-footer-code' ), // Title.
|
66 |
+
'auhfc_sitewide_settings_section_description', // Callback.
|
67 |
+
'head_footer_code' // Page.
|
68 |
);
|
69 |
|
70 |
/**
|
73 |
* wp-admin settings pages by registering your settings and using a few
|
74 |
* callbacks to control the output.
|
75 |
*/
|
|
|
76 |
add_settings_field(
|
77 |
+
'auhfc_head_code', // Id.
|
78 |
+
__( 'HEAD Code', 'head-footer-code' ), // Title.
|
79 |
+
'auhfc_textarea_field_render', // Callback.
|
80 |
+
'head_footer_code', // Page.
|
81 |
+
'head_footer_code_settings_sitewide', // Section.
|
82 |
+
array( // Arguments.
|
83 |
'field' => 'auhfc_settings_sitewide[head]',
|
84 |
'value' => $auhfc_settings['sitewide']['head'],
|
85 |
+
'description' => $head_note . sprintf(
|
86 |
/* translators: %s will be replaced with preformatted HTML tag </head> */
|
87 |
esc_html__( 'Code to enqueue in HEAD section (before the %s).', 'head-footer-code' ),
|
88 |
auhfc_html2code( '</head>' )
|
89 |
),
|
90 |
'field_class' => 'widefat code codeEditor',
|
91 |
'rows' => 7,
|
92 |
+
)
|
93 |
);
|
94 |
|
95 |
add_settings_field(
|
98 |
'auhfc_number_field_render',
|
99 |
'head_footer_code',
|
100 |
'head_footer_code_settings_sitewide',
|
101 |
+
array(
|
102 |
'field' => 'auhfc_settings_sitewide[priority_h]',
|
103 |
'value' => $auhfc_settings['sitewide']['priority_h'],
|
104 |
'description' => sprintf(
|
105 |
+
/* translators: 1: default HEAD priority, 2: preformatted HTML tag </head> */
|
|
|
106 |
esc_html__( 'Priority for enqueued HEAD code. Default is %1$d. Larger number inject code closer to %2$s.', 'head-footer-code' ),
|
107 |
10,
|
108 |
auhfc_html2code( '</head>' )
|
111 |
'min' => 1,
|
112 |
'max' => 1000,
|
113 |
'step' => 1,
|
114 |
+
)
|
115 |
+
);
|
116 |
+
|
117 |
+
add_settings_field(
|
118 |
+
'auhfc_do_shortcode_h',
|
119 |
+
__( 'Process HEAD Shortcodes', 'head-footer-code' ),
|
120 |
+
'auhfc_select_field_render',
|
121 |
+
'head_footer_code',
|
122 |
+
'head_footer_code_settings_sitewide',
|
123 |
+
array(
|
124 |
+
'field' => 'auhfc_settings_sitewide[do_shortcode_h]',
|
125 |
+
'items' => array(
|
126 |
+
'y' => __( 'Enable', 'head-footer-code' ),
|
127 |
+
'n' => __( 'Disable', 'head-footer-code' ),
|
128 |
+
),
|
129 |
+
'value' => $auhfc_settings['sitewide']['do_shortcode_h'],
|
130 |
+
'description' => esc_html__( 'If you wish to process shortcodes in the HEAD section, enable this option. Please note, shortcodes with malformed output in the HEAD section can break the rendering of your website!', 'head-footer-code' ),
|
131 |
+
'class' => 'regular-text',
|
132 |
+
)
|
133 |
);
|
134 |
|
135 |
add_settings_field(
|
138 |
'auhfc_textarea_field_render',
|
139 |
'head_footer_code',
|
140 |
'head_footer_code_settings_sitewide',
|
141 |
+
array(
|
142 |
'field' => 'auhfc_settings_sitewide[body]',
|
143 |
'value' => $auhfc_settings['sitewide']['body'],
|
144 |
'description' => $body_note . sprintf(
|
148 |
) . $wp52note,
|
149 |
'field_class' => 'widefat code codeEditor',
|
150 |
'rows' => 7,
|
151 |
+
)
|
152 |
);
|
153 |
|
154 |
add_settings_field(
|
157 |
'auhfc_number_field_render',
|
158 |
'head_footer_code',
|
159 |
'head_footer_code_settings_sitewide',
|
160 |
+
array(
|
161 |
'field' => 'auhfc_settings_sitewide[priority_b]',
|
162 |
'value' => $auhfc_settings['sitewide']['priority_b'],
|
163 |
'description' => sprintf(
|
164 |
+
/* translators: 1: default BODY priority, 2: preformatted HTML tag <body> */
|
|
|
165 |
esc_html__(
|
166 |
'Priority for enqueued BODY code. Default is %1$d. Smaller number inject code closer to %2$s.',
|
167 |
'head-footer-code'
|
174 |
'min' => 1,
|
175 |
'max' => 1000,
|
176 |
'step' => 1,
|
177 |
+
)
|
178 |
+
);
|
179 |
+
|
180 |
+
add_settings_field(
|
181 |
+
'auhfc_do_shortcode_b',
|
182 |
+
__( 'Process BODY Shortcodes', 'head-footer-code' ),
|
183 |
+
'auhfc_select_field_render',
|
184 |
+
'head_footer_code',
|
185 |
+
'head_footer_code_settings_sitewide',
|
186 |
+
array(
|
187 |
+
'field' => 'auhfc_settings_sitewide[do_shortcode_b]',
|
188 |
+
'items' => array(
|
189 |
+
'y' => __( 'Enable', 'head-footer-code' ),
|
190 |
+
'n' => __( 'Disable', 'head-footer-code' ),
|
191 |
+
),
|
192 |
+
'value' => $auhfc_settings['sitewide']['do_shortcode_b'],
|
193 |
+
'description' => esc_html__( 'If you wish to process shortcodes in the BODY section, enable this option.', 'head-footer-code' ),
|
194 |
+
'class' => 'regular-text',
|
195 |
+
)
|
196 |
);
|
197 |
|
198 |
add_settings_field(
|
201 |
'auhfc_textarea_field_render',
|
202 |
'head_footer_code',
|
203 |
'head_footer_code_settings_sitewide',
|
204 |
+
array(
|
205 |
'field' => 'auhfc_settings_sitewide[footer]',
|
206 |
'value' => $auhfc_settings['sitewide']['footer'],
|
207 |
'description' => sprintf(
|
211 |
),
|
212 |
'field_class' => 'widefat code codeEditor',
|
213 |
'rows' => 7,
|
214 |
+
)
|
215 |
);
|
216 |
|
217 |
add_settings_field(
|
220 |
'auhfc_number_field_render',
|
221 |
'head_footer_code',
|
222 |
'head_footer_code_settings_sitewide',
|
223 |
+
array(
|
224 |
'field' => 'auhfc_settings_sitewide[priority_f]',
|
225 |
'value' => $auhfc_settings['sitewide']['priority_f'],
|
226 |
'description' => sprintf(
|
227 |
+
/* translators: 1: default FOOTER priority, 2: preformatted HTML tag </body> */
|
|
|
228 |
esc_html__( 'Priority for enqueued FOOTER code. Default is %1$d. Larger number inject code closer to %2$s.', 'head-footer-code' ),
|
229 |
10,
|
230 |
auhfc_html2code( '</body>' )
|
233 |
'min' => 1,
|
234 |
'max' => 1000,
|
235 |
'step' => 1,
|
236 |
+
)
|
237 |
);
|
238 |
|
239 |
add_settings_field(
|
240 |
+
'auhfc_do_shortcode_f',
|
241 |
+
__( 'Process FOOTER Shortcodes', 'head-footer-code' ),
|
242 |
'auhfc_select_field_render',
|
243 |
'head_footer_code',
|
244 |
'head_footer_code_settings_sitewide',
|
245 |
+
array(
|
246 |
+
'field' => 'auhfc_settings_sitewide[do_shortcode_f]',
|
247 |
+
'items' => array(
|
248 |
'y' => __( 'Enable', 'head-footer-code' ),
|
249 |
'n' => __( 'Disable', 'head-footer-code' ),
|
250 |
+
),
|
251 |
+
'value' => $auhfc_settings['sitewide']['do_shortcode_f'],
|
252 |
+
'description' => esc_html__( 'If you wish to process shortcodes in the FOOTER section, enable this option.', 'head-footer-code' ),
|
253 |
'class' => 'regular-text',
|
254 |
+
)
|
255 |
);
|
256 |
|
257 |
/**
|
260 |
* wp-admin settings pages by registering your settings and using a few
|
261 |
* callbacks to control the output.
|
262 |
*/
|
263 |
+
register_setting(
|
264 |
+
'head_footer_code_settings', // Option group.
|
265 |
+
'auhfc_settings_sitewide' // Option name.
|
266 |
+
);
|
267 |
|
268 |
/**
|
269 |
* Add section for Homepage if show_on_front is set to Blog Posts
|
277 |
* simpler to maintain and creates less new pages for users to learn.
|
278 |
* You just tell them to change your setting on the relevant existing page.
|
279 |
*/
|
|
|
280 |
add_settings_section(
|
281 |
+
'head_footer_code_settings_homepage', // Id.
|
282 |
+
esc_html__( 'Head, body and footer code on Homepage in Blog Posts mode', 'head-footer-code' ), // Title.
|
283 |
+
'auhfc_homepage_settings_section_description', // Callback.
|
284 |
+
'head_footer_code' // Page.
|
285 |
);
|
286 |
|
287 |
/**
|
290 |
* wp-admin settings pages by registering your settings and using a few
|
291 |
* callbacks to control the output.
|
292 |
*/
|
|
|
293 |
add_settings_field(
|
294 |
+
'auhfc_homepage_head_code', // Id.
|
295 |
+
__( 'Homepage HEAD Code', 'head-footer-code' ), // Title.
|
296 |
+
'auhfc_textarea_field_render', // Callback.
|
297 |
+
'head_footer_code', // Page.
|
298 |
+
'head_footer_code_settings_homepage', // Section.
|
299 |
+
array( // Arguments.
|
300 |
'field' => 'auhfc_settings_homepage[head]',
|
301 |
'value' => $auhfc_settings['homepage']['head'],
|
302 |
+
'description' => $head_note . sprintf(
|
303 |
/* translators: %s will be replaced with preformatted HTML tag </head> */
|
304 |
esc_html__( 'Code to enqueue in HEAD section (before the %s) on Homepage.', 'head-footer-code' ),
|
305 |
auhfc_html2code( '</head>' )
|
306 |
),
|
307 |
'field_class' => 'widefat code codeEditor',
|
308 |
'rows' => 5,
|
309 |
+
)
|
310 |
);
|
311 |
|
312 |
add_settings_field(
|
315 |
'auhfc_textarea_field_render',
|
316 |
'head_footer_code',
|
317 |
'head_footer_code_settings_homepage',
|
318 |
+
array(
|
319 |
'field' => 'auhfc_settings_homepage[body]',
|
320 |
'value' => $auhfc_settings['homepage']['body'],
|
321 |
'description' => $body_note . sprintf(
|
322 |
+
/* translators: %s: preformatted HTML tag <body> */
|
323 |
esc_html__( 'Code to enqueue in BODY section (after the %s) on Homepage.', 'head-footer-code' ),
|
324 |
auhfc_html2code( '<body>' )
|
325 |
) . $wp52note,
|
326 |
'field_class' => 'widefat code codeEditor',
|
327 |
'rows' => 5,
|
328 |
+
)
|
329 |
);
|
330 |
|
331 |
add_settings_field(
|
334 |
'auhfc_textarea_field_render',
|
335 |
'head_footer_code',
|
336 |
'head_footer_code_settings_homepage',
|
337 |
+
array(
|
338 |
'field' => 'auhfc_settings_homepage[footer]',
|
339 |
'value' => $auhfc_settings['homepage']['footer'],
|
340 |
'description' => sprintf(
|
344 |
),
|
345 |
'field_class' => 'widefat code codeEditor',
|
346 |
'rows' => 5,
|
347 |
+
)
|
348 |
);
|
349 |
|
350 |
add_settings_field(
|
353 |
'auhfc_select_field_render',
|
354 |
'head_footer_code',
|
355 |
'head_footer_code_settings_homepage',
|
356 |
+
array(
|
357 |
'field' => 'auhfc_settings_homepage[behavior]',
|
358 |
+
'items' => array(
|
359 |
'append' => esc_html__( 'Append to the site-wide code', 'head-footer-code' ),
|
360 |
'replace' => esc_html__( 'Replace the site-wide code', 'head-footer-code' ),
|
361 |
+
),
|
362 |
'value' => $auhfc_settings['homepage']['behavior'],
|
363 |
'description' => esc_html__( 'Chose how the Homepage specific code will be enqueued in relation to site-wide code.', 'head-footer-code' ),
|
364 |
'class' => 'regular-text',
|
365 |
+
)
|
366 |
);
|
367 |
|
368 |
/**
|
371 |
* wp-admin settings pages by registering your settings and using a few
|
372 |
* callbacks to control the output.
|
373 |
*/
|
374 |
+
register_setting(
|
375 |
+
'head_footer_code_settings', // Option group.
|
376 |
+
'auhfc_settings_homepage' // Option name.
|
377 |
+
);
|
378 |
|
379 |
} // END if ( $auhfc_homepage_blog_posts )
|
380 |
|
385 |
* simpler to maintain and creates less new pages for users to learn.
|
386 |
* You just tell them to change your setting on the relevant existing page.
|
387 |
*/
|
|
|
388 |
add_settings_section(
|
389 |
+
'head_footer_code_settings_article', // Id.
|
390 |
+
esc_html__( 'Article specific settings', 'head-footer-code' ), // Title.
|
391 |
+
'auhfc_article_settings_section_description', // Callback.
|
392 |
+
'head_footer_code' // Page.
|
393 |
);
|
394 |
|
395 |
+
// Prepare clean list of post types w/o attachment.
|
396 |
+
$public_post_types = get_post_types( array( 'public' => true ), 'objects' );
|
397 |
+
$clean_post_types = array();
|
398 |
foreach ( $public_post_types as $public_post_type => $public_post_object ) {
|
399 |
if ( 'attachment' === $public_post_type ) {
|
400 |
continue;
|
402 |
$clean_post_types[ $public_post_type ] = "{$public_post_object->label} ({$public_post_type})";
|
403 |
}
|
404 |
|
|
|
405 |
add_settings_field(
|
406 |
+
'auhfc_post_types', // Id.
|
407 |
+
__( 'Post Types', 'head-footer-code' ), // Title.
|
408 |
+
'auhfc_checkbox_group_field_render', // Vallback.
|
409 |
+
'head_footer_code', // Page.
|
410 |
+
'head_footer_code_settings_article', // Section.
|
411 |
+
array( // Arguments.
|
412 |
'field' => 'auhfc_settings_article[post_types]',
|
413 |
'items' => $clean_post_types,
|
414 |
'value' => $auhfc_settings['article']['post_types'],
|
415 |
'description' => esc_html__( 'Select which post types will have Article specific section. Please note, even if you have Head/Footer Code set per article and then you disable that post type, article specific code will not be printed but only site-wide code.', 'head-footer-code' ),
|
416 |
'class' => 'checkbox',
|
417 |
+
)
|
418 |
);
|
419 |
|
420 |
/**
|
423 |
* wp-admin settings pages by registering your settings and using a few
|
424 |
* callbacks to control the output.
|
425 |
*/
|
426 |
+
register_setting(
|
427 |
+
'head_footer_code_settings', // Option group.
|
428 |
+
'auhfc_settings_article' // Option name.
|
429 |
+
);
|
430 |
|
431 |
} // END function auhfc_settings_init()
|
432 |
|
433 |
/**
|
434 |
* This function provides textarea for settings fields
|
435 |
+
*
|
436 |
+
* @param array $args Array of arguments (field, rows, field_class, value, description).
|
437 |
*/
|
438 |
function auhfc_textarea_field_render( $args ) {
|
439 |
if ( empty( $args['rows'] ) ) {
|
452 |
|
453 |
/**
|
454 |
* This function provides number input for settings fields
|
455 |
+
*
|
456 |
+
* @param array $args Array of arguments (field, value, min, max, step, rows, class, description).
|
457 |
*/
|
458 |
function auhfc_number_field_render( $args ) {
|
459 |
printf(
|
460 |
'<input type="number" name="%1$s" id="%1$s" value="%2$s" class="%3$s" min="%4$s" max="%5$s" step="%6$s" /><p class="description">%7$s</p>',
|
461 |
+
$args['field'], // name/id.
|
462 |
+
$args['value'], // value.
|
463 |
+
$args['class'], // class.
|
464 |
+
$args['min'], // min.
|
465 |
+
$args['max'], // max.
|
466 |
+
$args['step'], // step.
|
467 |
+
$args['description'] // description.
|
468 |
);
|
469 |
} // END function auhfc_number_field_render( $args )
|
470 |
|
471 |
/**
|
472 |
* This function provides checkbox group for settings fields
|
473 |
+
*
|
474 |
+
* @param array $args Array of arguments (items, value, field, class, description).
|
475 |
*/
|
476 |
function auhfc_checkbox_group_field_render( $args ) {
|
477 |
|
482 |
|
483 |
$checked = '';
|
484 |
if ( ! empty( $args['value'] ) ) {
|
485 |
+
$checked = ( in_array( $key, $args['value'], true ) ) ? 'checked="checked"' : '';
|
486 |
}
|
487 |
|
488 |
$out .= sprintf(
|
510 |
|
511 |
/**
|
512 |
* This function provides select for settings fields
|
513 |
+
*
|
514 |
+
* @param array $args Array of field arguments (class, field, items, value, description).
|
515 |
*/
|
516 |
function auhfc_select_field_render( $args ) {
|
517 |
if ( empty( $args['class'] ) ) {
|
523 |
sanitize_html_class( $args['class'] )
|
524 |
);
|
525 |
foreach ( $args['items'] as $key => $val ) {
|
526 |
+
$selected = ( $args['value'] === $key ) ? 'selected=selected' : '';
|
527 |
printf(
|
528 |
'<option %1$s value="%2$s">%3$s</option>',
|
529 |
esc_attr( $selected ), // 1
|
535 |
'</select><p class="description">%s</p>',
|
536 |
wp_kses(
|
537 |
$args['description'],
|
538 |
+
array(
|
539 |
+
'a' => array(
|
540 |
+
'href' => array(),
|
541 |
+
'target' => array( '_blank' ),
|
542 |
+
),
|
543 |
'strong',
|
544 |
'em',
|
545 |
'pre',
|
546 |
'code',
|
547 |
+
)
|
548 |
)
|
549 |
);
|
550 |
} // END function auhfc_select_field_render( $args )
|
551 |
|
552 |
+
/**
|
553 |
+
* Print description for site-wide section
|
554 |
+
*/
|
555 |
function auhfc_sitewide_settings_section_description() {
|
556 |
printf(
|
557 |
'<p>%s</p>',
|
559 |
);
|
560 |
} // END function auhfc_sitewide_settings_section_description()
|
561 |
|
562 |
+
/**
|
563 |
+
* Print description for homepage section
|
564 |
+
*/
|
565 |
function auhfc_homepage_settings_section_description() {
|
566 |
printf(
|
567 |
'<p>%s</p>',
|
569 |
);
|
570 |
} // END function auhfc_homepage_settings_section_description()
|
571 |
|
572 |
+
/**
|
573 |
+
* Print description for article section
|
574 |
+
*/
|
575 |
function auhfc_article_settings_section_description() {
|
576 |
printf(
|
577 |
'<p>%s</p>',
|
579 |
);
|
580 |
} // END function auhfc_article_settings_section_description()
|
581 |
|
582 |
+
/**
|
583 |
+
* Print settings page from template
|
584 |
+
*/
|
585 |
function auhfc_options_page() {
|
586 |
if ( ! current_user_can( 'manage_options' ) ) {
|
587 |
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'head-footer-code' ) );
|
592 |
|
593 |
/**
|
594 |
* Generate Settings link on Plugins page listing
|
595 |
+
*
|
596 |
* @param array $links Array of existing plugin row links.
|
597 |
* @return array Updated array of plugin row links with link to Settings page
|
598 |
*/
|
604 |
|
605 |
/**
|
606 |
* Add link to official plugin pages
|
607 |
+
*
|
608 |
+
* @param array $links Array of existing plugin row links.
|
609 |
* @param string $file Path of current plugin file.
|
610 |
* @return array Array of updated plugin row links
|
611 |
*/
|
613 |
if ( 'head-footer-code/head-footer-code.php' === $file ) {
|
614 |
return array_merge(
|
615 |
$links,
|
616 |
+
array(
|
617 |
sprintf(
|
618 |
'<a href="https://wordpress.org/support/plugin/head-footer-code" target="_blank">%s</a>',
|
619 |
__( 'Support', 'head-footer-code' )
|
622 |
'<a href="https://urosevic.net/wordpress/donate/?donate_for=head-footer-code" target="_blank">%s</a>',
|
623 |
__( 'Donate', 'head-footer-code' )
|
624 |
),
|
625 |
+
)
|
626 |
);
|
627 |
}
|
628 |
return $links;
|
inc/update.php
CHANGED
@@ -1,4 +1,10 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
// If this file is called directly, abort.
|
3 |
if ( ! defined( 'WPINC' ) ) {
|
4 |
die;
|
@@ -9,11 +15,10 @@ if ( ! defined( 'WPINC' ) ) {
|
|
9 |
*
|
10 |
* For example, if the current DB version is 3, and the target DB version is 6,
|
11 |
* this function will execute update routines if they exist:
|
12 |
-
*
|
13 |
-
*
|
14 |
-
*
|
15 |
*/
|
16 |
-
|
17 |
function auhfc_update() {
|
18 |
// Disable PHP timeout for running updates.
|
19 |
set_time_limit( 0 );
|
@@ -146,25 +151,25 @@ function auhfc_update_5() {
|
|
146 |
// Get options from DB.
|
147 |
$defaults = get_option( 'auhfc_settings' );
|
148 |
|
149 |
-
$sitewide =
|
150 |
'head' => ! empty( $defaults['head'] ) ? $defaults['head'] : '',
|
151 |
'body' => ! empty( $defaults['body'] ) ? $defaults['body'] : '',
|
152 |
'footer' => ! empty( $defaults['footer'] ) ? $defaults['footer'] : '',
|
153 |
'do_shortcode' => ! empty( $defaults['do_shortcode'] ) ? $defaults['do_shortcode'] : 'n',
|
154 |
-
|
155 |
update_option( 'auhfc_settings_sitewide', $sitewide );
|
156 |
|
157 |
-
$homepage =
|
158 |
-
'head'
|
159 |
-
'body'
|
160 |
-
'footer'
|
161 |
-
'behavior'
|
162 |
-
|
163 |
update_option( 'auhfc_settings_homepage', $homepage );
|
164 |
|
165 |
-
$article =
|
166 |
-
'post_types'
|
167 |
-
|
168 |
update_option( 'auhfc_settings_article', $article );
|
169 |
|
170 |
// Now delete old single option.
|
@@ -178,7 +183,27 @@ function auhfc_update_5() {
|
|
178 |
function auhfc_update_6() {
|
179 |
$article = get_option( 'auhfc_settings_article' );
|
180 |
if ( is_null( $article['post_types'] ) ) {
|
181 |
-
$article['post_types'] =
|
182 |
update_option( 'auhfc_settings_article', $article );
|
183 |
}
|
184 |
} // END function auhfc_update_6()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Routines to update Head & Footer Code database through new versions
|
4 |
+
*
|
5 |
+
* @package Head_Footer_Code
|
6 |
+
*/
|
7 |
+
|
8 |
// If this file is called directly, abort.
|
9 |
if ( ! defined( 'WPINC' ) ) {
|
10 |
die;
|
15 |
*
|
16 |
* For example, if the current DB version is 3, and the target DB version is 6,
|
17 |
* this function will execute update routines if they exist:
|
18 |
+
* - auhfc_update_4()
|
19 |
+
* - auhfc_update_5()
|
20 |
+
* - auhfc_update_6()
|
21 |
*/
|
|
|
22 |
function auhfc_update() {
|
23 |
// Disable PHP timeout for running updates.
|
24 |
set_time_limit( 0 );
|
151 |
// Get options from DB.
|
152 |
$defaults = get_option( 'auhfc_settings' );
|
153 |
|
154 |
+
$sitewide = array(
|
155 |
'head' => ! empty( $defaults['head'] ) ? $defaults['head'] : '',
|
156 |
'body' => ! empty( $defaults['body'] ) ? $defaults['body'] : '',
|
157 |
'footer' => ! empty( $defaults['footer'] ) ? $defaults['footer'] : '',
|
158 |
'do_shortcode' => ! empty( $defaults['do_shortcode'] ) ? $defaults['do_shortcode'] : 'n',
|
159 |
+
);
|
160 |
update_option( 'auhfc_settings_sitewide', $sitewide );
|
161 |
|
162 |
+
$homepage = array(
|
163 |
+
'head' => ! empty( $defaults['homepage_head'] ) ? $defaults['homepage_head'] : '',
|
164 |
+
'body' => ! empty( $defaults['homepage_body'] ) ? $defaults['homepage_body'] : '',
|
165 |
+
'footer' => ! empty( $defaults['homepage_footer'] ) ? $defaults['homepage_footer'] : '',
|
166 |
+
'behavior' => ! empty( $defaults['homepage_behavior'] ) ? $defaults['homepage_behavior'] : 'append',
|
167 |
+
);
|
168 |
update_option( 'auhfc_settings_homepage', $homepage );
|
169 |
|
170 |
+
$article = array(
|
171 |
+
'post_types' => ! empty( $defaults['post_types'] ) ? $defaults['post_types'] : array(),
|
172 |
+
);
|
173 |
update_option( 'auhfc_settings_article', $article );
|
174 |
|
175 |
// Now delete old single option.
|
183 |
function auhfc_update_6() {
|
184 |
$article = get_option( 'auhfc_settings_article' );
|
185 |
if ( is_null( $article['post_types'] ) ) {
|
186 |
+
$article['post_types'] = array();
|
187 |
update_option( 'auhfc_settings_article', $article );
|
188 |
}
|
189 |
} // END function auhfc_update_6()
|
190 |
+
|
191 |
+
/**
|
192 |
+
* Do Shortcode per location
|
193 |
+
*/
|
194 |
+
function auhfc_update_7() {
|
195 |
+
// Get options from DB.
|
196 |
+
$sitewide = get_option( 'auhfc_settings_sitewide' );
|
197 |
+
|
198 |
+
if ( ! empty( $sitewide['do_shortcode'] ) ) {
|
199 |
+
$sitewide['do_shortcode_h'] = 'n';
|
200 |
+
$sitewide['do_shortcode_b'] = 'n';
|
201 |
+
$sitewide['do_shortcode_f'] = $sitewide['do_shortcode'];
|
202 |
+
} else {
|
203 |
+
$sitewide['do_shortcode_h'] = 'n';
|
204 |
+
$sitewide['do_shortcode_b'] = 'n';
|
205 |
+
$sitewide['do_shortcode_f'] = 'n';
|
206 |
+
}
|
207 |
+
unset( $sitewide['do_shortcode'] );
|
208 |
+
update_option( 'auhfc_settings_sitewide', $sitewide );
|
209 |
+
} // END function auhfc_update_7()
|
index.php
CHANGED
@@ -1,2 +1,7 @@
|
|
1 |
<?php
|
2 |
-
|
|
|
|
|
|
|
|
|
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Silence is golden
|
4 |
+
*
|
5 |
+
* @package Head_Footer_Code
|
6 |
+
*/
|
7 |
+
|
readme.txt
CHANGED
@@ -1,19 +1,20 @@
|
|
1 |
-
|
|
|
2 |
Contributors: urkekg, techwebux
|
3 |
Donate link: https://urosevic.net/wordpress/donate/?donate_for=head-footer-code
|
4 |
Tags: head, header, footer, body, scripts, wp_head, wp_footer, wp_body_open, head footer code, custom script
|
5 |
Requires at least: 4.9
|
6 |
-
Tested up to:
|
7 |
-
Stable tag: 1.
|
8 |
Requires PHP: 5.6
|
9 |
License: GPLv3
|
10 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
11 |
|
12 |
-
Easy add site-wide and
|
13 |
|
14 |
-
|
15 |
|
16 |
-
**Head & Footer Code** plugin helps you add custom code snippets (JavaScript, CSS, or HTML) to the page even if you are not a programmer.
|
17 |
|
18 |
Go to **Tools** → **Head & Footer Code** in WordPress Dashboard. Insert custom code to HEAD, BODY or FOOTER section (depending on what you have to do).
|
19 |
|
@@ -21,7 +22,8 @@ If your WordPress shows the latest blog posts on the homepage, you can also add
|
|
21 |
|
22 |
To insert custom code specific for individual article (post, page or custom post type), use article-specific Metabox while editing post/page/custom post type (check out [Screenshots](https://wordpress.org/plugins/head-footer-code/#screenshots)). There choose if that specific code appends to site-wide code defined on **Tools** → **Head & Footer Code**, or to replace it.
|
23 |
|
24 |
-
|
|
|
25 |
|
26 |
This magic is done by hooking to WordPress hooks `wp_head`, `wp_footer` and `wp_body_open`.
|
27 |
|
@@ -40,13 +42,13 @@ Various code snippets are supported, including but not limited to:
|
|
40 |
* Yandex site verification
|
41 |
* Alexa site verification
|
42 |
|
43 |
-
|
44 |
|
45 |
If **Head & Footer Code** does not work on your WordPress project, please let us know by [raising a new support ticket](https://wordpress.org/support/plugin/head-footer-code/#new-topic-0) in the [Community Forum](https://wordpress.org/support/plugin/head-footer-code/) and describe what does not works and how to reproduce the issue. We will make sure to resolve the issue as soon as possible.
|
46 |
|
47 |
If you find **Head & Footer Code** useful for your project, please [review plugin](https://wordpress.org/support/plugin/head-footer-code/reviews/#new-post).
|
48 |
|
49 |
-
|
50 |
|
51 |
* Set site-wide custom content for head page section (before the `</head>`)
|
52 |
* Set site-wide custom content for body section (after the `<body>`) - **Requires WordPress 5.2!**
|
@@ -55,24 +57,26 @@ If you find **Head & Footer Code** useful for your project, please [review p
|
|
55 |
* Set article specific custom code for head page section (before the `</head>`)
|
56 |
* Set article specific custom code for body section (after the `<body>`) - **Requires WordPress 5.2!**
|
57 |
* Set article specific custom content for footer page section (before the `</body>`)
|
|
|
58 |
* Choose priority of printed custom code to head/body/footer sections (lower number mean far from `</head>` and `</body>` and closer to `<body>`, higher number means closer to `</head>` and `</body>` and farther to `<body>`)
|
59 |
* Choose which post types will have enabled article specific head/body/footer fields
|
60 |
* Choose should article specific head/body/footer code be appended to site-wide code, or will replace site-wide code
|
61 |
* **[NEW in 1.2.1]** View on Posts/Pages/Custom Post Types listing if article has defined any article specific custom code
|
62 |
* Site-wide section located under **Tools** > **Head & Footer Code**
|
63 |
* If you have set WP_DEBUG constant in `wp-config.php` to `true`, you'll see site-wide and article specific entries in page source code wrapped to comments.
|
64 |
-
* Multisite is supported.
|
65 |
-
* PHP 8 ready!
|
66 |
|
67 |
General settings (HEAD, BODY, FOOTER global code and priority, Homepage code and behaviour) saves in WordPress option `auhfc_settings`.
|
68 |
Each post/page/custom post type specific HEAD, BODY and FOOTER code and behaviour saves to post meta `_auhfc`.
|
|
|
69 |
This data deletes from the database on uninstall.
|
70 |
|
71 |
-
|
72 |
|
73 |
Installation of the **Head & Footer Code** is easy as any other WordPress plugin.
|
74 |
|
75 |
-
|
76 |
|
77 |
1. In WordPress Dashboard go to **Plugins** → **Add New**.
|
78 |
1. Enter `head footer code` to the **Search plugins...** field and wait for the moment.
|
@@ -81,7 +85,7 @@ Installation of the **Head & Footer Code** is easy as any other WordPress pl
|
|
81 |
1. Click **Settings** link for **Head & Footer Code** or visit the **Tools** → **Head & Footer Code**.
|
82 |
1. Add the desired code to the target section.
|
83 |
|
84 |
-
|
85 |
|
86 |
1. Click on the **Download** button to get **Head & Footer Code** installation package.
|
87 |
1. Unpack archive **head-footer-code.zip** on local computer.
|
@@ -90,56 +94,80 @@ Installation of the **Head & Footer Code** is easy as any other WordPress pl
|
|
90 |
1. Click **Settings** link for **Head & Footer Code** or visit the **Tools** → **Head & Footer Code**.
|
91 |
1. Add the desired code to the target section.
|
92 |
|
93 |
-
|
94 |
|
95 |
-
|
96 |
|
97 |
As it's a security risk, the **Head & Footer Code** does not process PHP code if entered into any plugin field (global or article specific).
|
98 |
|
99 |
Any content added to HFC fields is printed on the front-end as is.
|
100 |
|
101 |
-
|
102 |
|
103 |
This feature is implemented since WordPress version 5.2 and requires theme compatibility.
|
104 |
|
105 |
To make sure if theme you use supports [wp_body_open](https://developer.wordpress.org/reference/hooks/wp_body_open/) hook, open in code editor `header.php` file from theme you use, and check if right after opening `<BODY>` tag there is following code (if it does not exists, add it or ask some developer to do that for you):
|
106 |
|
107 |
-
|
|
|
|
|
|
|
|
|
108 |
|
109 |
-
|
110 |
|
111 |
1. Head & Footer Code box in Plugin search results
|
112 |
2. Plugin Settings page (Site-wide, Homepage and Article Post Types)
|
113 |
3. Article specific metabox
|
114 |
4. Example of custom code inserted to HEAD section (site-wide with appended article specific)
|
115 |
-
5. Example of custom code inserted to BODY
|
116 |
-
6.
|
117 |
-
7. Example of
|
|
|
|
|
|
|
|
|
118 |
|
119 |
-
|
120 |
|
121 |
-
= 1.0.0 =
|
122 |
Initial release of new plugin developed by Aleksandar Urosevic.
|
123 |
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
|
128 |
-
= 1.2.3 (2021-07-19) =
|
129 |
* Tested: on WordPress 5.8-RC4 and PHP 8.0.8
|
130 |
* (2021-05-04) Fix: Notice errors Trying to get property 'post_type' of non-object in inc/front.php (thanks to @tekgirlymama)
|
131 |
* Improve: DRY for getting post type.
|
132 |
|
133 |
-
|
|
|
134 |
* Tested: on WordPress 5.7.1
|
135 |
* (2021-02-01) Fix: Noice errors in update script (thanks to @swinggraphics)
|
136 |
* Improve: wording on post/page listing
|
137 |
|
138 |
-
|
|
|
139 |
* Add: Head & Footer Code column to post/page/custom post type listing to show if/what article specific custom code is defined
|
140 |
* Fix: in_array() expects parameter 2 to be array, null given in head-footer-code/inc/front.php on line 46, 111, and 176
|
141 |
|
142 |
-
|
|
|
143 |
* Add: custom head, body and footer code for Homepage in Blog Posts mode.
|
144 |
* Fix: Code Editor broken in WordPress 5.5 release.
|
145 |
* Fix: Invalid requests while saving settings https://github.com/urosevic/head-footer-code/issues/1
|
@@ -147,11 +175,13 @@ Initial release of new plugin developed by Aleksandar Urosevic.
|
|
147 |
* Improve: translators tips for complex strings.
|
148 |
* Improve: all strings available to localize.
|
149 |
|
150 |
-
|
|
|
151 |
* Tested: on WordPress 5.4.1, 5.5-RC2-48768 with PHP 7.4.1
|
152 |
* Add: Video tutorial on how to install, configure and use Head & Footer Code plugin
|
153 |
|
154 |
-
|
|
|
155 |
* Tested: on WordPress 5.1.4, 5.3.2 and 5.4-beta3 with PHP 7.2.15 and 7.3.7
|
156 |
* Fix: Backslashes are removed on post/page update in article specific HEAD/BODY/FOOTER code reported by @asherber (`update_post_meta` pass key and value to `update_metadata` which expect them slashed key and value)
|
157 |
* Add: Support for `wp_body_open` Body hook introduced in WordPress 5.2
|
@@ -160,11 +190,13 @@ Initial release of new plugin developed by Aleksandar Urosevic.
|
|
160 |
* Update: Links and wording on plugin settings page
|
161 |
* Update: Screenshots
|
162 |
|
163 |
-
|
|
|
164 |
* Fix: Fatal Error on Multisite WP's (thanks @kunzemarketing for reporting)
|
165 |
* Improve: DRI for front-end debugging
|
166 |
|
167 |
-
|
|
|
168 |
* Add: Descriptive post types and descriptions for article specific sections
|
169 |
* Add: Option to process shortcodes in FOOTER section (global setting for site-wide and article specific)
|
170 |
* Change: Separate priority for HEAD and FOOT so admin can choose different priorities for header and footer
|
@@ -172,7 +204,8 @@ Initial release of new plugin developed by Aleksandar Urosevic.
|
|
172 |
* Add: Plugin activation hook to prevent fatal errors in case of legacy WP and/or PHP
|
173 |
* Improve: Loading security
|
174 |
|
175 |
-
|
|
|
176 |
* Test compatibility with WordPress 5.1.1 and PHP 7.2.15
|
177 |
* Change: Meta boxes layout and type of behavior selector
|
178 |
* Change: Convert Post metaboxes to OOP
|
@@ -180,35 +213,42 @@ Initial release of new plugin developed by Aleksandar Urosevic.
|
|
180 |
* Add: Bundle GNU GPLv3 license to plugin codebase
|
181 |
* Update: Screenshots
|
182 |
|
183 |
-
|
184 |
* Compatibility check: Tested for WordPress 4.7.1
|
185 |
* UX: Add right hand sidebar on global settings page with links to donate, FAQ, Community support and plugin Reviews page.
|
186 |
* UX: Set monospaced font for textareas on global settings and article pages
|
187 |
|
188 |
-
|
|
|
189 |
* Fix: `PHP Notice: Trying to get property of non-object in \wp-content\plugins\head-footer-code\inc\front.php on line 41`.
|
190 |
* Fix: Overwrite footer content for post/page if post/page template after content have another WP Loop query (like recent posts WP Widget in RHS sidebar).
|
191 |
* Optimize: Avoid reading post meta if not singular or post type not enabled
|
192 |
* Tested in Multisite environment (main and other network websites) on WordPress v4.5-alpha-36504 and theme Twenty Sixteen v1.2-alpha.
|
193 |
|
194 |
-
|
|
|
195 |
* Enhance: Add uninstall routine to make some housekeeping on plugin removal.
|
196 |
* Enhance: Add post type in debug comments.
|
197 |
* Readme: Test on WordPress v4.4-beta1 and updated compatibility.
|
198 |
|
199 |
-
|
|
|
200 |
* Fix: PHP Warning: in_array() expects parameter 2 to be array, string given (introduced in v1.0.3)
|
201 |
|
202 |
-
|
|
|
203 |
* Change: Make even default WP post types `post` and `page` optional for page specific head/footer code
|
204 |
|
205 |
-
|
|
|
206 |
* Change: Replace PayPal donation links to prevent account limitations if plugin is used on website that violates PayPal's Acceptable Use Policy
|
207 |
|
208 |
-
|
|
|
209 |
* Fix: PHP Notice Trying to get property of non-object
|
210 |
* Optimize: Remove `attachment` post type from available to select as no reason to have custom head/footer code on attachments
|
211 |
* Optimize: Settings code cleanup
|
212 |
|
213 |
-
|
|
|
214 |
* Initial release.
|
1 |
+
# Head & Footer Code
|
2 |
+
|
3 |
Contributors: urkekg, techwebux
|
4 |
Donate link: https://urosevic.net/wordpress/donate/?donate_for=head-footer-code
|
5 |
Tags: head, header, footer, body, scripts, wp_head, wp_footer, wp_body_open, head footer code, custom script
|
6 |
Requires at least: 4.9
|
7 |
+
Tested up to: 6.0
|
8 |
+
Stable tag: 1.3.0
|
9 |
Requires PHP: 5.6
|
10 |
License: GPLv3
|
11 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
12 |
|
13 |
+
Easy add site-wide, category and article specific custom code before the closing </head> and </body>, or after opening <body> tag.
|
14 |
|
15 |
+
## Description
|
16 |
|
17 |
+
**Head & Footer Code** plugin helps you add custom code snippets (JavaScript, CSS, or HTML) to the page even if you are not a programmer. It could be within the `<head>` (site verification code for various services, custom styles, meta or Webfont link), right after opening `<body>` (pixel tracking, analytics or heatmap code) or just before closing `</body>` tag.
|
18 |
|
19 |
Go to **Tools** → **Head & Footer Code** in WordPress Dashboard. Insert custom code to HEAD, BODY or FOOTER section (depending on what you have to do).
|
20 |
|
22 |
|
23 |
To insert custom code specific for individual article (post, page or custom post type), use article-specific Metabox while editing post/page/custom post type (check out [Screenshots](https://wordpress.org/plugins/head-footer-code/#screenshots)). There choose if that specific code appends to site-wide code defined on **Tools** → **Head & Footer Code**, or to replace it.
|
24 |
|
25 |
+
Since version 1.2.5 you can also define Category specific code on each individual category.
|
26 |
+
Other taxonomies (tag and custom taxonomy) do not have their specific code. Global code uses instead for them.
|
27 |
|
28 |
This magic is done by hooking to WordPress hooks `wp_head`, `wp_footer` and `wp_body_open`.
|
29 |
|
42 |
* Yandex site verification
|
43 |
* Alexa site verification
|
44 |
|
45 |
+
### Works or broken?
|
46 |
|
47 |
If **Head & Footer Code** does not work on your WordPress project, please let us know by [raising a new support ticket](https://wordpress.org/support/plugin/head-footer-code/#new-topic-0) in the [Community Forum](https://wordpress.org/support/plugin/head-footer-code/) and describe what does not works and how to reproduce the issue. We will make sure to resolve the issue as soon as possible.
|
48 |
|
49 |
If you find **Head & Footer Code** useful for your project, please [review plugin](https://wordpress.org/support/plugin/head-footer-code/reviews/#new-post).
|
50 |
|
51 |
+
### Features
|
52 |
|
53 |
* Set site-wide custom content for head page section (before the `</head>`)
|
54 |
* Set site-wide custom content for body section (after the `<body>`) - **Requires WordPress 5.2!**
|
57 |
* Set article specific custom code for head page section (before the `</head>`)
|
58 |
* Set article specific custom code for body section (after the `<body>`) - **Requires WordPress 5.2!**
|
59 |
* Set article specific custom content for footer page section (before the `</body>`)
|
60 |
+
* **[NEW in 1.3.0]** Set category specific custom code for head, body and/or footer of the page
|
61 |
* Choose priority of printed custom code to head/body/footer sections (lower number mean far from `</head>` and `</body>` and closer to `<body>`, higher number means closer to `</head>` and `</body>` and farther to `<body>`)
|
62 |
* Choose which post types will have enabled article specific head/body/footer fields
|
63 |
* Choose should article specific head/body/footer code be appended to site-wide code, or will replace site-wide code
|
64 |
* **[NEW in 1.2.1]** View on Posts/Pages/Custom Post Types listing if article has defined any article specific custom code
|
65 |
* Site-wide section located under **Tools** > **Head & Footer Code**
|
66 |
* If you have set WP_DEBUG constant in `wp-config.php` to `true`, you'll see site-wide and article specific entries in page source code wrapped to comments.
|
67 |
+
* **Multisite** is supported.
|
68 |
+
* **PHP 8** ready!
|
69 |
|
70 |
General settings (HEAD, BODY, FOOTER global code and priority, Homepage code and behaviour) saves in WordPress option `auhfc_settings`.
|
71 |
Each post/page/custom post type specific HEAD, BODY and FOOTER code and behaviour saves to post meta `_auhfc`.
|
72 |
+
Each category specific HEAD, BODY and FOOTER code and behaviour saves to taxonomy meta `_auhfc`.
|
73 |
This data deletes from the database on uninstall.
|
74 |
|
75 |
+
## Installation
|
76 |
|
77 |
Installation of the **Head & Footer Code** is easy as any other WordPress plugin.
|
78 |
|
79 |
+
### Standard procedure
|
80 |
|
81 |
1. In WordPress Dashboard go to **Plugins** → **Add New**.
|
82 |
1. Enter `head footer code` to the **Search plugins...** field and wait for the moment.
|
85 |
1. Click **Settings** link for **Head & Footer Code** or visit the **Tools** → **Head & Footer Code**.
|
86 |
1. Add the desired code to the target section.
|
87 |
|
88 |
+
### FTP procedure
|
89 |
|
90 |
1. Click on the **Download** button to get **Head & Footer Code** installation package.
|
91 |
1. Unpack archive **head-footer-code.zip** on local computer.
|
94 |
1. Click **Settings** link for **Head & Footer Code** or visit the **Tools** → **Head & Footer Code**.
|
95 |
1. Add the desired code to the target section.
|
96 |
|
97 |
+
## Frequently Asked Questions
|
98 |
|
99 |
+
### Is supported PHP code in code snippets?
|
100 |
|
101 |
As it's a security risk, the **Head & Footer Code** does not process PHP code if entered into any plugin field (global or article specific).
|
102 |
|
103 |
Any content added to HFC fields is printed on the front-end as is.
|
104 |
|
105 |
+
### I entered code to BODY section, but nothing outputs on front-end
|
106 |
|
107 |
This feature is implemented since WordPress version 5.2 and requires theme compatibility.
|
108 |
|
109 |
To make sure if theme you use supports [wp_body_open](https://developer.wordpress.org/reference/hooks/wp_body_open/) hook, open in code editor `header.php` file from theme you use, and check if right after opening `<BODY>` tag there is following code (if it does not exists, add it or ask some developer to do that for you):
|
110 |
|
111 |
+
```
|
112 |
+
if ( function_exists( 'wp_body_open' ) ) {
|
113 |
+
wp_body_open();
|
114 |
+
}
|
115 |
+
```
|
116 |
|
117 |
+
## Screenshots
|
118 |
|
119 |
1. Head & Footer Code box in Plugin search results
|
120 |
2. Plugin Settings page (Site-wide, Homepage and Article Post Types)
|
121 |
3. Article specific metabox
|
122 |
4. Example of custom code inserted to HEAD section (site-wide with appended article specific)
|
123 |
+
5. Example of custom code inserted to BODY and FOOTER sections (site-wide with appended article specific)
|
124 |
+
6. Category specific metabox
|
125 |
+
7. Example of custom code inserted to HEAD section (site-wide with appended category specific)
|
126 |
+
8. Example of custom code inserted to BODY and FOOTER section (site-wide with appended category specific)
|
127 |
+
9. Example of **Head & Footer Code** column on Pages listing, to identify which pages have set custom code, which one and what mode is selected
|
128 |
+
|
129 |
+
## Upgrade Notice
|
130 |
|
131 |
+
### 1.0.0
|
132 |
|
|
|
133 |
Initial release of new plugin developed by Aleksandar Urosevic.
|
134 |
|
135 |
+
## Changelog
|
136 |
+
|
137 |
+
### 1.3.0 (2022-05-08)
|
138 |
+
|
139 |
+
* Tested: on PHP 8.1.5 and WordPress 6.0-RC1 with Twenty Twenty-Two theme (Single and Multisite)
|
140 |
+
* Add: Support for Categotry specific code.
|
141 |
+
* Improve: Coding Standard.
|
142 |
+
* Improve: Important notes on settings page.
|
143 |
+
* Improve: README converted to MarkDown.
|
144 |
+
* Improve: Remove PayPal logo and load minified admin stylesheet.
|
145 |
+
|
146 |
+
### 1.2.4 (2021-10-15)
|
147 |
+
|
148 |
+
* Tested: on WordPress 5.8.1 and PHP 8.0.9 and 8.0.11
|
149 |
+
* Improve: clarify wihtin article metabox on how replace behaviour for article-specific code works
|
150 |
+
* (2021-08-23) Improve: along to FOOTER, enable processing of shortcodes in HEAD and BODY (you has to enable this opetion per location)
|
151 |
+
|
152 |
+
### 1.2.3 (2021-07-19)
|
153 |
|
|
|
154 |
* Tested: on WordPress 5.8-RC4 and PHP 8.0.8
|
155 |
* (2021-05-04) Fix: Notice errors Trying to get property 'post_type' of non-object in inc/front.php (thanks to @tekgirlymama)
|
156 |
* Improve: DRY for getting post type.
|
157 |
|
158 |
+
### 1.2.2 (2021-04-24)
|
159 |
+
|
160 |
* Tested: on WordPress 5.7.1
|
161 |
* (2021-02-01) Fix: Noice errors in update script (thanks to @swinggraphics)
|
162 |
* Improve: wording on post/page listing
|
163 |
|
164 |
+
### 1.2.1
|
165 |
+
|
166 |
* Add: Head & Footer Code column to post/page/custom post type listing to show if/what article specific custom code is defined
|
167 |
* Fix: in_array() expects parameter 2 to be array, null given in head-footer-code/inc/front.php on line 46, 111, and 176
|
168 |
|
169 |
+
### 1.2
|
170 |
+
|
171 |
* Add: custom head, body and footer code for Homepage in Blog Posts mode.
|
172 |
* Fix: Code Editor broken in WordPress 5.5 release.
|
173 |
* Fix: Invalid requests while saving settings https://github.com/urosevic/head-footer-code/issues/1
|
175 |
* Improve: translators tips for complex strings.
|
176 |
* Improve: all strings available to localize.
|
177 |
|
178 |
+
### 1.1.1
|
179 |
+
|
180 |
* Tested: on WordPress 5.4.1, 5.5-RC2-48768 with PHP 7.4.1
|
181 |
* Add: Video tutorial on how to install, configure and use Head & Footer Code plugin
|
182 |
|
183 |
+
### 1.1.0
|
184 |
+
|
185 |
* Tested: on WordPress 5.1.4, 5.3.2 and 5.4-beta3 with PHP 7.2.15 and 7.3.7
|
186 |
* Fix: Backslashes are removed on post/page update in article specific HEAD/BODY/FOOTER code reported by @asherber (`update_post_meta` pass key and value to `update_metadata` which expect them slashed key and value)
|
187 |
* Add: Support for `wp_body_open` Body hook introduced in WordPress 5.2
|
190 |
* Update: Links and wording on plugin settings page
|
191 |
* Update: Screenshots
|
192 |
|
193 |
+
### 1.0.9.1
|
194 |
+
|
195 |
* Fix: Fatal Error on Multisite WP's (thanks @kunzemarketing for reporting)
|
196 |
* Improve: DRI for front-end debugging
|
197 |
|
198 |
+
### 1.0.9
|
199 |
+
|
200 |
* Add: Descriptive post types and descriptions for article specific sections
|
201 |
* Add: Option to process shortcodes in FOOTER section (global setting for site-wide and article specific)
|
202 |
* Change: Separate priority for HEAD and FOOT so admin can choose different priorities for header and footer
|
204 |
* Add: Plugin activation hook to prevent fatal errors in case of legacy WP and/or PHP
|
205 |
* Improve: Loading security
|
206 |
|
207 |
+
### 1.0.8
|
208 |
+
|
209 |
* Test compatibility with WordPress 5.1.1 and PHP 7.2.15
|
210 |
* Change: Meta boxes layout and type of behavior selector
|
211 |
* Change: Convert Post metaboxes to OOP
|
213 |
* Add: Bundle GNU GPLv3 license to plugin codebase
|
214 |
* Update: Screenshots
|
215 |
|
216 |
+
### 1.0.7
|
217 |
* Compatibility check: Tested for WordPress 4.7.1
|
218 |
* UX: Add right hand sidebar on global settings page with links to donate, FAQ, Community support and plugin Reviews page.
|
219 |
* UX: Set monospaced font for textareas on global settings and article pages
|
220 |
|
221 |
+
### 1.0.6
|
222 |
+
|
223 |
* Fix: `PHP Notice: Trying to get property of non-object in \wp-content\plugins\head-footer-code\inc\front.php on line 41`.
|
224 |
* Fix: Overwrite footer content for post/page if post/page template after content have another WP Loop query (like recent posts WP Widget in RHS sidebar).
|
225 |
* Optimize: Avoid reading post meta if not singular or post type not enabled
|
226 |
* Tested in Multisite environment (main and other network websites) on WordPress v4.5-alpha-36504 and theme Twenty Sixteen v1.2-alpha.
|
227 |
|
228 |
+
### 1.0.5
|
229 |
+
|
230 |
* Enhance: Add uninstall routine to make some housekeeping on plugin removal.
|
231 |
* Enhance: Add post type in debug comments.
|
232 |
* Readme: Test on WordPress v4.4-beta1 and updated compatibility.
|
233 |
|
234 |
+
### 1.0.4
|
235 |
+
|
236 |
* Fix: PHP Warning: in_array() expects parameter 2 to be array, string given (introduced in v1.0.3)
|
237 |
|
238 |
+
### 1.0.3
|
239 |
+
|
240 |
* Change: Make even default WP post types `post` and `page` optional for page specific head/footer code
|
241 |
|
242 |
+
### 1.0.2
|
243 |
+
|
244 |
* Change: Replace PayPal donation links to prevent account limitations if plugin is used on website that violates PayPal's Acceptable Use Policy
|
245 |
|
246 |
+
### 1.0.1
|
247 |
+
|
248 |
* Fix: PHP Notice Trying to get property of non-object
|
249 |
* Optimize: Remove `attachment` post type from available to select as no reason to have custom head/footer code on attachments
|
250 |
* Optimize: Settings code cleanup
|
251 |
|
252 |
+
### 1.0.0
|
253 |
+
|
254 |
* Initial release.
|
templates/settings.php
CHANGED
@@ -1,19 +1,18 @@
|
|
1 |
<?php
|
2 |
-
// If this file is called directly, abort.
|
3 |
-
if ( ! defined( 'WPINC' ) ) {
|
4 |
-
die;
|
5 |
-
}
|
6 |
-
|
7 |
/**
|
8 |
* Head & Footer Code General Settings page template
|
9 |
*
|
10 |
* @category Template
|
11 |
-
* @package
|
12 |
* @author Aleksandar Urosevic
|
13 |
* @license https://www.gnu.org/copyleft/gpl-3.0.html GNU General Public License v3.0
|
14 |
* @link https://urosevic.net
|
15 |
*/
|
16 |
|
|
|
|
|
|
|
|
|
17 |
?>
|
18 |
<div class="wrap" id="head_footer_code_settings">
|
19 |
<h2><?php esc_html_e( 'Head & Footer Code', 'head-footer-code' ); ?></h2>
|
@@ -30,13 +29,29 @@ if ( ! defined( 'WPINC' ) ) {
|
|
30 |
</div><!-- .content_cell -->
|
31 |
|
32 |
<div class="sidebar_container">
|
33 |
-
<a href="https://urosevic.net/wordpress/donate/?donate_for=head-footer-code" class="auhfc-button paypal_donate" target="_blank"><?php _e( 'Donate', 'head-footer-code' ); ?></a>
|
34 |
-
<br />
|
35 |
<a href="https://wordpress.org/plugins/head-footer-code/#faq" class="auhfc-button" target="_blank"><?php _e( 'FAQ', 'head-footer-code' ); ?></a>
|
36 |
<br />
|
37 |
<a href="https://wordpress.org/support/plugin/head-footer-code/" class="auhfc-button" target="_blank"><?php _e( 'Community Support', 'head-footer-code' ); ?></a>
|
38 |
<br />
|
39 |
-
<a href="https://wordpress.org/support/plugin/head-footer-code/reviews/#new-post" class="auhfc-button" target="_blank"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
</div><!-- .sidebar_container -->
|
41 |
</div><!-- .head_footer_code_wrapper -->
|
42 |
</div>
|
@@ -46,4 +61,4 @@ jQuery(document).ready(function($) {
|
|
46 |
wp.codeEditor.initialize(this, cm_settings);
|
47 |
});
|
48 |
});
|
49 |
-
</script>
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Head & Footer Code General Settings page template
|
4 |
*
|
5 |
* @category Template
|
6 |
+
* @package Head_Footer_Code
|
7 |
* @author Aleksandar Urosevic
|
8 |
* @license https://www.gnu.org/copyleft/gpl-3.0.html GNU General Public License v3.0
|
9 |
* @link https://urosevic.net
|
10 |
*/
|
11 |
|
12 |
+
// If this file is called directly, abort.
|
13 |
+
if ( ! defined( 'WPINC' ) ) {
|
14 |
+
die;
|
15 |
+
}
|
16 |
?>
|
17 |
<div class="wrap" id="head_footer_code_settings">
|
18 |
<h2><?php esc_html_e( 'Head & Footer Code', 'head-footer-code' ); ?></h2>
|
29 |
</div><!-- .content_cell -->
|
30 |
|
31 |
<div class="sidebar_container">
|
|
|
|
|
32 |
<a href="https://wordpress.org/plugins/head-footer-code/#faq" class="auhfc-button" target="_blank"><?php _e( 'FAQ', 'head-footer-code' ); ?></a>
|
33 |
<br />
|
34 |
<a href="https://wordpress.org/support/plugin/head-footer-code/" class="auhfc-button" target="_blank"><?php _e( 'Community Support', 'head-footer-code' ); ?></a>
|
35 |
<br />
|
36 |
+
<a href="https://wordpress.org/support/plugin/head-footer-code/reviews/#new-post" class="auhfc-button" target="_blank">
|
37 |
+
<?php
|
38 |
+
printf(
|
39 |
+
/* translators: %s will be replaced with plugin name Head & Footer Code */
|
40 |
+
esc_html__( 'Review %s plugin', 'head-footer-code' ),
|
41 |
+
esc_html__( 'Head & Footer Code', 'head-footer-code' )
|
42 |
+
);
|
43 |
+
?>
|
44 |
+
</a>
|
45 |
+
<br />
|
46 |
+
<a href="https://urosevic.net/wordpress/donate/?donate_for=head-footer-code" class="auhfc-button paypal" target="_blank">
|
47 |
+
<?php
|
48 |
+
printf(
|
49 |
+
/* translators: %s: coloured PayPal */
|
50 |
+
esc_html__( 'Donate via %s', 'head-footer-code' ),
|
51 |
+
'<em><i>Pay</i><i>Pal</i></em>'
|
52 |
+
);
|
53 |
+
?>
|
54 |
+
</a>
|
55 |
</div><!-- .sidebar_container -->
|
56 |
</div><!-- .head_footer_code_wrapper -->
|
57 |
</div>
|
61 |
wp.codeEditor.initialize(this, cm_settings);
|
62 |
});
|
63 |
});
|
64 |
+
</script>
|
uninstall.php
CHANGED
@@ -1,32 +1,47 @@
|
|
1 |
<?php
|
2 |
-
// If this file is called directly, abort.
|
3 |
-
if ( ! defined( 'WPINC' ) ) {
|
4 |
-
die;
|
5 |
-
}
|
6 |
-
|
7 |
/**
|
|
|
|
|
8 |
* @link https://urosevic.net
|
9 |
* @since 1.0.5
|
10 |
* @package Head_Footer_Code
|
11 |
*/
|
12 |
|
13 |
-
// If
|
|
|
|
|
|
|
|
|
|
|
14 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
15 |
exit();
|
16 |
}
|
17 |
|
18 |
-
$auhfc_options =
|
19 |
'auhfc_settings',
|
20 |
'auhfc_settings_sitewide',
|
21 |
'auhfc_settings_homepage',
|
22 |
'auhfc_settings_article',
|
23 |
'auhfc_db_ver',
|
24 |
-
|
25 |
foreach ( $auhfc_options as $option_name ) {
|
26 |
-
// Delete option on single site
|
27 |
delete_option( $option_name );
|
28 |
}
|
29 |
|
30 |
-
// Delete post meta values
|
31 |
$post_meta_key = '_auhfc';
|
32 |
delete_post_meta_by_key( $post_meta_key );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
+
* Routine to fully uninstall Head & Footer Code plugin.
|
4 |
+
*
|
5 |
* @link https://urosevic.net
|
6 |
* @since 1.0.5
|
7 |
* @package Head_Footer_Code
|
8 |
*/
|
9 |
|
10 |
+
// If this file is called directly, abort.
|
11 |
+
if ( ! defined( 'WPINC' ) ) {
|
12 |
+
die;
|
13 |
+
}
|
14 |
+
|
15 |
+
// If uninstall is not called from WordPress, exit.
|
16 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
17 |
exit();
|
18 |
}
|
19 |
|
20 |
+
$auhfc_options = array(
|
21 |
'auhfc_settings',
|
22 |
'auhfc_settings_sitewide',
|
23 |
'auhfc_settings_homepage',
|
24 |
'auhfc_settings_article',
|
25 |
'auhfc_db_ver',
|
26 |
+
);
|
27 |
foreach ( $auhfc_options as $option_name ) {
|
28 |
+
// Delete option on single site.
|
29 |
delete_option( $option_name );
|
30 |
}
|
31 |
|
32 |
+
// Delete post meta values.
|
33 |
$post_meta_key = '_auhfc';
|
34 |
delete_post_meta_by_key( $post_meta_key );
|
35 |
+
|
36 |
+
// Delete category meta values.
|
37 |
+
$category_meta_key = '_auhfc';
|
38 |
+
$auhfc_category_ids = get_terms(
|
39 |
+
array(
|
40 |
+
'taxonomy' => 'category',
|
41 |
+
'fields' => 'ids',
|
42 |
+
'meta_key' => $category_meta_key,
|
43 |
+
)
|
44 |
+
);
|
45 |
+
foreach ( $auhfc_category_ids as $category_id ) {
|
46 |
+
$ret = delete_term_meta( $category_id, $category_meta_key );
|
47 |
+
}
|