PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.0.5
Adminify – White Label, Admin Menu Editor, Login Customizer v3.0.5
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Modules / CustomHeaderFooter / CustomHeaderFooter.php

CustomHeaderFooter.php in Adminify – White Label, Admin Menu Editor, Login Customizer 3.0.5, at Inc/Modules/CustomHeaderFooter/CustomHeaderFooter.php

161 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPAdminify\Inc\Modules\CustomHeaderFooter;
4
5 use WPAdminify\Inc\Utils ;
6 use WPAdminify\Inc\Modules\CustomHeaderFooter\CustomHeaderFooterModel ;
7 // no direct access allowed
8 if ( !defined( 'ABSPATH' ) ) {
9 exit;
10 }
11 /**
12 * WPAdminify
13 *
14 * @package Custom CSS/JS
15 *
16 * @author Jewel Theme <support@jeweltheme.com>
17 */
18 class CustomHeaderFooter extends CustomHeaderFooterModel
19 {
20 public $url ;
21 public function __construct()
22 {
23
24 if ( is_multisite() && is_network_admin() ) {
25 return;
26 // only display to network admin if multisite is enbaled
27 }
28
29 $this->url = WP_ADMINIFY_URL . 'Inc/Modules/CustomHeaderFooter';
30 $this->options = ( new CustomHeaderFooterSettings() )->get();
31 $this->options = ( !empty($this->options['custom_scripts']) ? $this->options['custom_scripts'] : '' );
32 if ( is_admin() ) {
33 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
34 }
35 add_action( 'wp_head', [ $this, 'adminify_header_scripts' ], 9999 );
36 add_action( 'wp_footer', [ $this, 'adminify_footer_scripts' ], 9999 );
37 add_action( 'the_content', [ $this, 'adminify_content_scripts' ] );
38 }
39
40 // Add Header Scripts
41 public function adminify_header_scripts()
42 {
43 $this->adminify_custom_css_js_script( 'header' );
44 }
45
46 // Add Footer Scripts
47 public function adminify_footer_scripts()
48 {
49 $this->adminify_custom_css_js_script( 'footer' );
50 }
51
52 // Add Footer Scripts
53 public function adminify_content_scripts( $content )
54 {
55 return $this->adminify_custom_css_js_script( false, $content );
56 }
57
58 /**
59 * Render Snippet
60 *
61 * @param [since] 1.0.0
62 *
63 * @return void
64 */
65 public function render_snippet( $value )
66 {
67 // $device_display = wp_is_mobile() ? 'desktop' : 'mobile';
68
69 if ( $value['script_type'] == 'css' ) {
70
71 if ( !empty($value['custom_css']) ) {
72 $stat_tag = '/<style>/m';
73 $end_tag = '#</style>#m';
74 $result_start = preg_match( $stat_tag, $value['custom_css'] );
75 $result_end = preg_match( $end_tag, $value['custom_css'] );
76 echo "\n<!-- Start of WP Adminify Custom CSS - Snippet#{$value['title']} -->\n" ;
77 echo ( !$result_start && !$result_end ? '<style>' : '' ) ;
78 echo wp_kses_post( "\n{$value['custom_css']}\n" ) ;
79 echo ( !$result_start && !$result_end ? '</style>' : '' ) ;
80 echo "\n<!-- /End of WP Adminify Custom CSS -->\n" ;
81 }
82
83 } elseif ( $value['script_type'] === 'js' ) {
84
85 if ( !empty($value['custom_js']) ) {
86 $stat_tag = '/<script>/m';
87 $end_tag = '#</script>#m';
88 $result_start = preg_match( $stat_tag, $value['custom_js'] );
89 $result_end = preg_match( $end_tag, $value['custom_js'] );
90 echo wp_kses_post( "\n<!-- Start of WP Adminify Custom JS - Snippet#{$value['title']} -->\n" ) ;
91 echo ( !$result_start && !$result_end ? '<script>' : '' ) ;
92 echo wp_kses_post( "\n{$value['custom_js']}\n" ) ;
93 echo ( !$result_start && !$result_end ? '</script>' : '' ) ;
94 echo "\n<!-- /End of WP Adminify Custom JS -->\n" ;
95 }
96
97 }
98
99 }
100
101 /**
102 * Add Snippet
103 *
104 * @return void
105 */
106 public function adminify_custom_css_js_script( $location = '', $content = '' )
107 {
108 $options = $this->options;
109 $before_content = '';
110 $after_content = '';
111 if ( !empty($options) ) {
112 foreach ( $options as $key => $value ) {
113 $output = '';
114 if ( $value['location'] === $location ) {
115 switch ( $value['display_on'] ) {
116 case 'full_site':
117 $output = $this->render_snippet( $value );
118 break;
119 case 's_posts':
120 break;
121 case 's_pages':
122 break;
123 case 's_categories':
124 break;
125 case 's_custom_posts':
126 break;
127 case 's_tags':
128 break;
129 }
130 }
131 }
132 }
133 return $before_content . $content . $after_content;
134 }
135
136 /**
137 * Scripts/Styles
138 */
139 public function enqueue_scripts()
140 {
141 global $pagenow ;
142 // Load Scripts/Styles only WP Adminify Custom CSS/JS Page
143 if ( 'admin.php' === $pagenow && 'adminify-custom-css-js' === $_GET['page'] ) {
144 $this->header_footer_admin_script();
145 }
146 }
147
148 // WP Adminify Custom CSS/JS Page Style
149 public function header_footer_admin_script()
150 {
151 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;}
152
153 /* If needed for white top-bar */
154 .adminify-custom-css-js .adminify-header-inner {
155 background-color: #fafafa !important;
156 border-bottom: 1px solid #f5f5f5;
157 }
158 </style>' ;
159 }
160
161 }