← All changes
|
frameworks/codestar-framework/classes/abstract.class.php
+195
-194
2.3.4
→
2.4.0
View file →
| @@ -1,194 +1,195 @@ | ||
| 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 | - | |
| 13 | - public $abstract = ''; | |
| 14 | - public $output_css = ''; | |
| 15 | - | |
| 16 | - public function __construct() { | |
| 17 | - | |
| 18 | - // Collect output css and typography | |
| 19 | - if ( ! empty( $this->args['output_css'] ) || ! empty( $this->args['enqueue_webfont'] ) ) { | |
| 20 | - add_action( 'wp_enqueue_scripts', array( $this, 'collect_output_css_and_typography' ), 10 ); | |
| 21 | - CSF::$css = apply_filters( "csf_{$this->unique}_output_css", CSF::$css, $this ); | |
| 22 | - } | |
| 23 | - | |
| 24 | - } | |
| 25 | - | |
| 26 | - public function collect_output_css_and_typography() { | |
| 27 | - $this->recursive_output_css( $this->pre_fields ); | |
| 28 | - } | |
| 29 | - | |
| 30 | - public function recursive_output_css( $fields = array(), $combine_field = array() ) { | |
| 31 | - | |
| 32 | - if ( ! empty( $fields ) ) { | |
| 33 | - | |
| 34 | - foreach ( $fields as $field ) { | |
| 35 | - | |
| 36 | - $field_id = ( ! empty( $field['id'] ) ) ? $field['id'] : ''; | |
| 37 | - $field_type = ( ! empty( $field['type'] ) ) ? $field['type'] : ''; | |
| 38 | - $field_output = ( ! empty( $field['output'] ) ) ? $field['output'] : ''; | |
| 39 | - $field_check = ( $field_type === 'typography' || $field_output ) ? true : false; | |
| 40 | - $field_class = 'CSF_Field_' . $field_type; | |
| 41 | - | |
| 42 | - if ( $field_type && $field_id ) { | |
| 43 | - | |
| 44 | - | |
| 45 | - if( $field_type === 'fieldset' ) { | |
| 46 | - if ( ! empty( $field['fields'] ) ) { | |
| 47 | - $this->recursive_output_css( $field['fields'], $field ); | |
| 48 | - } | |
| 49 | - } | |
| 50 | - | |
| 51 | - if( $field_type === 'accordion' ) { | |
| 52 | - if ( ! empty( $field['accordions'] ) ) { | |
| 53 | - foreach ( $field['accordions'] as $accordion ) { | |
| 54 | - $this->recursive_output_css( $accordion['fields'], $field ); | |
| 55 | - } | |
| 56 | - } | |
| 57 | - } | |
| 58 | - | |
| 59 | - if( $field_type === 'tabbed' ) { | |
| 60 | - if ( ! empty( $field['tabs'] ) ) { | |
| 61 | - foreach ( $field['tabs'] as $accordion ) { | |
| 62 | - $this->recursive_output_css( $accordion['fields'], $field ); | |
| 63 | - } | |
| 64 | - } | |
| 65 | - } | |
| 66 | - | |
| 67 | - if ( class_exists( $field_class ) ) { | |
| 68 | - | |
| 69 | - if ( method_exists( $field_class, 'output' ) || method_exists( $field_class, 'enqueue_google_fonts' ) ) { | |
| 70 | - | |
| 71 | - $field_value = ''; | |
| 72 | - | |
| 73 | - if ( $field_check && ( $this->abstract === 'options' || $this->abstract === 'customize' ) ) { | |
| 74 | - | |
| 75 | - if( ! empty( $combine_field ) ) { | |
| 76 | - | |
| 77 | - $field_value = ( isset( $this->options[$combine_field['id']][$field_id] ) ) ? $this->options[$combine_field['id']][$field_id] : ''; | |
| 78 | - | |
| 79 | - } else { | |
| 80 | - | |
| 81 | - $field_value = ( isset( $this->options[$field_id] ) ) ? $this->options[$field_id] : ''; | |
| 82 | - | |
| 83 | - } | |
| 84 | - | |
| 85 | - } else if ( $field_check && ( $this->abstract === 'metabox' && is_singular() || $this->abstract === 'taxonomy' && is_archive() ) ) { | |
| 86 | - | |
| 87 | - if( ! empty( $combine_field ) ) { | |
| 88 | - | |
| 89 | - $meta_value = $this->get_meta_value( $combine_field ); | |
| 90 | - $field_value = ( isset( $meta_value[$field_id] ) ) ? $meta_value[$field_id] : ''; | |
| 91 | - | |
| 92 | - } else { | |
| 93 | - | |
| 94 | - $meta_value = $this->get_meta_value( $field ); | |
| 95 | - $field_value = ( isset( $meta_value ) ) ? $meta_value : ''; | |
| 96 | - | |
| 97 | - } | |
| 98 | - | |
| 99 | - } | |
| 100 | - | |
| 101 | - $instance = new $field_class( $field, $field_value, $this->unique, 'wp/enqueue', $this ); | |
| 102 | - | |
| 103 | - // typography enqueue and embed google web fonts | |
| 104 | - if ( $field_type === 'typography' && $this->args['enqueue_webfont'] && ! empty( $field_value['font-family'] ) ) { | |
| 105 | - | |
| 106 | - $method = ( ! empty( $this->args['async_webfont'] ) ) ? 'async' : 'enqueue'; | |
| 107 | - | |
| 108 | - $instance->enqueue_google_fonts( $method ); | |
| 109 | - | |
| 110 | - } | |
| 111 | - | |
| 112 | - // output css | |
| 113 | - if ( $field_output && $this->args['output_css'] ) { | |
| 114 | - CSF::$css .= $instance->output(); | |
| 115 | - } | |
| 116 | - | |
| 117 | - unset( $instance ); | |
| 118 | - | |
| 119 | - } | |
| 120 | - | |
| 121 | - } | |
| 122 | - | |
| 123 | - } | |
| 124 | - | |
| 125 | - } | |
| 126 | - | |
| 127 | - } | |
| 128 | - | |
| 129 | - } | |
| 130 | - | |
| 131 | - public function pre_tabs( $sections ) { | |
| 132 | - | |
| 133 | - $count = 100; | |
| 134 | - $result = array(); | |
| 135 | - $parents = array(); | |
| 136 | - | |
| 137 | - foreach ( $sections as $key => $section ) { | |
| 138 | - if ( ! empty( $section['parent'] ) ) { | |
| 139 | - $section['priority'] = ( isset( $section['priority'] ) ) ? $section['priority'] : $count; | |
| 140 | - $parents[$section['parent']][] = $section; | |
| 141 | - unset( $sections[$key] ); | |
| 142 | - } | |
| 143 | - $count++; | |
| 144 | - } | |
| 145 | - | |
| 146 | - foreach ( $sections as $key => $section ) { | |
| 147 | - $section['priority'] = ( isset( $section['priority'] ) ) ? $section['priority'] : $count; | |
| 148 | - if ( ! empty( $section['id'] ) && ! empty( $parents[$section['id']] ) ) { | |
| 149 | - $section['subs'] = wp_list_sort( $parents[$section['id']], array( 'priority' => 'ASC' ), 'ASC', true ); | |
| 150 | - } | |
| 151 | - $result[] = $section; | |
| 152 | - $count++; | |
| 153 | - } | |
| 154 | - | |
| 155 | - return wp_list_sort( $result, array( 'priority' => 'ASC' ), 'ASC', true ); | |
| 156 | - | |
| 157 | - } | |
| 158 | - | |
| 159 | - public function pre_sections( $sections ) { | |
| 160 | - | |
| 161 | - $result = array(); | |
| 162 | - | |
| 163 | - foreach ( $this->pre_tabs( $sections ) as $section ) { | |
| 164 | - if ( ! empty( $section['subs'] ) ) { | |
| 165 | - foreach ( $section['subs'] as $sub ) { | |
| 166 | - $sub['ptitle'] = ( ! empty( $section['title'] ) ) ? $section['title'] : ''; | |
| 167 | - $result[] = $sub; | |
| 168 | - } | |
| 169 | - } | |
| 170 | - if ( empty( $section['subs'] ) ) { | |
| 171 | - $result[] = $section; | |
| 172 | - } | |
| 173 | - } | |
| 174 | - | |
| 175 | - return $result; | |
| 176 | - } | |
| 177 | - | |
| 178 | - public function pre_fields( $sections ) { | |
| 179 | - | |
| 180 | - $result = array(); | |
| 181 | - | |
| 182 | - foreach ( $sections as $key => $section ) { | |
| 183 | - if ( ! empty( $section['fields'] ) ) { | |
| 184 | - foreach ( $section['fields'] as $field ) { | |
| 185 | - $result[] = $field; | |
| 186 | - } | |
| 187 | - } | |
| 188 | - } | |
| 189 | - | |
| 190 | - return $result; | |
| 191 | - } | |
| 192 | - | |
| 193 | - } | |
| 194 | -} | |
| 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 | +#[AllowDynamicProperties] | |
| 12 | +abstract class CSF_Abstract { | |
| 13 | + | |
| 14 | + public $abstract = ''; | |
| 15 | + public $output_css = ''; | |
| 16 | + | |
| 17 | + public function __construct() { | |
| 18 | + | |
| 19 | + // Collect output css and typography | |
| 20 | + if ( ! empty( $this->args['output_css'] ) || ! empty( $this->args['enqueue_webfont'] ) ) { | |
| 21 | + add_action( 'wp_enqueue_scripts', array( $this, 'collect_output_css_and_typography' ), 10 ); | |
| 22 | + CSF::$css = apply_filters( "csf_{$this->unique}_output_css", CSF::$css, $this ); | |
| 23 | + } | |
| 24 | + | |
| 25 | + } | |
| 26 | + | |
| 27 | + public function collect_output_css_and_typography() { | |
| 28 | + $this->recursive_output_css( $this->pre_fields ); | |
| 29 | + } | |
| 30 | + | |
| 31 | + public function recursive_output_css( $fields = array(), $combine_field = array() ) { | |
| 32 | + | |
| 33 | + if ( ! empty( $fields ) ) { | |
| 34 | + | |
| 35 | + foreach ( $fields as $field ) { | |
| 36 | + | |
| 37 | + $field_id = ( ! empty( $field['id'] ) ) ? $field['id'] : ''; | |
| 38 | + $field_type = ( ! empty( $field['type'] ) ) ? $field['type'] : ''; | |
| 39 | + $field_output = ( ! empty( $field['output'] ) ) ? $field['output'] : ''; | |
| 40 | + $field_check = ( $field_type === 'typography' || $field_output ) ? true : false; | |
| 41 | + $field_class = 'CSF_Field_' . $field_type; | |
| 42 | + | |
| 43 | + if ( $field_type && $field_id ) { | |
| 44 | + | |
| 45 | + | |
| 46 | + if( $field_type === 'fieldset' ) { | |
| 47 | + if ( ! empty( $field['fields'] ) ) { | |
| 48 | + $this->recursive_output_css( $field['fields'], $field ); | |
| 49 | + } | |
| 50 | + } | |
| 51 | + | |
| 52 | + if( $field_type === 'accordion' ) { | |
| 53 | + if ( ! empty( $field['accordions'] ) ) { | |
| 54 | + foreach ( $field['accordions'] as $accordion ) { | |
| 55 | + $this->recursive_output_css( $accordion['fields'], $field ); | |
| 56 | + } | |
| 57 | + } | |
| 58 | + } | |
| 59 | + | |
| 60 | + if( $field_type === 'tabbed' ) { | |
| 61 | + if ( ! empty( $field['tabs'] ) ) { | |
| 62 | + foreach ( $field['tabs'] as $accordion ) { | |
| 63 | + $this->recursive_output_css( $accordion['fields'], $field ); | |
| 64 | + } | |
| 65 | + } | |
| 66 | + } | |
| 67 | + | |
| 68 | + if ( class_exists( $field_class ) ) { | |
| 69 | + | |
| 70 | + if ( method_exists( $field_class, 'output' ) || method_exists( $field_class, 'enqueue_google_fonts' ) ) { | |
| 71 | + | |
| 72 | + $field_value = ''; | |
| 73 | + | |
| 74 | + if ( $field_check && ( $this->abstract === 'options' || $this->abstract === 'customize' ) ) { | |
| 75 | + | |
| 76 | + if( ! empty( $combine_field ) ) { | |
| 77 | + | |
| 78 | + $field_value = ( isset( $this->options[$combine_field['id']][$field_id] ) ) ? $this->options[$combine_field['id']][$field_id] : ''; | |
| 79 | + | |
| 80 | + } else { | |
| 81 | + | |
| 82 | + $field_value = ( isset( $this->options[$field_id] ) ) ? $this->options[$field_id] : ''; | |
| 83 | + | |
| 84 | + } | |
| 85 | + | |
| 86 | + } else if ( $field_check && ( $this->abstract === 'metabox' && is_singular() || $this->abstract === 'taxonomy' && is_archive() ) ) { | |
| 87 | + | |
| 88 | + if( ! empty( $combine_field ) ) { | |
| 89 | + | |
| 90 | + $meta_value = $this->get_meta_value( $combine_field ); | |
| 91 | + $field_value = ( isset( $meta_value[$field_id] ) ) ? $meta_value[$field_id] : ''; | |
| 92 | + | |
| 93 | + } else { | |
| 94 | + | |
| 95 | + $meta_value = $this->get_meta_value( $field ); | |
| 96 | + $field_value = ( isset( $meta_value ) ) ? $meta_value : ''; | |
| 97 | + | |
| 98 | + } | |
| 99 | + | |
| 100 | + } | |
| 101 | + | |
| 102 | + $instance = new $field_class( $field, $field_value, $this->unique, 'wp/enqueue', $this ); | |
| 103 | + | |
| 104 | + // typography enqueue and embed google web fonts | |
| 105 | + if ( $field_type === 'typography' && $this->args['enqueue_webfont'] && ! empty( $field_value['font-family'] ) ) { | |
| 106 | + | |
| 107 | + $method = ( ! empty( $this->args['async_webfont'] ) ) ? 'async' : 'enqueue'; | |
| 108 | + | |
| 109 | + $instance->enqueue_google_fonts( $method ); | |
| 110 | + | |
| 111 | + } | |
| 112 | + | |
| 113 | + // output css | |
| 114 | + if ( $field_output && $this->args['output_css'] ) { | |
| 115 | + CSF::$css .= $instance->output(); | |
| 116 | + } | |
| 117 | + | |
| 118 | + unset( $instance ); | |
| 119 | + | |
| 120 | + } | |
| 121 | + | |
| 122 | + } | |
| 123 | + | |
| 124 | + } | |
| 125 | + | |
| 126 | + } | |
| 127 | + | |
| 128 | + } | |
| 129 | + | |
| 130 | + } | |
| 131 | + | |
| 132 | + public function pre_tabs( $sections ) { | |
| 133 | + | |
| 134 | + $count = 100; | |
| 135 | + $result = array(); | |
| 136 | + $parents = array(); | |
| 137 | + | |
| 138 | + foreach ( $sections as $key => $section ) { | |
| 139 | + if ( ! empty( $section['parent'] ) ) { | |
| 140 | + $section['priority'] = ( isset( $section['priority'] ) ) ? $section['priority'] : $count; | |
| 141 | + $parents[$section['parent']][] = $section; | |
| 142 | + unset( $sections[$key] ); | |
| 143 | + } | |
| 144 | + $count++; | |
| 145 | + } | |
| 146 | + | |
| 147 | + foreach ( $sections as $key => $section ) { | |
| 148 | + $section['priority'] = ( isset( $section['priority'] ) ) ? $section['priority'] : $count; | |
| 149 | + if ( ! empty( $section['id'] ) && ! empty( $parents[$section['id']] ) ) { | |
| 150 | + $section['subs'] = wp_list_sort( $parents[$section['id']], array( 'priority' => 'ASC' ), 'ASC', true ); | |
| 151 | + } | |
| 152 | + $result[] = $section; | |
| 153 | + $count++; | |
| 154 | + } | |
| 155 | + | |
| 156 | + return wp_list_sort( $result, array( 'priority' => 'ASC' ), 'ASC', true ); | |
| 157 | + | |
| 158 | + } | |
| 159 | + | |
| 160 | + public function pre_sections( $sections ) { | |
| 161 | + | |
| 162 | + $result = array(); | |
| 163 | + | |
| 164 | + foreach ( $this->pre_tabs( $sections ) as $section ) { | |
| 165 | + if ( ! empty( $section['subs'] ) ) { | |
| 166 | + foreach ( $section['subs'] as $sub ) { | |
| 167 | + $sub['ptitle'] = ( ! empty( $section['title'] ) ) ? $section['title'] : ''; | |
| 168 | + $result[] = $sub; | |
| 169 | + } | |
| 170 | + } | |
| 171 | + if ( empty( $section['subs'] ) ) { | |
| 172 | + $result[] = $section; | |
| 173 | + } | |
| 174 | + } | |
| 175 | + | |
| 176 | + return $result; | |
| 177 | + } | |
| 178 | + | |
| 179 | + public function pre_fields( $sections ) { | |
| 180 | + | |
| 181 | + $result = array(); | |
| 182 | + | |
| 183 | + foreach ( $sections as $key => $section ) { | |
| 184 | + if ( ! empty( $section['fields'] ) ) { | |
| 185 | + foreach ( $section['fields'] as $field ) { | |
| 186 | + $result[] = $field; | |
| 187 | + } | |
| 188 | + } | |
| 189 | + } | |
| 190 | + | |
| 191 | + return $result; | |
| 192 | + } | |
| 193 | + | |
| 194 | +} | |
| 195 | +} | |