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 7.6.8 7.6.9 7.7.0 7.8.0 7.8.1 7.8.10 7.8.11 7.8.12 7.8.13 7.8.14 7.8.15 7.8.16 7.8.17 7.8.18 7.8.2 7.8.3 7.8.4 7.8.5 7.8.5.1 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1 7.9.10 7.9.11 7.9.2 7.9.3 7.9.4 7.9.5 7.9.6 7.9.7 7.9.8 7.9.9 8.0.0 8.0.1 8.0.2 8.0.3 8.0.4 8.0.5 8.0.6 8.0.7 8.0.8 8.1.0 8.1.1 8.1.2 8.1.3 8.1.4 8.2.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.2.0 3.3.0 3.4.0 3.5.0 3.6.1 3.7.0 3.8.0 3.9.0 3.9.1 3.9.2 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.9.0 4.9.1 4.9.2 4.9.3 5.0.0
admin-site-enhancements / classes / class-custom-code.php
admin-site-enhancements / classes Last commit date
class-activation.php 2 years ago class-admin-interface.php 2 years ago class-common-methods.php 2 years ago class-content-management.php 2 years ago class-custom-code.php 2 years ago class-deactivation.php 2 years ago class-disable-components.php 2 years ago class-login-logout.php 2 years ago class-optimizations.php 2 years ago class-security.php 2 years ago class-settings-fields-render.php 2 years ago class-settings-sanitization.php 2 years ago class-settings-sections-fields.php 2 years ago class-utilities.php 2 years ago
class-custom-code.php
259 lines
1 <?php
2
3 namespace ASENHA\Classes;
4
5 /**
6 * Class related to Custom Code features
7 *
8 * @since 3.6.0
9 */
10 class Custom_Code
11 {
12 /**
13 * Enqueue custom admin CSS
14 * Consider using https://github.com/Cerdic/CSSTidy in the future
15 *
16 * @since 2.3.0
17 */
18 public function custom_admin_css()
19 {
20 $options = get_option( ASENHA_SLUG_U, array() );
21 $custom_admin_css = $options['custom_admin_css'];
22 ?>
23 <style type="text/css">
24 <?php
25 echo $custom_admin_css ;
26 ?>
27 </style>
28 <?php
29 }
30
31 /**
32 * Enqueue custom frontend CSS
33 * Consider using https://github.com/Cerdic/CSSTidy in the future
34 *
35 * @since 2.3.0
36 */
37 public function custom_frontend_css()
38 {
39 $options = get_option( ASENHA_SLUG_U, array() );
40 $custom_frontend_css = $options['custom_frontend_css'];
41 ?>
42 <style type="text/css">
43 <?php
44 echo $custom_frontend_css ;
45 ?>
46 </style>
47 <?php
48 }
49
50 /**
51 * Add Custom Body Class meta box for enabled post types
52 *
53 * @since 3.9.0
54 */
55 public function add_custom_body_class_meta_box( $post_type, $post )
56 {
57 $options = get_option( ASENHA_SLUG_U, array() );
58 $enable_custom_body_class_for = $options['enable_custom_body_class_for'];
59 foreach ( $enable_custom_body_class_for as $post_type_slug => $is_custom_body_class_enabled ) {
60 if ( get_post_type() == $post_type_slug && $is_custom_body_class_enabled ) {
61 // Skip adding meta box for post types where Gutenberg is enabled
62 // if (
63 // function_exists( 'use_block_editor_for_post_type' )
64 // && use_block_editor_for_post_type( $post_type_slug )
65 // ) {
66 // continue; // go to the beginning of next iteration
67 // }
68 add_meta_box(
69 'asenha-custom-body-class',
70 // ID of meta box
71 'Custom &lt;body&gt; Class',
72 // Title of meta box
73 [ $this, 'output_custom_body_class_meta_box' ],
74 // Callback function
75 $post_type_slug,
76 // The screen on which the meta box should be output to
77 'normal',
78 // context
79 'high'
80 );
81 }
82 }
83 }
84
85 /**
86 * Render External Permalink meta box
87 *
88 * @since 3.9.0
89 */
90 public function output_custom_body_class_meta_box( $post )
91 {
92 ?>
93 <div class="custom-body-class-input">
94 <input name="<?php
95 echo esc_attr( 'custom_body_class' ) ;
96 ?>" class="large-text" id="<?php
97 echo esc_attr( 'custom_body_class' ) ;
98 ?>" type="text" value="<?php
99 echo esc_attr( get_post_meta( $post->ID, '_custom_body_class', true ) ) ;
100 ?>" placeholder="e.g. light-theme new-year-promo" />
101 <div class="custom-body-class-input-description">Use blank space to separate multiple classes, e.g. first-class second-class</div>
102 <?php
103 wp_nonce_field(
104 'custom_body_class_' . $post->ID,
105 'custom_body_class_nonce',
106 false,
107 true
108 );
109 ?>
110 </div>
111 <?php
112 }
113
114 /**
115 * Save custom body class input
116 *
117 * @since 3.9.0
118 */
119 public function save_custom_body_class( $post_id )
120 {
121 // Only proceed if nonce is verified
122
123 if ( isset( $_POST['custom_body_class_nonce'] ) && wp_verify_nonce( $_POST['custom_body_class_nonce'], 'custom_body_class_' . $post_id ) ) {
124 // Get the value of external permalink from input field
125 $custom_body_class = ( isset( $_POST['custom_body_class'] ) ? sanitize_text_field( trim( $_POST['custom_body_class'] ) ) : '' );
126 // Update or delete external permalink post meta
127
128 if ( !empty($custom_body_class) ) {
129 update_post_meta( $post_id, '_custom_body_class', $custom_body_class );
130 } else {
131 delete_post_meta( $post_id, '_custom_body_class' );
132 }
133
134 }
135
136 }
137
138 /**
139 * Append custom body classes to the frontend <body> tag
140 *
141 * @since 4.4.0
142 */
143 public function append_custom_body_class( $classes )
144 {
145 // Only add custom body classes to the singular view of enabled post types
146
147 if ( is_singular() ) {
148 global $post ;
149 $custom_body_classes = get_post_meta( $post->ID, '_custom_body_class', true );
150
151 if ( !empty($custom_body_classes) ) {
152 $custom_body_classes = explode( ' ', $custom_body_classes );
153 foreach ( $custom_body_classes as $custom_body_class ) {
154 $classes[] = sanitize_html_class( $custom_body_class );
155 }
156 }
157
158 }
159
160 return $classes;
161 }
162
163 /**
164 * Show content of ads.txt saved to options
165 *
166 * @since 3.2.0
167 */
168 public function show_ads_appads_txt_content()
169 {
170 $options = get_option( ASENHA_SLUG_U, array() );
171 $request = ( isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : false );
172
173 if ( '/ads.txt' === $request ) {
174 $ads_txt_content = ( array_key_exists( 'ads_txt_content', $options ) ? $options['ads_txt_content'] : '' );
175 header( 'Content-Type: text/plain' );
176 echo esc_textarea( $ads_txt_content ) ;
177 die;
178 }
179
180
181 if ( '/app-ads.txt' === $request ) {
182 $app_ads_txt_content = ( array_key_exists( 'app_ads_txt_content', $options ) ? $options['app_ads_txt_content'] : '' );
183 header( 'Content-Type: text/plain' );
184 echo esc_textarea( $app_ads_txt_content ) ;
185 die;
186 }
187
188 }
189
190 /**
191 * Maybe show custom robots.txt content
192 *
193 * @since 3.5.0
194 */
195 public function maybe_show_custom_robots_txt_content( $output, $public )
196 {
197 $options = get_option( ASENHA_SLUG_U, array() );
198 if ( array_key_exists( 'robots_txt_content', $options ) && !empty($options['robots_txt_content']) ) {
199 $output = wp_strip_all_tags( $options['robots_txt_content'] );
200 }
201 return $output;
202 }
203
204 /**
205 * Insert code before </head> tag
206 *
207 * @since 3.3.0
208 */
209 public function insert_head_code()
210 {
211 $this->insert_code( 'head' );
212 }
213
214 /**
215 * Insert code after <body> tag
216 *
217 * @since 3.3.0
218 */
219 public function insert_body_code()
220 {
221 $this->insert_code( 'body' );
222 }
223
224 /**
225 * Insert code in footer section before </body> tag
226 *
227 * @since 3.3.0
228 */
229 public function insert_footer_code()
230 {
231 $this->insert_code( 'footer' );
232 }
233
234 /**
235 * Insert code
236 *
237 * @since 3.3.0
238 */
239 public function insert_code( $location )
240 {
241 // Do not insert code in admin, feed, robots or trackbacks
242 if ( is_admin() || is_feed() || is_robots() || is_trackback() ) {
243 return;
244 }
245 // Get option that stores the code
246 $options = get_option( ASENHA_SLUG_U, array() );
247 if ( 'head' == $location ) {
248 $code = ( array_key_exists( 'head_code', $options ) ? $options['head_code'] : '' );
249 }
250 if ( 'body' == $location ) {
251 $code = ( array_key_exists( 'body_code', $options ) ? $options['body_code'] : '' );
252 }
253 if ( 'footer' == $location ) {
254 $code = ( array_key_exists( 'footer_code', $options ) ? $options['footer_code'] : '' );
255 }
256 echo wp_unslash( $code ) . PHP_EOL ;
257 }
258
259 }