abstract.class.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
  2. /**
  3. *
  4. * Abstract Class
  5. *
  6. * @since 1.0.0
  7. * @version 1.0.0
  8. *
  9. */
  10. if ( ! class_exists( 'CSF_Abstract' ) ) {
  11. abstract class CSF_Abstract {
  12. public $abstract = '';
  13. public $output_css = '';
  14. public function __construct() {
  15. // Collect output css and typography
  16. if ( ! empty( $this->args['output_css'] ) || ! empty( $this->args['enqueue_webfont'] ) ) {
  17. add_action( 'wp_enqueue_scripts', array( $this, 'collect_output_css_and_typography' ), 10 );
  18. Sakurairo_CSF::$css = apply_filters( "csf_{$this->unique}_output_css", Sakurairo_CSF::$css, $this );
  19. }
  20. }
  21. public function collect_output_css_and_typography() {
  22. $this->recursive_output_css( $this->pre_fields );
  23. }
  24. public function recursive_output_css( $fields = array(), $combine_field = array() ) {
  25. if ( ! empty( $fields ) ) {
  26. foreach ( $fields as $field ) {
  27. $field_id = ( ! empty( $field['id'] ) ) ? $field['id'] : '';
  28. $field_type = ( ! empty( $field['type'] ) ) ? $field['type'] : '';
  29. $field_output = ( ! empty( $field['output'] ) ) ? $field['output'] : '';
  30. $field_check = ( $field_type === 'typography' || $field_output ) ? true : false;
  31. $field_class = 'CSF_Field_' . $field_type;
  32. if ( $field_type && $field_id ) {
  33. if( $field_type === 'fieldset' ) {
  34. if ( ! empty( $field['fields'] ) ) {
  35. $this->recursive_output_css( $field['fields'], $field );
  36. }
  37. }
  38. if( $field_type === 'accordion' ) {
  39. if ( ! empty( $field['accordions'] ) ) {
  40. foreach ( $field['accordions'] as $accordion ) {
  41. $this->recursive_output_css( $accordion['fields'], $field );
  42. }
  43. }
  44. }
  45. if( $field_type === 'tabbed' ) {
  46. if ( ! empty( $field['tabs'] ) ) {
  47. foreach ( $field['tabs'] as $accordion ) {
  48. $this->recursive_output_css( $accordion['fields'], $field );
  49. }
  50. }
  51. }
  52. if ( class_exists( $field_class ) ) {
  53. if ( method_exists( $field_class, 'output' ) || method_exists( $field_class, 'enqueue_google_fonts' ) ) {
  54. $field_value = '';
  55. if ( $field_check && ( $this->abstract === 'options' || $this->abstract === 'customize' ) ) {
  56. if( ! empty( $combine_field ) ) {
  57. $field_value = ( isset( $this->options[$combine_field['id']][$field_id] ) ) ? $this->options[$combine_field['id']][$field_id] : '';
  58. } else {
  59. $field_value = ( isset( $this->options[$field_id] ) ) ? $this->options[$field_id] : '';
  60. }
  61. } else if ( $field_check && ( $this->abstract === 'metabox' && is_singular() || $this->abstract === 'taxonomy' && is_archive() ) ) {
  62. if( ! empty( $combine_field ) ) {
  63. $meta_value = $this->get_meta_value( $combine_field );
  64. $field_value = ( isset( $meta_value[$field_id] ) ) ? $meta_value[$field_id] : '';
  65. } else {
  66. $meta_value = $this->get_meta_value( $field );
  67. $field_value = ( isset( $meta_value ) ) ? $meta_value : '';
  68. }
  69. }
  70. $instance = new $field_class( $field, $field_value, $this->unique, 'wp/enqueue', $this );
  71. // typography enqueue and embed google web fonts
  72. if ( $field_type === 'typography' && $this->args['enqueue_webfont'] && ! empty( $field_value['font-family'] ) ) {
  73. $method = ( ! empty( $this->args['async_webfont'] ) ) ? 'async' : 'enqueue';
  74. $instance->enqueue_google_fonts( $method );
  75. }
  76. // output css
  77. if ( $field_output && $this->args['output_css'] ) {
  78. Sakurairo_CSF::$css .= $instance->output();
  79. }
  80. unset( $instance );
  81. }
  82. }
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }