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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-utilities.php
admin-site-enhancements / classes Last commit date
class-activation.php 3 years ago class-admin-interface.php 3 years ago class-common-methods.php 3 years ago class-content-management.php 3 years ago class-deactivation.php 3 years ago class-disable-components.php 3 years ago class-security.php 3 years ago class-settings-fields-render.php 3 years ago class-settings-sanitization.php 3 years ago class-settings-sections-fields.php 3 years ago class-utilities.php 3 years ago
class-utilities.php
269 lines
1 <?php
2
3 namespace ASENHA\Classes;
4
5 /**
6 * Class related to Utilities features
7 *
8 * @since 1.5.0
9 */
10 class Utilities {
11
12 /**
13 * Redirect to custom internal URL after login for user roles
14 *
15 * @param string $redirect_to_url URL to redirect to. Default is admin dashboard URL.
16 * @param string $origin_url URL the user is coming from.
17 * @param object $user logged-in user's data.
18 * @since 1.5.0
19 */
20 public function redirect_for_roles_after_login( $username, $user ) {
21
22 $options = get_option( ASENHA_SLUG_U );
23 $redirect_after_login_to_slug = $options['redirect_after_login_to_slug'];
24 $redirect_after_login_for = $options['redirect_after_login_for'];
25
26 if ( isset( $redirect_after_login_for ) && ( count( $redirect_after_login_for ) > 0 ) ) {
27
28 // Assemble single-dimensional array of roles for which custom URL redirection should happen
29 $roles_for_custom_redirect = array();
30
31 foreach( $redirect_after_login_for as $role_slug => $custom_redirect ) {
32 if ( $custom_redirect ) {
33 $roles_for_custom_redirect[] = $role_slug;
34 }
35 }
36
37 // Does the user have roles data in array form?
38 if ( isset( $user->roles ) && is_array( $user->roles ) ) {
39
40 $current_user_roles = $user->roles;
41
42 }
43
44 // Set custom redirect URL for roles set in the settings. Otherwise, leave redirect URL to the default, i.e. admin dashboard.
45 foreach ( $current_user_roles as $role ) {
46 if ( in_array( $role, $roles_for_custom_redirect ) ) {
47
48 wp_safe_redirect( home_url( $redirect_after_login_to_slug . '/' ) );
49 exit();
50
51 }
52 }
53
54 }
55
56 }
57
58 /**
59 * Redirect to custom internal URL after login for user roles
60 *
61 * @param string $redirect_to_url URL to redirect to. Default is admin dashboard URL.
62 * @param string $origin_url URL the user is coming from.
63 * @param object $user logged-in user's data.
64 * @since 1.6.0
65 */
66 public function redirect_after_logout( $user_id ) {
67
68 $options = get_option( ASENHA_SLUG_U );
69 $redirect_after_logout_to_slug = $options['redirect_after_logout_to_slug'];
70 $redirect_after_logout_for = $options['redirect_after_logout_for'];
71
72 $user = get_userdata( $user_id );
73
74 if ( isset( $redirect_after_logout_for ) && ( count( $redirect_after_logout_for ) > 0 ) ) {
75
76 // Assemble single-dimensional array of roles for which custom URL redirection should happen
77 $roles_for_custom_redirect = array();
78
79 foreach( $redirect_after_logout_for as $role_slug => $custom_redirect ) {
80 if ( $custom_redirect ) {
81 $roles_for_custom_redirect[] = $role_slug;
82 }
83 }
84
85 // Does the user have roles data in array form?
86 if ( isset( $user->roles ) && is_array( $user->roles ) ) {
87
88 $current_user_roles = $user->roles;
89
90 }
91
92 // Redirect for roles set in the settings. Otherwise, leave redirect URL to the default, i.e. admin dashboard.
93 foreach ( $current_user_roles as $role ) {
94 if ( in_array( $role, $roles_for_custom_redirect ) ) {
95
96 wp_safe_redirect( home_url( $redirect_after_logout_to_slug . '/' ) );
97 exit();
98
99 }
100 }
101
102 }
103
104 }
105
106 /**
107 * Redirect 404 to homepage
108 *
109 * @since 1.7.0
110 */
111 public function redirect_404_to_homepage() {
112
113 if ( ! is_404() || is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) || ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) ) {
114
115 return;
116
117 } else {
118
119 // wp_safe_redirect( home_url(), 301 );
120
121 header( 'HTTP/1.1 301 Moved Permanently');
122 header( 'Location: ' . home_url() );
123 exit();
124
125 }
126
127 }
128
129 /**
130 * Enqueue custom admin CSS
131 *
132 * @since 2.3.0
133 */
134 public function custom_admin_css() {
135
136 $options = get_option( ASENHA_SLUG_U );
137 $custom_admin_css = $options['custom_admin_css'];
138
139 ?>
140 <style type="text/css">
141 <?php echo wp_kses_post( $custom_admin_css ); ?>
142 </style>
143 <?php
144
145 }
146
147 /**
148 * Enqueue custom frontend CSS
149 *
150 * @since 2.3.0
151 */
152 public function custom_frontend_css() {
153
154 $options = get_option( ASENHA_SLUG_U );
155 $custom_frontend_css = $options['custom_frontend_css'];
156
157 ?>
158 <style type="text/css">
159 <?php echo wp_kses_post( $custom_frontend_css ); ?>
160 </style>
161 <?php
162
163 }
164
165 /**
166 * Show content of ads.txt saved to options
167 *
168 * @since 3.2.0
169 */
170 public function show_ads_appads_txt_content() {
171
172 $options = get_option( ASENHA_SLUG_U, array() );
173
174 $request = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : false;
175
176 if ( '/ads.txt' === $request ) {
177
178 $ads_txt_content = array_key_exists( 'ads_txt_content', $options ) ? $options['ads_txt_content'] : '';
179
180 header( 'Content-Type: text/plain' );
181 echo esc_textarea( $ads_txt_content );
182 die();
183
184 }
185
186 if ( '/app-ads.txt' === $request ) {
187
188 $app_ads_txt_content = array_key_exists( 'app_ads_txt_content', $options ) ? $options['app_ads_txt_content'] : '';
189
190 header( 'Content-Type: text/plain' );
191 echo esc_textarea( $app_ads_txt_content );
192 die();
193
194 }
195
196 }
197
198 /**
199 * Insert code before </head> tag
200 *
201 * @since 3.3.0
202 */
203 public function insert_head_code() {
204
205 $this->insert_code( 'head' );
206
207 }
208
209 /**
210 * Insert code after <body> tag
211 *
212 * @since 3.3.0
213 */
214 public function insert_body_code() {
215
216 $this->insert_code( 'body' );
217
218 }
219
220 /**
221 * Insert code in footer section before </body> tag
222 *
223 * @since 3.3.0
224 */
225 public function insert_footer_code() {
226
227 $this->insert_code( 'footer' );
228
229 }
230
231 /**
232 * Insert code
233 *
234 * @since 3.3.0
235 */
236 public function insert_code( $location ) {
237
238 // Do not insert code in admin, feed, robots or trackbacks
239 if ( is_admin() || is_feed() || is_robots() || is_trackback() ) {
240 return;
241 }
242
243 // Get option that stores the code
244 $options = get_option( ASENHA_SLUG_U, array() );
245
246 if ( 'head' == $location ) {
247
248 $code = array_key_exists( 'head_code', $options ) ? $options['head_code'] : '';
249
250 }
251
252 if ( 'body' == $location ) {
253
254 $code = array_key_exists( 'body_code', $options ) ? $options['body_code'] : '';
255
256 }
257
258 if ( 'footer' == $location ) {
259
260 $code = array_key_exists( 'footer_code', $options ) ? $options['footer_code'] : '';
261
262 }
263
264 echo wp_unslash( $code ) . PHP_EOL;
265
266 }
267
268
269 }