helpers.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. // manual css cache regeneration
  3. function vamtam_setup_adminbar() {
  4. if ( ! current_user_can( 'edit_theme_options' ) || ! class_exists( 'VamtamFramework' ) ) {
  5. return;
  6. }
  7. global $wp_admin_bar;
  8. $wp_admin_bar->add_menu( array(
  9. 'parent' => false,
  10. 'id' => 'vamtam_theme_options',
  11. 'title' => esc_html__( 'VamTam', 'vamtam-elements-b' ),
  12. 'href' => '',
  13. 'meta' => false,
  14. ) );
  15. $wp_admin_bar->add_menu(array(
  16. 'parent' => 'vamtam_theme_options',
  17. 'id' => 'vamtam_clear_css_cache',
  18. 'title' => esc_html__( 'Clear Cache', 'vamtam-elements-b' ),
  19. 'href' => admin_url( 'admin.php?vamtam_action=clear_cache' ),
  20. 'meta' => false,
  21. ) );
  22. }
  23. add_action( 'wp_before_admin_bar_render', 'vamtam_setup_adminbar', 11 );
  24. /**
  25. * Map an accent name to its value
  26. *
  27. * @param string $color accent name
  28. * @param string|bool $deprecated
  29. * @return string hex color or the input string
  30. */
  31. function vamtam_el_sanitize_accent( $color, $deprecated = false ) {
  32. if ( function_exists( 'vamtam_sanitize_accent' ) ) {
  33. return vamtam_sanitize_accent( $color );
  34. }
  35. if ( preg_match( '/accent(?:-color-)?(\d)/i', $color, $matches ) ) {
  36. $num = (int) $matches[1];
  37. $color = "var( --vamtam-accent-color-{$num} )";
  38. }
  39. return $color;
  40. }
  41. function vamtam_el_after_setup_theme() {
  42. if ( ! function_exists( 'vamtam_sanitize_bool' ) ) {
  43. /**
  44. * Converts '1', '0', 'true' and 'false' to booleans, otherwise returns $value
  45. * @param mixed $value original value
  46. * @return mixed sanitized value
  47. */
  48. function vamtam_sanitize_bool( $value ) {
  49. if ( $value === '1' || $value === 'true' ) {
  50. return true;
  51. }
  52. if ( $value === '0' || $value === 'false' ) {
  53. return false;
  54. }
  55. return $value;
  56. }
  57. }
  58. }
  59. add_action( 'after_setup_theme', 'vamtam_el_after_setup_theme' );