elementor
1 year ago
class-simple-author-box-admin-page.php
1 year ago
class-simple-author-box-block.php
1 year ago
class-simple-author-box-helper.php
1 year ago
class-simple-author-box-previewer.php
1 year ago
class-simple-author-box-social.php
1 year ago
class-simple-author-box-user-profile.php
1 year ago
class-simple-author-box-widget.php
1 year ago
class-simple-author-box.php
1 year ago
functions.php
3 years ago
functions.php
453 lines
| 1 | <?php |
| 2 | |
| 3 | // If this file is called directly, busted! |
| 4 | if (!defined('ABSPATH')) { |
| 5 | exit; |
| 6 | } |
| 7 | |
| 8 | /*---------------------------------------------------------------------------------------------------------- |
| 9 | Adding the author box to the end of your single post |
| 10 | -----------------------------------------------------------------------------------------------------------*/ |
| 11 | if (!function_exists('wpsabox_author_box')) { |
| 12 | |
| 13 | |
| 14 | function wpsabox_author_box($saboxmeta = null, $user_id = null) |
| 15 | { |
| 16 | global $post; |
| 17 | $sabox_options = Simple_Author_Box_Helper::get_option('saboxplugin_options'); |
| 18 | |
| 19 | $show = (is_single() && isset($post->post_type) && $post->post_type == 'post') || is_author() || (is_archive() && 1 != $sabox_options['sab_hide_on_archive']); |
| 20 | |
| 21 | /** |
| 22 | * Hook: sabox_check_if_show. |
| 23 | * |
| 24 | * @hooked Simple_Author_Box::check_if_show_archive - 10 |
| 25 | */ |
| 26 | |
| 27 | if (is_archive()) { |
| 28 | $show = apply_filters('sabox_check_if_show', $show); |
| 29 | } |
| 30 | |
| 31 | if ($show) { |
| 32 | |
| 33 | global $post; |
| 34 | |
| 35 | $template = Simple_Author_Box_Helper::get_template(); |
| 36 | |
| 37 | ob_start(); |
| 38 | $sabox_options = Simple_Author_Box_Helper::get_option('saboxplugin_options'); |
| 39 | $sabox_author_id = $user_id ? $user_id : $post->post_author; |
| 40 | $show_post_author_box = apply_filters('sabox_check_if_show_post_author_box', true, $sabox_options); |
| 41 | |
| 42 | do_action('sabox_before_author_box', $sabox_options); |
| 43 | |
| 44 | if ($show_post_author_box) { |
| 45 | include($template); |
| 46 | } |
| 47 | |
| 48 | do_action('sabox_after_author_box', $sabox_options); |
| 49 | |
| 50 | $sabox = ob_get_clean(); |
| 51 | $return = $saboxmeta . $sabox; |
| 52 | |
| 53 | // Filter returning HTML of the Author Box |
| 54 | $saboxmeta = apply_filters('sabox_return_html', $return, $sabox, $saboxmeta); |
| 55 | } |
| 56 | |
| 57 | return $saboxmeta; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | function wpsabox_wp_kses_wf($html) |
| 62 | { |
| 63 | add_filter('safe_style_css', function ($styles) { |
| 64 | $styles_wf = array( |
| 65 | 'text-align', |
| 66 | 'margin', |
| 67 | 'color', |
| 68 | 'float', |
| 69 | 'border', |
| 70 | 'background', |
| 71 | 'background-color', |
| 72 | 'border-bottom', |
| 73 | 'border-bottom-color', |
| 74 | 'border-bottom-style', |
| 75 | 'border-bottom-width', |
| 76 | 'border-collapse', |
| 77 | 'border-color', |
| 78 | 'border-left', |
| 79 | 'border-left-color', |
| 80 | 'border-left-style', |
| 81 | 'border-left-width', |
| 82 | 'border-right', |
| 83 | 'border-right-color', |
| 84 | 'border-right-style', |
| 85 | 'border-right-width', |
| 86 | 'border-spacing', |
| 87 | 'border-style', |
| 88 | 'border-top', |
| 89 | 'border-top-color', |
| 90 | 'border-top-style', |
| 91 | 'border-top-width', |
| 92 | 'border-width', |
| 93 | 'caption-side', |
| 94 | 'clear', |
| 95 | 'cursor', |
| 96 | 'direction', |
| 97 | 'font', |
| 98 | 'font-family', |
| 99 | 'font-size', |
| 100 | 'font-style', |
| 101 | 'font-variant', |
| 102 | 'font-weight', |
| 103 | 'height', |
| 104 | 'letter-spacing', |
| 105 | 'line-height', |
| 106 | 'margin-bottom', |
| 107 | 'margin-left', |
| 108 | 'margin-right', |
| 109 | 'margin-top', |
| 110 | 'overflow', |
| 111 | 'padding', |
| 112 | 'padding-bottom', |
| 113 | 'padding-left', |
| 114 | 'padding-right', |
| 115 | 'padding-top', |
| 116 | 'text-decoration', |
| 117 | 'text-indent', |
| 118 | 'vertical-align', |
| 119 | 'width', |
| 120 | 'display', |
| 121 | ); |
| 122 | |
| 123 | foreach ($styles_wf as $style_wf) { |
| 124 | $styles[] = $style_wf; |
| 125 | } |
| 126 | return $styles; |
| 127 | }); |
| 128 | |
| 129 | $allowed_tags = wp_kses_allowed_html('post'); |
| 130 | $allowed_tags['input'] = array( |
| 131 | 'type' => true, |
| 132 | 'style' => true, |
| 133 | 'class' => true, |
| 134 | 'id' => true, |
| 135 | 'checked' => true, |
| 136 | 'disabled' => true, |
| 137 | 'name' => true, |
| 138 | 'size' => true, |
| 139 | 'placeholder' => true, |
| 140 | 'value' => true, |
| 141 | 'data-*' => true, |
| 142 | 'size' => true, |
| 143 | 'disabled' => true |
| 144 | ); |
| 145 | |
| 146 | $allowed_tags['textarea'] = array( |
| 147 | 'type' => true, |
| 148 | 'style' => true, |
| 149 | 'class' => true, |
| 150 | 'id' => true, |
| 151 | 'checked' => true, |
| 152 | 'disabled' => true, |
| 153 | 'name' => true, |
| 154 | 'size' => true, |
| 155 | 'placeholder' => true, |
| 156 | 'value' => true, |
| 157 | 'data-*' => true, |
| 158 | 'cols' => true, |
| 159 | 'rows' => true, |
| 160 | 'disabled' => true, |
| 161 | 'autocomplete' => true |
| 162 | ); |
| 163 | |
| 164 | $allowed_tags['select'] = array( |
| 165 | 'type' => true, |
| 166 | 'style' => true, |
| 167 | 'class' => true, |
| 168 | 'id' => true, |
| 169 | 'checked' => true, |
| 170 | 'disabled' => true, |
| 171 | 'name' => true, |
| 172 | 'size' => true, |
| 173 | 'placeholder' => true, |
| 174 | 'value' => true, |
| 175 | 'data-*' => true, |
| 176 | 'multiple' => true, |
| 177 | 'disabled' => true |
| 178 | ); |
| 179 | |
| 180 | $allowed_tags['option'] = array( |
| 181 | 'type' => true, |
| 182 | 'style' => true, |
| 183 | 'class' => true, |
| 184 | 'id' => true, |
| 185 | 'checked' => true, |
| 186 | 'disabled' => true, |
| 187 | 'name' => true, |
| 188 | 'size' => true, |
| 189 | 'placeholder' => true, |
| 190 | 'value' => true, |
| 191 | 'selected' => true, |
| 192 | 'data-*' => true |
| 193 | ); |
| 194 | $allowed_tags['optgroup'] = array( |
| 195 | 'type' => true, |
| 196 | 'style' => true, |
| 197 | 'class' => true, |
| 198 | 'id' => true, |
| 199 | 'checked' => true, |
| 200 | 'disabled' => true, |
| 201 | 'name' => true, |
| 202 | 'size' => true, |
| 203 | 'placeholder' => true, |
| 204 | 'value' => true, |
| 205 | 'selected' => true, |
| 206 | 'data-*' => true, |
| 207 | 'label' => true |
| 208 | ); |
| 209 | |
| 210 | $allowed_tags['a'] = array( |
| 211 | 'href' => true, |
| 212 | 'data-*' => true, |
| 213 | 'class' => true, |
| 214 | 'style' => true, |
| 215 | 'id' => true, |
| 216 | 'target' => true, |
| 217 | 'data-*' => true, |
| 218 | 'role' => true, |
| 219 | 'aria-controls' => true, |
| 220 | 'aria-selected' => true, |
| 221 | 'disabled' => true, |
| 222 | 'rel' => true, |
| 223 | 'title' => true |
| 224 | ); |
| 225 | |
| 226 | $allowed_tags['div'] = array( |
| 227 | 'style' => true, |
| 228 | 'class' => true, |
| 229 | 'id' => true, |
| 230 | 'data-*' => true, |
| 231 | 'role' => true, |
| 232 | 'aria-labelledby' => true, |
| 233 | 'value' => true, |
| 234 | 'aria-modal' => true, |
| 235 | 'tabindex' => true |
| 236 | ); |
| 237 | |
| 238 | $allowed_tags['li'] = array( |
| 239 | 'style' => true, |
| 240 | 'class' => true, |
| 241 | 'id' => true, |
| 242 | 'data-*' => true, |
| 243 | 'role' => true, |
| 244 | 'aria-labelledby' => true, |
| 245 | 'value' => true, |
| 246 | 'aria-modal' => true, |
| 247 | 'tabindex' => true |
| 248 | ); |
| 249 | |
| 250 | $allowed_tags['span'] = array( |
| 251 | 'style' => true, |
| 252 | 'class' => true, |
| 253 | 'id' => true, |
| 254 | 'data-*' => true, |
| 255 | 'aria-hidden' => true |
| 256 | ); |
| 257 | |
| 258 | $allowed_tags['style'] = array( |
| 259 | 'class' => true, |
| 260 | 'id' => true, |
| 261 | 'type' => true |
| 262 | ); |
| 263 | |
| 264 | $allowed_tags['fieldset'] = array( |
| 265 | 'class' => true, |
| 266 | 'id' => true, |
| 267 | 'type' => true |
| 268 | ); |
| 269 | |
| 270 | $allowed_tags['link'] = array( |
| 271 | 'class' => true, |
| 272 | 'id' => true, |
| 273 | 'type' => true, |
| 274 | 'rel' => true, |
| 275 | 'href' => true, |
| 276 | 'media' => true |
| 277 | ); |
| 278 | |
| 279 | $allowed_tags['form'] = array( |
| 280 | 'style' => true, |
| 281 | 'class' => true, |
| 282 | 'id' => true, |
| 283 | 'method' => true, |
| 284 | 'action' => true, |
| 285 | 'data-*' => true |
| 286 | ); |
| 287 | |
| 288 | $allowed_tags['script'] = array( |
| 289 | 'class' => true, |
| 290 | 'id' => true, |
| 291 | 'type' => true, |
| 292 | 'src' => true |
| 293 | ); |
| 294 | |
| 295 | $allowed_tags['path'] = array( |
| 296 | 'class' => true, |
| 297 | 'id' => true, |
| 298 | 'fill' => true, |
| 299 | 'd' => true |
| 300 | ); |
| 301 | |
| 302 | $allowed_tags['svg'] = array( |
| 303 | 'class' => true, |
| 304 | 'id' => true, |
| 305 | 'aria-hidden' => true, |
| 306 | 'role' => true, |
| 307 | 'xmlns' => true, |
| 308 | 'viewBox' => true, |
| 309 | 'viewbox' => true, |
| 310 | 'width' => true, |
| 311 | 'height' => true, |
| 312 | 'focusable' => true, |
| 313 | 'style' => true, |
| 314 | 'xml:space' => true |
| 315 | ); |
| 316 | |
| 317 | $allowed_tags['defs'] = array( |
| 318 | 'class' => true, |
| 319 | 'id' => true, |
| 320 | ); |
| 321 | |
| 322 | $allowed_tags['filter'] = array( |
| 323 | 'class' => true, |
| 324 | 'id' => true, |
| 325 | ); |
| 326 | |
| 327 | $allowed_tags['rect'] = array( |
| 328 | 'class' => true, |
| 329 | 'x' => true, |
| 330 | 'y' => true, |
| 331 | 'width' => true, |
| 332 | 'height' => true, |
| 333 | 'fill' => true |
| 334 | ); |
| 335 | |
| 336 | $allowed_tags['polygon'] = array( |
| 337 | 'class' => true, |
| 338 | 'points' => true, |
| 339 | 'width' => true, |
| 340 | 'height' => true, |
| 341 | 'fill' => true |
| 342 | ); |
| 343 | |
| 344 | echo wp_kses($html, $allowed_tags); |
| 345 | |
| 346 | add_filter('safe_style_css', function ($styles) { |
| 347 | $styles_wf = array( |
| 348 | 'text-align', |
| 349 | 'margin', |
| 350 | 'color', |
| 351 | 'float', |
| 352 | 'border', |
| 353 | 'background', |
| 354 | 'background-color', |
| 355 | 'border-bottom', |
| 356 | 'border-bottom-color', |
| 357 | 'border-bottom-style', |
| 358 | 'border-bottom-width', |
| 359 | 'border-collapse', |
| 360 | 'border-color', |
| 361 | 'border-left', |
| 362 | 'border-left-color', |
| 363 | 'border-left-style', |
| 364 | 'border-left-width', |
| 365 | 'border-right', |
| 366 | 'border-right-color', |
| 367 | 'border-right-style', |
| 368 | 'border-right-width', |
| 369 | 'border-spacing', |
| 370 | 'border-style', |
| 371 | 'border-top', |
| 372 | 'border-top-color', |
| 373 | 'border-top-style', |
| 374 | 'border-top-width', |
| 375 | 'border-width', |
| 376 | 'caption-side', |
| 377 | 'clear', |
| 378 | 'cursor', |
| 379 | 'direction', |
| 380 | 'font', |
| 381 | 'font-family', |
| 382 | 'font-size', |
| 383 | 'font-style', |
| 384 | 'font-variant', |
| 385 | 'font-weight', |
| 386 | 'height', |
| 387 | 'letter-spacing', |
| 388 | 'line-height', |
| 389 | 'margin-bottom', |
| 390 | 'margin-left', |
| 391 | 'margin-right', |
| 392 | 'margin-top', |
| 393 | 'overflow', |
| 394 | 'padding', |
| 395 | 'padding-bottom', |
| 396 | 'padding-left', |
| 397 | 'padding-right', |
| 398 | 'padding-top', |
| 399 | 'text-decoration', |
| 400 | 'text-indent', |
| 401 | 'vertical-align', |
| 402 | 'width' |
| 403 | ); |
| 404 | |
| 405 | foreach ($styles_wf as $style_wf) { |
| 406 | if (($key = array_search($style_wf, $styles)) !== false) { |
| 407 | unset($styles[$key]); |
| 408 | } |
| 409 | } |
| 410 | return $styles; |
| 411 | }); |
| 412 | } |
| 413 | |
| 414 | //return notice if user hasn't filled Biographical Info |
| 415 | function sab_user_description_notice() |
| 416 | { |
| 417 | $user_id = get_current_user_id(); |
| 418 | $user = get_userdata($user_id); |
| 419 | $user_descrition = $user->description; |
| 420 | $user_roles = $user->roles; |
| 421 | if (!$user_descrition && in_array('author', $user_roles)) { |
| 422 | |
| 423 | ?> |
| 424 | <div class="notice notice-info is-dismissible"> |
| 425 | <p><?php esc_html_e('Please complete Biographical Info', 'simple-author-box'); ?></p> |
| 426 | </div> |
| 427 | <?php |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | add_action('admin_notices', 'sab_user_description_notice'); |
| 432 | |
| 433 | |
| 434 | //return notice if user hasn't filled any social profiles |
| 435 | function sab_user_social_notice() |
| 436 | { |
| 437 | $user_id = get_current_user_id(); |
| 438 | $user_social = get_user_meta($user_id, 'sabox_social_links'); |
| 439 | $user = get_userdata($user_id); |
| 440 | $user_roles = $user->roles; |
| 441 | |
| 442 | if (!$user_social && in_array('author', $user_roles)) { |
| 443 | |
| 444 | ?> |
| 445 | <div class="notice notice-info is-dismissible"> |
| 446 | <p><?php esc_html_e('Please enter a social profile', 'simple-author-box'); ?></p> |
| 447 | </div> |
| 448 | <?php |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | add_action('admin_notices', 'sab_user_social_notice'); |
| 453 |