first commit
This commit is contained in:
@@ -0,0 +1,292 @@
|
||||
<?php
|
||||
|
||||
namespace PixelYourSite;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class HeadFooter extends Settings {
|
||||
|
||||
private static $_instance;
|
||||
|
||||
private $is_mobile;
|
||||
|
||||
public static function instance() {
|
||||
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self();
|
||||
}
|
||||
|
||||
return self::$_instance;
|
||||
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct( 'head_footer' );
|
||||
|
||||
$this->locateOptions(
|
||||
PYS_FREE_PATH . '/modules/head_footer/options_fields.json',
|
||||
PYS_FREE_PATH . '/modules/head_footer/options_defaults.json'
|
||||
);
|
||||
|
||||
add_action( 'pys_register_plugins', function( $core ) {
|
||||
/** @var PYS $core */
|
||||
$core->registerPlugin( $this );
|
||||
} );
|
||||
|
||||
if ( $this->getOption( 'enabled' ) ) {
|
||||
add_action( 'add_meta_boxes', array( $this, 'register_meta_box' ) );
|
||||
add_action( 'save_post', array( $this, 'save_meta_box' ) );
|
||||
}
|
||||
|
||||
if ( $this->getOption( 'enabled' ) ) {
|
||||
add_action( 'template_redirect', array( $this, 'output_scripts' ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register meta box for each public post type.
|
||||
*/
|
||||
public function register_meta_box() {
|
||||
|
||||
if ( current_user_can( 'manage_pys' ) ) {
|
||||
|
||||
$screens = get_post_types( array( 'public' => true ) );
|
||||
|
||||
foreach ( $screens as $screen ) {
|
||||
add_meta_box( 'pys-head-footer', 'PixelYourSite Head & Footer Scripts',
|
||||
array( $this, 'render_meta_box' ),
|
||||
$screen );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function render_meta_box() {
|
||||
include 'views/html-meta-box.php';
|
||||
}
|
||||
|
||||
public function save_meta_box( $post_id ) {
|
||||
|
||||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'manage_pys' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! isset( $_POST['pys_head_footer'] ) ) {
|
||||
// delete_post_meta( $post_id, '_pys_head_footer' );
|
||||
return;
|
||||
}
|
||||
|
||||
$data = $_POST['pys_head_footer'];
|
||||
|
||||
$meta = array(
|
||||
'disable_global' => isset( $data['disable_global'] ) ? true : false,
|
||||
'head_any' => isset( $data['head_any'] ) ? trim( $data['head_any'] ) : '',
|
||||
'head_desktop' => isset( $data['head_desktop'] ) ? trim( $data['head_desktop'] ) : '',
|
||||
'head_mobile' => isset( $data['head_mobile'] ) ? trim( $data['head_mobile'] ) : '',
|
||||
'footer_any' => isset( $data['footer_any'] ) ? trim( $data['footer_any'] ) : '',
|
||||
'footer_desktop' => isset( $data['footer_desktop'] ) ? trim( $data['footer_desktop'] ) : '',
|
||||
'footer_mobile' => isset( $data['footer_mobile'] ) ? trim( $data['footer_mobile'] ) : '',
|
||||
);
|
||||
|
||||
update_post_meta( $post_id, '_pys_head_footer', $meta );
|
||||
|
||||
}
|
||||
|
||||
public function output_scripts() {
|
||||
global $post;
|
||||
|
||||
if ( is_admin() || defined( 'DOING_AJAX' ) || defined( 'DOING_CRON' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->is_mobile = wp_is_mobile();
|
||||
|
||||
/**
|
||||
* WooCommerce Order Received page
|
||||
*/
|
||||
|
||||
if ( isWooCommerceActive() && is_order_received_page() ) {
|
||||
add_action( 'wp_head', array( $this, 'output_head_woo_order_received' ) );
|
||||
add_action( 'wp_footer', array( $this, 'output_footer_woo_order_received' ) );
|
||||
}
|
||||
|
||||
$disabled_by_woo = isWooCommerceActive() && is_order_received_page() &&
|
||||
$this->getOption( 'woo_order_received_disable_global' );
|
||||
|
||||
if ( $disabled_by_woo ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Single Post
|
||||
*/
|
||||
|
||||
if ( is_singular() && $post ) {
|
||||
$post_meta = get_post_meta( $post->ID, '_pys_head_footer', true );
|
||||
} else {
|
||||
$post_meta = array();
|
||||
}
|
||||
|
||||
if ( ! empty( $post_meta ) ) {
|
||||
add_action( 'wp_head', array( $this, 'output_head_post' ) );
|
||||
add_action( 'wp_footer', array( $this, 'output_footer_post' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Global
|
||||
*/
|
||||
|
||||
$disabled_by_post = ! empty( $post_meta ) && isset($post_meta['disable_global']) && $post_meta['disable_global'];
|
||||
|
||||
if ( ! $disabled_by_post ) {
|
||||
add_action( 'wp_head', array( $this, 'output_head_global' ) );
|
||||
add_action( 'wp_footer', array( $this, 'output_footer_global' ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function output_head_woo_order_received() {
|
||||
|
||||
$scripts_any = $this->getOption( 'woo_order_received_head_any' );
|
||||
|
||||
if ( $scripts_any ) {
|
||||
echo "\r\n{$scripts_any}\r\n";
|
||||
}
|
||||
|
||||
if ( $this->is_mobile ) {
|
||||
$scripts_by_device = $this->getOption( 'woo_order_received_head_mobile' );
|
||||
} else {
|
||||
$scripts_by_device = $this->getOption( 'woo_order_received_head_desktop' );
|
||||
}
|
||||
|
||||
if ( $scripts_by_device ) {
|
||||
echo "\r\n{$scripts_by_device}\r\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function output_footer_woo_order_received() {
|
||||
|
||||
$scripts_any = $this->getOption( 'woo_order_received_footer_any' );
|
||||
|
||||
if ( $scripts_any ) {
|
||||
echo "\r\n{$scripts_any}\r\n";
|
||||
}
|
||||
|
||||
if ( $this->is_mobile ) {
|
||||
$scripts_by_device = $this->getOption( 'woo_order_received_footer_mobile' );
|
||||
} else {
|
||||
$scripts_by_device = $this->getOption( 'woo_order_received_footer_desktop' );
|
||||
}
|
||||
|
||||
if ( $scripts_by_device ) {
|
||||
echo "\r\n{$scripts_by_device}\r\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function output_head_global() {
|
||||
|
||||
$scripts_any = $this->getOption( 'head_any' );
|
||||
|
||||
if ( $scripts_any ) {
|
||||
echo "\r\n{$scripts_any}\r\n";
|
||||
}
|
||||
|
||||
if ( $this->is_mobile ) {
|
||||
$scripts_by_device = $this->getOption( 'head_mobile' );
|
||||
} else {
|
||||
$scripts_by_device = $this->getOption( 'head_desktop' );
|
||||
}
|
||||
|
||||
if ( $scripts_by_device ) {
|
||||
echo "\r\n{$scripts_by_device}\r\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function output_footer_global() {
|
||||
|
||||
$scripts_any = $this->getOption( 'footer_any' );
|
||||
|
||||
if ( $scripts_any ) {
|
||||
echo "\r\n{$scripts_any}\r\n";
|
||||
}
|
||||
|
||||
if ( $this->is_mobile ) {
|
||||
$scripts_by_device = $this->getOption( 'footer_mobile' );
|
||||
} else {
|
||||
$scripts_by_device = $this->getOption( 'footer_desktop' );
|
||||
}
|
||||
|
||||
if ( $scripts_by_device ) {
|
||||
echo "\r\n{$scripts_by_device}\r\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function output_head_post() {
|
||||
global $post;
|
||||
|
||||
$post_meta = get_post_meta( $post->ID, '_pys_head_footer', true );
|
||||
|
||||
$scripts_any = isset( $post_meta['head_any'] ) ? $post_meta['head_any'] : false;
|
||||
|
||||
if ( $scripts_any ) {
|
||||
echo "\r\n{$scripts_any}\r\n";
|
||||
}
|
||||
|
||||
if ( $this->is_mobile ) {
|
||||
$scripts_by_device = isset( $post_meta['head_mobile'] ) ? $post_meta['head_mobile'] : false;
|
||||
} else {
|
||||
$scripts_by_device = isset( $post_meta['head_desktop'] ) ? $post_meta['head_desktop'] : false;
|
||||
}
|
||||
|
||||
if ( $scripts_by_device ) {
|
||||
echo "\r\n{$scripts_by_device}\r\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function output_footer_post() {
|
||||
global $post;
|
||||
|
||||
$post_meta = get_post_meta( $post->ID, '_pys_head_footer', true );
|
||||
|
||||
$scripts_any = isset( $post_meta['footer_any'] ) ? $post_meta['footer_any'] : false;
|
||||
|
||||
if ( $scripts_any ) {
|
||||
echo "\r\n{$scripts_any}\r\n";
|
||||
}
|
||||
|
||||
if ( $this->is_mobile ) {
|
||||
$scripts_by_device = isset( $post_meta['footer_mobile'] ) ? $post_meta['footer_mobile'] : false;
|
||||
} else {
|
||||
$scripts_by_device = isset( $post_meta['footer_desktop'] ) ? $post_meta['footer_desktop'] : false;
|
||||
}
|
||||
|
||||
if ( $scripts_by_device ) {
|
||||
echo "\r\n{$scripts_by_device}\r\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HeadFooter
|
||||
*/
|
||||
function HeadFooter() {
|
||||
return HeadFooter::instance();
|
||||
}
|
||||
|
||||
HeadFooter();
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"enabled": true,
|
||||
"head_any" : "",
|
||||
"head_desktop" : "",
|
||||
"head_mobile" : "",
|
||||
"footer_any" : "",
|
||||
"footer_desktop" : "",
|
||||
"footer_mobile" : "",
|
||||
"woo_order_received_disable_global" : false,
|
||||
"woo_order_received_head_any" : "",
|
||||
"woo_order_received_head_desktop" : "",
|
||||
"woo_order_received_head_mobile" : "",
|
||||
"woo_order_received_footer_any" : "",
|
||||
"woo_order_received_footer_desktop" : "",
|
||||
"woo_order_received_footer_mobile" : ""
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"enabled": "checkbox",
|
||||
"head_any": "textarea",
|
||||
"head_desktop": "textarea",
|
||||
"head_mobile": "textarea",
|
||||
"footer_any": "textarea",
|
||||
"footer_desktop": "textarea",
|
||||
"footer_mobile": "textarea",
|
||||
"woo_order_received_disable_global": "checkbox",
|
||||
"woo_order_received_head_any": "textarea",
|
||||
"woo_order_received_head_desktop": "textarea",
|
||||
"woo_order_received_head_mobile": "textarea",
|
||||
"woo_order_received_footer_any": "textarea",
|
||||
"woo_order_received_footer_desktop": "textarea",
|
||||
"woo_order_received_footer_mobile": "textarea"
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
namespace PixelYourSite;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<h2 class="section-title">Head and Footer Settings</h2>
|
||||
|
||||
<!-- General -->
|
||||
<div class="card card-static">
|
||||
<div class="card-header">
|
||||
General
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<?php HeadFooter()->render_switcher_input( 'enabled' ); ?>
|
||||
<h4 class="switcher-label">Enable Head and Footer</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Header Scripts -->
|
||||
<div class="card card-static">
|
||||
<div class="card-header">
|
||||
Head Scripts
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row form-group">
|
||||
<div class="col">
|
||||
<h4 class="label">Any device type:</h4>
|
||||
<?php HeadFooter()->render_text_area_input( 'head_any' ); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row form-group">
|
||||
<div class="col">
|
||||
<h4 class="label">Desktop Only:</h4>
|
||||
<?php HeadFooter()->render_text_area_input( 'head_desktop' ); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h4 class="label">Mobile Only:</h4>
|
||||
<?php HeadFooter()->render_text_area_input( 'head_mobile' ); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Footer Scripts -->
|
||||
<div class="card card-static">
|
||||
<div class="card-header">
|
||||
Footer Scripts
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row form-group">
|
||||
<div class="col">
|
||||
<h4 class="label">Any device type:</h4>
|
||||
<?php HeadFooter()->render_text_area_input( 'footer_any' ); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row form-group">
|
||||
<div class="col">
|
||||
<h4 class="label">Desktop Only:</h4>
|
||||
<?php HeadFooter()->render_text_area_input( 'footer_desktop' ); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h4 class="label">Mobile Only:</h4>
|
||||
<?php HeadFooter()->render_text_area_input( 'footer_mobile' ); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if( isWooCommerceActive() ) : ?>
|
||||
|
||||
<h2 class="section-title">WooCommerce Order Received Page Scripts</h2>
|
||||
|
||||
<!-- <p>Insert any script on the WooCommerce Thank You Page (order-received).</p>-->
|
||||
|
||||
<div class="card card-static">
|
||||
<div class="card-header">
|
||||
General
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<?php HeadFooter()->render_switcher_input( 'woo_order_received_disable_global' ); ?>
|
||||
<h4 class="switcher-label">Disable global head and footer scripts on Order Received page</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card card-static">
|
||||
<div class="card-header">
|
||||
Head Scripts
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row form-group">
|
||||
<div class="col">
|
||||
<h4 class="label">Any device type:</h4>
|
||||
<?php HeadFooter()->render_text_area_input( 'woo_order_received_head_any' ); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row form-group">
|
||||
<div class="col">
|
||||
<h4 class="label">Desktop Only:</h4>
|
||||
<?php HeadFooter()->render_text_area_input( 'woo_order_received_head_desktop' ); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h4 class="label">Mobile Only:</h4>
|
||||
<?php HeadFooter()->render_text_area_input( 'woo_order_received_head_mobile' ); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card card-static">
|
||||
<div class="card-header">
|
||||
Footer Scripts
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row form-group">
|
||||
<div class="col">
|
||||
<h4 class="label">Any device type:</h4>
|
||||
<?php HeadFooter()->render_text_area_input( 'woo_order_received_footer_any' ); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row form-group">
|
||||
<div class="col">
|
||||
<h4 class="label">Desktop Only:</h4>
|
||||
<?php HeadFooter()->render_text_area_input( 'woo_order_received_footer_desktop' ); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h4 class="label">Mobile Only:</h4>
|
||||
<?php HeadFooter()->render_text_area_input( 'woo_order_received_footer_mobile' ); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<h2 class="section-title">Replacements <?php renderHfBadge(); ?></h2>
|
||||
|
||||
<div class="panel">
|
||||
<div class="row">
|
||||
<div class="col text-secondary">
|
||||
<?php include 'html-variables-help.php'; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-4">
|
||||
<button class="btn btn-block btn-save">Save Settings</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace PixelYourSite;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
global $post;
|
||||
|
||||
$meta = get_post_meta( $post->ID, '_pys_head_footer', true );
|
||||
|
||||
if ( ! is_array( $meta ) ) {
|
||||
|
||||
$meta = array(
|
||||
'disable_global' => false,
|
||||
'head_any' => '',
|
||||
'head_desktop' => '',
|
||||
'head_mobile' => '',
|
||||
'footer_any' => '',
|
||||
'footer_desktop' => '',
|
||||
'footer_mobile' => '',
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<style type="text/css">
|
||||
.pys-head-footer label {
|
||||
display: block;
|
||||
margin-top: 15px;
|
||||
margin-bottom: 5px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.pys-head-footer textarea {
|
||||
width: 100%;
|
||||
font-family: monospace;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="pys-head-footer">
|
||||
<p>Add any script in the Head or Footer section of your pages. You can also add custom per page scripts
|
||||
by editing each page.</p>
|
||||
</div>
|
||||
|
||||
<div class="pys-head-footer" style="margin: 15px 0;">
|
||||
<label for="pys_head_footer_disable_global" style="font-weight: normal;">
|
||||
<input name="pys_head_footer[disable_global]"
|
||||
type="checkbox"
|
||||
<?php checked( $meta['disable_global'] ); ?>
|
||||
id="pys_head_footer_disable_global"
|
||||
value="1"> Disable <a href="<?php echo admin_url( 'admin.php?page=pixelyoursite&tab=head_footer' ); ?>"
|
||||
target="_blank">global</a> head and footer scripts.
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="pys-head-footer">
|
||||
|
||||
<label for="pys_head_footer_head_any" class="control-label">Head (any device type):</label>
|
||||
<textarea name="pys_head_footer[head_any]" id="pys_head_footer_head_any"
|
||||
rows="10"><?php @esc_html_e( $meta['head_any'] ); ?></textarea>
|
||||
|
||||
<label for="pys_head_footer_head_desktop" class="control-label">Head - Desktop Only:</label>
|
||||
<textarea name="pys_head_footer[head_desktop]" id="pys_head_footer_head_desktop"
|
||||
rows="5"><?php @esc_html_e( $meta['head_desktop'] ); ?></textarea>
|
||||
|
||||
<label for="pys_head_footer_head_mobile" class="control-label">Head - Mobile Only:</label>
|
||||
<textarea name="pys_head_footer[head_mobile]" id="pys_head_footer_head_mobile"
|
||||
rows="5"><?php @esc_html_e( $meta['head_mobile'] ); ?></textarea>
|
||||
|
||||
<hr style="margin-top: 15px;">
|
||||
|
||||
<label for="pys_head_footer_footer_any" class="control-label">Footer (any device type):</label>
|
||||
<textarea name="pys_head_footer[footer_any]" id="pys_head_footer_footer_any"
|
||||
rows="10"><?php @esc_html_e( $meta['footer_any'] ); ?></textarea>
|
||||
|
||||
<label for="pys_head_footer_footer_desktop" class="control-label">Footer - Desktop Only:</label>
|
||||
<textarea name="pys_head_footer[footer_desktop]" id="pys_head_footer_footer_desktop"
|
||||
rows="5"><?php @esc_html_e( $meta['footer_desktop'] ); ?></textarea>
|
||||
|
||||
<label for="pys_head_footer_footer_mobile" class="control-label">Footer - Mobile Only:</label>
|
||||
<textarea name="pys_head_footer[footer_mobile]" id="pys_head_footer_footer_mobile"
|
||||
rows="5"><?php @esc_html_e( $meta['footer_mobile'] ); ?></textarea>
|
||||
|
||||
<hr style="margin-top: 15px;">
|
||||
|
||||
<?php include 'html-variables-help.php'; ?>
|
||||
|
||||
</div>
|
||||
|
||||
<script type="application/javascript">
|
||||
// collapse meta box by default
|
||||
jQuery('#pys-head-footer').addClass('closed');
|
||||
</script>
|
||||
@@ -0,0 +1,17 @@
|
||||
<p>You can use the following variables:</p>
|
||||
<ul>
|
||||
<li><code>[id]</code> - content ID</li>
|
||||
<li><code>[title]</code> - content title</li>
|
||||
<li><code>[categories]</code> - content categories</li>
|
||||
<li><code>[email]</code> - user's email</li>
|
||||
<li><code>[first_name]</code> - user's first name</li>
|
||||
<li><code>[last_name]</code> - user's last name</li>
|
||||
</ul>
|
||||
|
||||
<p>For the WooCommerce or Easy Digital Downloads Thank You Pages only:</p>
|
||||
<ul>
|
||||
<li><code>[order_number]</code> - order number</li>
|
||||
<li><code>[order_subtotal]</code> - order subtotal</li>
|
||||
<li><code>[order_total]</code> - order total</li>
|
||||
<li><code>[currency]</code> - currency</li>
|
||||
</ul>
|
||||
Reference in New Issue
Block a user