| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\Modules\CustomHeaderFooter; |
| 4 |
|
| 5 |
use WPAdminify\Inc\Utils; |
| 6 |
use WPAdminify\Inc\Modules\CustomHeaderFooter\CustomHeaderFooterModel; |
| 7 |
|
| 8 |
// no direct access allowed |
| 9 |
if (!defined('ABSPATH')) exit; |
| 10 |
|
| 11 |
/** |
| 12 |
* WPAdminify |
| 13 |
* @package Custom CSS/JS |
| 14 |
* |
| 15 |
* @author Jewel Theme <support@jeweltheme.com> |
| 16 |
*/ |
| 17 |
|
| 18 |
class CustomHeaderFooter extends CustomHeaderFooterModel |
| 19 |
{ |
| 20 |
public $url; |
| 21 |
public function __construct() |
| 22 |
{ |
| 23 |
|
| 24 |
$this->url = WP_ADMINIFY_URL . 'Inc/Modules/CustomHeaderFooter'; |
| 25 |
$this->options = (new CustomHeaderFooterSettings())->get(); |
| 26 |
$this->options = !empty($this->options['custom_scripts']) ? $this->options['custom_scripts'] : ''; |
| 27 |
|
| 28 |
if (is_admin()) { |
| 29 |
add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts']); |
| 30 |
} |
| 31 |
|
| 32 |
add_action('wp_head', [$this, 'adminify_header_scripts'], 9999); |
| 33 |
add_action('wp_footer', [$this, 'adminify_footer_scripts'], 9999); |
| 34 |
add_action('the_content', [$this, 'adminify_content_scripts']); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
// Add Header Scripts |
| 39 |
public function adminify_header_scripts() |
| 40 |
{ |
| 41 |
$this->adminify_custom_css_js_script('header'); |
| 42 |
} |
| 43 |
|
| 44 |
// Add Footer Scripts |
| 45 |
public function adminify_footer_scripts() |
| 46 |
{ |
| 47 |
$this->adminify_custom_css_js_script('footer'); |
| 48 |
} |
| 49 |
|
| 50 |
// Add Footer Scripts |
| 51 |
public function adminify_content_scripts($content) |
| 52 |
{ |
| 53 |
return $this->adminify_custom_css_js_script(false, $content); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Render Snippet |
| 58 |
* |
| 59 |
* @param [since] 1.0.0 |
| 60 |
* |
| 61 |
* @return void |
| 62 |
*/ |
| 63 |
public function render_snippet($value) |
| 64 |
{ |
| 65 |
// $device_display = wp_is_mobile() ? 'desktop' : 'mobile'; |
| 66 |
|
| 67 |
if ($value['script_type'] == 'css') { |
| 68 |
echo "\n<!-- Start of WP Adminify Custom CSS - Snippet#{$value['title']} -->\n"; |
| 69 |
echo '<style>'; |
| 70 |
echo "\n{$value['custom_css']}\n"; |
| 71 |
echo '</style>'; |
| 72 |
echo "\n<!-- /End of WP Adminify Custom CSS -->\n"; |
| 73 |
} elseif ($value['script_type'] === 'js') { |
| 74 |
echo "\n<!-- Start of WP Adminify Custom JS - Snippet#{$value['title']} -->\n"; |
| 75 |
echo '<script>'; |
| 76 |
echo "\n{$value['custom_js']}\n"; |
| 77 |
echo '</script>'; |
| 78 |
echo "\n<!-- /End of WP Adminify Custom JS -->\n"; |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Add Snippet |
| 84 |
* |
| 85 |
* @return void |
| 86 |
*/ |
| 87 |
public function adminify_custom_css_js_script($location = '', $content = '') |
| 88 |
{ |
| 89 |
$options = $this->options; |
| 90 |
$before_content = ''; |
| 91 |
$after_content = ''; |
| 92 |
|
| 93 |
if (!empty($options)) { |
| 94 |
foreach ($options as $key => $value) { |
| 95 |
$output = ''; |
| 96 |
if ($value['location'] === $location) { |
| 97 |
switch ($value['display_on']) { |
| 98 |
case 'full_site': |
| 99 |
$output = $this->render_snippet($value); |
| 100 |
break; |
| 101 |
|
| 102 |
case 's_posts': |
| 103 |
if (jltwp_adminify()->can_use_premium_code__premium_only()) { |
| 104 |
if (isset($value['custom_posts']) && $value['custom_posts']) { |
| 105 |
$output = is_single($value['custom_posts']) ? $this->render_snippet($value) : ''; |
| 106 |
} |
| 107 |
} |
| 108 |
break; |
| 109 |
|
| 110 |
case 's_pages': |
| 111 |
if (jltwp_adminify()->can_use_premium_code__premium_only()) { |
| 112 |
if (isset($value['custom_pages']) && $value['custom_pages']) { |
| 113 |
if (is_page($value['custom_pages']) || (!is_front_page() && is_home())) { |
| 114 |
$output = $this->render_snippet($value); |
| 115 |
} elseif (is_page($value['custom_pages'])) { |
| 116 |
$output = $this->render_snippet($value); |
| 117 |
} |
| 118 |
} |
| 119 |
} |
| 120 |
break; |
| 121 |
|
| 122 |
case 's_categories': |
| 123 |
if (jltwp_adminify()->can_use_premium_code__premium_only()) { |
| 124 |
if (isset($value['custom_category']) && $value['custom_category']) { |
| 125 |
if ((is_category($value['custom_category'])) && (!is_archive() && !is_home())) { |
| 126 |
$output = $this->render_snippet($value); |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
break; |
| 131 |
|
| 132 |
case 's_custom_posts': |
| 133 |
if (jltwp_adminify()->can_use_premium_code__premium_only()) { |
| 134 |
if (isset($value['custom_post_types']) && $value['custom_post_types']) { |
| 135 |
$output = is_singular($value['custom_post_types']) ? $this->render_snippet($value) : ''; |
| 136 |
} |
| 137 |
} |
| 138 |
break; |
| 139 |
|
| 140 |
case 's_tags': |
| 141 |
if (jltwp_adminify()->can_use_premium_code__premium_only()) { |
| 142 |
if (isset($value['custom_tags']) && $value['custom_tags']) { |
| 143 |
if (has_tag($value['custom_tags'])) { |
| 144 |
if (is_tag($value['custom_tags'])) { |
| 145 |
$output = $this->render_snippet($value); |
| 146 |
} |
| 147 |
if (!is_archive() && !is_home()) { |
| 148 |
$output = $this->render_snippet($value); |
| 149 |
} |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
break; |
| 154 |
} |
| 155 |
|
| 156 |
if (jltwp_adminify()->can_use_premium_code__premium_only()) { |
| 157 |
switch ($value['location'] === $location) { |
| 158 |
case 'before_content': |
| 159 |
$before_content .= $output; |
| 160 |
break; |
| 161 |
case 'after_content': |
| 162 |
$after_content .= $output; |
| 163 |
break; |
| 164 |
default: |
| 165 |
echo $output; |
| 166 |
} |
| 167 |
} |
| 168 |
} |
| 169 |
} |
| 170 |
} |
| 171 |
return $before_content . $content . $after_content; |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
/** |
| 176 |
* Scripts/Styles |
| 177 |
*/ |
| 178 |
public function enqueue_scripts() |
| 179 |
{ |
| 180 |
global $pagenow; |
| 181 |
|
| 182 |
// Load Scripts/Styles only WP Adminify Custom CSS/JS Page |
| 183 |
if (('admin.php' === $pagenow) && ('adminify-custom-css-js' === $_GET['page'])) { |
| 184 |
$this->header_footer_admin_script(); |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
// WP Adminify Custom CSS/JS Page Style |
| 189 |
public function header_footer_admin_script() |
| 190 |
{ |
| 191 |
echo '<style>.wp-adminify-custom-css-js .adminify-container{ max-width:60%; margin:0 auto;} .wp-adminify-custom-css-js .adminify-header-inner{padding:0;}.wp-adminify-custom-css-js .adminify-field-subheading{font-size:20px; padding-left:0;}.adminify-custom-css-js .adminify-nav,.adminify-custom-css-js .adminify-search,.adminify-custom-css-js .adminify-footer,.adminify-custom-css-js .adminify-reset-all,.adminify-custom-css-js .adminify-expand-all,.adminify-custom-css-js .adminify-header-left,.adminify-custom-css-js .adminify-reset-section,.adminify-custom-css-js .adminify-nav-background{display: none !important;}.adminify-custom-css-js .adminify-nav-normal + .adminify-content{margin-left: 0;} |
| 192 |
|
| 193 |
/* If needed for white top-bar */ |
| 194 |
.adminify-custom-css-js .adminify-header-inner { |
| 195 |
background-color: #fafafa !important; |
| 196 |
border-bottom: 1px solid #f5f5f5; |
| 197 |
} |
| 198 |
</style>'; |
| 199 |
} |
| 200 |
} |
| 201 |
|