idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
9,200
|
public static function loop_controls ( $ config_id ) { Generator :: get_instance ( ) ; $ fields = array_merge ( Kirki :: $ fields , self :: get_fields_by_config ( $ config_id ) ) ; $ css = [ ] ; if ( empty ( $ fields ) ) { return ; } foreach ( $ fields as $ field ) { if ( isset ( $ field [ 'kirki_config' ] ) && $ config_id !== $ field [ 'kirki_config' ] ) { continue ; } if ( true === apply_filters ( "kirki_{$config_id}_css_skip_hidden" , true ) ) { if ( ! empty ( $ field [ 'required' ] ) ) { $ valid = true ; foreach ( $ field [ 'required' ] as $ requirement ) { if ( isset ( $ requirement [ 'setting' ] ) && isset ( $ requirement [ 'value' ] ) && isset ( $ requirement [ 'operator' ] ) ) { $ controller_value = Values :: get_value ( $ config_id , $ requirement [ 'setting' ] ) ; if ( ! Helper :: compare_values ( $ controller_value , $ requirement [ 'value' ] , $ requirement [ 'operator' ] ) ) { $ valid = false ; } } } if ( ! $ valid ) { continue ; } } } if ( isset ( $ field [ 'output' ] ) && ! empty ( $ field [ 'output' ] ) ) { $ css = Helper :: array_replace_recursive ( $ css , Generator :: css ( $ field ) ) ; if ( isset ( self :: $ css_array [ $ config_id ] ) && ! empty ( self :: $ css_array [ $ config_id ] ) ) { Helper :: array_replace_recursive ( $ css , self :: $ css_array [ $ config_id ] ) ; } } } $ css = apply_filters ( "kirki_{$config_id}_styles" , $ css ) ; if ( is_array ( $ css ) ) { return Generator :: styles_parse ( Generator :: add_prefixes ( $ css ) ) ; } }
|
Loop through all fields and create an array of style definitions .
|
9,201
|
public function filter_setting_args ( $ args , $ wp_customize ) { $ args [ 'type' ] = 'theme_mod' ; if ( isset ( $ args [ 'option_type' ] ) ) { $ args [ 'type' ] = $ args [ 'option_type' ] ; if ( isset ( $ args [ 'option_name' ] ) && ! empty ( $ args [ 'option_name' ] ) ) { if ( isset ( $ args [ 'settings' ] ) && false === strpos ( $ args [ 'settings' ] , $ args [ 'option_name' ] . '[' ) ) { $ args [ 'settings' ] = $ args [ 'option_name' ] . '[' . $ args [ 'settings' ] . ']' ; } } } return $ args ; }
|
Filter setting args .
|
9,202
|
public function add_setting ( $ wp_customize ) { $ args = apply_filters ( 'kirki_field_add_setting_args' , $ this -> args , $ wp_customize ) ; if ( isset ( $ args [ 'settings' ] ) ) { $ wp_customize -> add_setting ( $ args [ 'settings' ] , $ args ) ; } }
|
Registers the setting .
|
9,203
|
public function add_control ( $ wp_customize ) { $ control_class = $ this -> control_class ; if ( ! $ control_class ) { return ; } $ args = apply_filters ( 'kirki_field_add_control_args' , $ this -> args , $ wp_customize ) ; $ wp_customize -> add_control ( new $ control_class ( $ wp_customize , $ args [ 'settings' ] , $ args ) ) ; }
|
Registers the control .
|
9,204
|
public function get_google_fonts_by_args ( $ args = [ ] ) { $ cache_name = 'kirki_googlefonts_' . md5 ( wp_json_encode ( $ args ) ) ; $ cache = get_site_transient ( $ cache_name ) ; if ( $ cache ) { return $ cache ; } $ args [ 'sort' ] = isset ( $ args [ 'sort' ] ) ? $ args [ 'sort' ] : 'alpha' ; $ fonts = $ this -> get_array ( ) ; $ ordered_fonts = $ fonts [ 'order' ] [ $ args [ 'sort' ] ] ; if ( isset ( $ args [ 'count' ] ) ) { set_site_transient ( $ cache_name , $ ordered_fonts , HOUR_IN_SECONDS ) ; $ ordered_fonts = array_slice ( $ ordered_fonts , 0 , $ args [ 'count' ] ) ; return $ ordered_fonts ; } set_site_transient ( $ cache_name , $ ordered_fonts , HOUR_IN_SECONDS ) ; return $ ordered_fonts ; }
|
Returns an array of google - fonts matching our arguments .
|
9,205
|
public static function get_remote_url_contents ( $ url , $ args = [ ] ) { $ response = wp_remote_get ( $ url , $ args ) ; if ( is_wp_error ( $ response ) ) { return [ ] ; } $ html = wp_remote_retrieve_body ( $ response ) ; if ( is_wp_error ( $ html ) ) { return ; } return $ html ; }
|
Gets the remote URL contents .
|
9,206
|
public static function get_root_path ( ) { $ upload_dir = wp_upload_dir ( ) ; $ path = untrailingslashit ( wp_normalize_path ( $ upload_dir [ 'basedir' ] ) ) . '/webfonts' ; if ( ! file_exists ( $ path ) ) { wp_mkdir_p ( $ path ) ; } return apply_filters ( 'kirki_googlefonts_root_path' , $ path ) ; }
|
Gets the root fonts folder path . Other paths are built based on this .
|
9,207
|
private static function get_filename_from_url ( $ url ) { $ url_parts = explode ( '/' , $ url ) ; $ parts_count = count ( $ url_parts ) ; if ( 1 < $ parts_count ) { return $ url_parts [ count ( $ url_parts ) - 1 ] ; } return $ url ; }
|
Gets the filename by breaking - down the URL parts .
|
9,208
|
public static function download_font_file ( $ url ) { require_once ABSPATH . 'wp-admin/includes/file.php' ; $ timeout_seconds = 5 ; $ temp_file = download_url ( $ url , $ timeout_seconds ) ; if ( is_wp_error ( $ temp_file ) ) { return false ; } $ file = [ 'name' => basename ( $ url ) , 'type' => 'font/woff' , 'tmp_name' => $ temp_file , 'error' => 0 , 'size' => filesize ( $ temp_file ) , ] ; $ overrides = [ 'test_type' => false , 'test_form' => false , 'test_size' => true , ] ; $ results = wp_handle_sideload ( $ file , $ overrides ) ; if ( empty ( $ results [ 'error' ] ) ) { return $ results [ 'url' ] ; } return false ; }
|
Downloads a font - file and saves it locally .
|
9,209
|
public static function get_root_url ( ) { $ upload_dir = wp_upload_dir ( ) ; $ url = trailingslashit ( $ upload_dir [ 'baseurl' ] ) ; if ( defined ( 'DOMAIN_MAPPING' ) && DOMAIN_MAPPING ) { if ( function_exists ( 'domain_mapping_siteurl' ) && function_exists ( 'get_original_url' ) ) { $ mapped_domain = domain_mapping_siteurl ( false ) ; $ original_domain = get_original_url ( 'siteurl' ) ; $ url = str_replace ( $ original_domain , $ mapped_domain , $ url ) ; } } $ url = str_replace ( [ 'https://' , 'http://' ] , '//' , $ url ) ; return apply_filters ( 'kirki_googlefonts_root_url' , untrailingslashit ( esc_url_raw ( $ url ) ) . '/webfonts' ) ; }
|
Gets the root folder url . Other urls are built based on this .
|
9,210
|
public function init ( ) { $ this -> set_configs ( ) ; $ this -> set_enabled ( ) ; $ this -> set_modules_css ( ) ; $ this -> set_google_fonts ( ) ; $ this -> set_modules_webfonts ( ) ; $ this -> add_hooks ( ) ; }
|
Initialize Module .
|
9,211
|
public function enqueue ( $ settings ) { $ styles = $ this -> get_styles ( ) ; if ( ! empty ( $ styles ) ) { $ settings [ 'styles' ] [ ] = [ 'css' => $ styles ] ; } return $ settings ; }
|
Enqueue styles to Gutenberg Editor .
|
9,212
|
public function get_styles ( ) { $ styles = null ; foreach ( $ this -> configs as $ config_id => $ args ) { if ( true === $ this -> is_disabled ( $ args ) ) { continue ; } $ modules_css = $ this -> modules_css ; $ styles = $ modules_css :: loop_controls ( $ config_id ) ; $ styles = apply_filters ( "kirki_gutenberg_{$config_id}_dynamic_css" , $ styles ) ; if ( empty ( $ styles ) ) { continue ; } } return $ styles ; }
|
Gets the styles to add to Gutenberg Editor .
|
9,213
|
private function is_disabled ( $ args = [ ] ) { if ( defined ( 'KIRKI_NO_OUTPUT' ) && true === KIRKI_NO_OUTPUT ) { return true ; } if ( ! empty ( $ args ) ) { if ( isset ( $ args [ 'disable_output' ] ) && true === $ args [ 'disable_output' ] ) { return true ; } if ( ! isset ( $ args [ 'gutenberg_support' ] ) || true !== $ args [ 'gutenberg_support' ] ) { return true ; } } return false ; }
|
Helper method to check if feature is disabled .
|
9,214
|
public function enqueue_fontawesome ( ) { foreach ( $ this -> configs as $ config_id => $ args ) { if ( $ this -> is_disabled ( $ args ) ) { continue ; } $ modules_css = $ this -> modules_css ; if ( $ modules_css :: get_enqueue_fa ( ) && apply_filters ( 'kirki_load_fontawesome' , true ) ) { wp_enqueue_script ( 'kirki-fontawesome-font' , 'https://use.fontawesome.com/30858dc40a.js' , [ ] , '4.0.7' , true ) ; } return ; } }
|
Enqueue fontawesome in Gutenberg Editor .
|
9,215
|
public function add_to_customizer ( ) { $ this -> fields_from_filters ( ) ; add_action ( 'customize_register' , [ $ this , 'register_control_types' ] ) ; add_action ( 'customize_register' , [ $ this , 'add_panels' ] , 97 ) ; add_action ( 'customize_register' , [ $ this , 'add_sections' ] , 98 ) ; add_action ( 'customize_register' , [ $ this , 'add_fields' ] , 99 ) ; }
|
Helper function that adds the fields sections and panels to the customizer .
|
9,216
|
public function register_control_types ( ) { global $ wp_customize ; $ section_types = apply_filters ( 'kirki_section_types' , [ ] ) ; foreach ( $ section_types as $ section_type ) { $ wp_customize -> register_section_type ( $ section_type ) ; } $ this -> control_types = $ this -> default_control_types ( ) ; if ( ! class_exists ( 'WP_Customize_Code_Editor_Control' ) ) { unset ( $ this -> control_types [ 'code_editor' ] ) ; } foreach ( $ this -> control_types as $ key => $ classname ) { if ( ! class_exists ( $ classname ) ) { unset ( $ this -> control_types [ $ key ] ) ; } } $ skip_control_types = apply_filters ( 'kirki_control_types_exclude' , [ '\Kirki\Control\Repeater' , '\WP_Customize_Control' , ] ) ; foreach ( $ this -> control_types as $ control_type ) { if ( ! in_array ( $ control_type , $ skip_control_types , true ) && class_exists ( $ control_type ) ) { $ wp_customize -> register_control_type ( $ control_type ) ; } } }
|
Register control types
|
9,217
|
public function add_panels ( ) { if ( ! empty ( Kirki :: $ panels ) ) { foreach ( Kirki :: $ panels as $ panel_args ) { if ( isset ( $ panel_args [ 'panel' ] ) ) { if ( isset ( Kirki :: $ panels [ $ panel_args [ 'panel' ] ] ) ) { $ panel_args [ 'type' ] = 'kirki-nested' ; } } new Panel ( $ panel_args ) ; } } }
|
Register our panels to the WordPress Customizer .
|
9,218
|
public function add_sections ( ) { if ( ! empty ( Kirki :: $ sections ) ) { foreach ( Kirki :: $ sections as $ section_args ) { if ( isset ( $ section_args [ 'section' ] ) ) { if ( isset ( Kirki :: $ sections [ $ section_args [ 'section' ] ] ) ) { $ section_args [ 'type' ] = 'kirki-nested' ; $ parent_section = Kirki :: $ sections [ $ section_args [ 'section' ] ] ; if ( isset ( $ parent_section [ 'panel' ] ) ) { $ section_args [ 'panel' ] = $ parent_section [ 'panel' ] ; } } } new Section ( $ section_args ) ; } } }
|
Register our sections to the WordPress Customizer .
|
9,219
|
private function fields_from_filters ( ) { $ fields = apply_filters ( 'kirki_controls' , [ ] ) ; $ fields = apply_filters ( 'kirki_fields' , $ fields ) ; if ( ! empty ( $ fields ) ) { foreach ( $ fields as $ field ) { $ field [ 'kirki_config' ] = 'global' ; Kirki :: add_field ( $ field ) ; } } }
|
Process fields added using the kirki_fields and kirki_controls filter . These filters are no longer used this is simply for backwards - compatibility .
|
9,220
|
public function sanitize ( $ value ) { if ( is_array ( $ value ) ) { foreach ( $ value as $ key => $ subvalue ) { if ( '' !== $ subvalue || isset ( $ this -> choices [ '' ] ) ) { $ key = sanitize_key ( $ key ) ; $ value [ $ key ] = sanitize_text_field ( $ subvalue ) ; } } return $ value ; } return sanitize_text_field ( $ value ) ; }
|
Sanitizes select control values .
|
9,221
|
public static function sanitize ( $ value ) { if ( ! is_array ( $ value ) ) { return [ ] ; } $ sanitized_value = [ 'background-color' => '' , 'background-image' => '' , 'background-repeat' => '' , 'background-position' => '' , 'background-size' => '' , 'background-attachment' => '' , ] ; if ( isset ( $ value [ 'background-color' ] ) ) { $ sanitized_value [ 'background-color' ] = \ Kirki \ Field \ Color :: sanitize ( $ value [ 'background-color' ] ) ; } if ( isset ( $ value [ 'background-image' ] ) ) { $ sanitized_value [ 'background-image' ] = esc_url_raw ( $ value [ 'background-image' ] ) ; } if ( isset ( $ value [ 'background-repeat' ] ) ) { $ sanitized_value [ 'background-repeat' ] = in_array ( $ value [ 'background-repeat' ] , [ 'no-repeat' , 'repeat' , 'repeat-x' , 'repeat-y' , ] , true ) ? $ value [ 'background-repeat' ] : '' ; } if ( isset ( $ value [ 'background-position' ] ) ) { $ sanitized_value [ 'background-position' ] = in_array ( $ value [ 'background-position' ] , [ 'left top' , 'left center' , 'left bottom' , 'center top' , 'center center' , 'center bottom' , 'right top' , 'right center' , 'right bottom' , ] , true ) ? $ value [ 'background-position' ] : '' ; } if ( isset ( $ value [ 'background-size' ] ) ) { $ sanitized_value [ 'background-size' ] = in_array ( $ value [ 'background-size' ] , [ 'cover' , 'contain' , 'auto' , ] , true ) ? $ value [ 'background-size' ] : '' ; } if ( isset ( $ value [ 'background-attachment' ] ) ) { $ sanitized_value [ 'background-attachment' ] = in_array ( $ value [ 'background-attachment' ] , [ 'scroll' , 'fixed' , ] , true ) ? $ value [ 'background-attachment' ] : '' ; } return $ sanitized_value ; }
|
Sanitizes background controls
|
9,222
|
public static function dropdown_pages ( $ page_id , $ setting ) { $ page_id = absint ( $ page_id ) ; return ( 'publish' === get_post_status ( $ page_id ) ? $ page_id : $ setting -> default ) ; }
|
Drop - down Pages sanitization callback .
|
9,223
|
public static function css_dimension ( $ value ) { $ value = trim ( $ value ) ; if ( 'round' === $ value ) { $ value = '50%' ; } if ( '' === $ value ) { return '' ; } if ( 'auto' === $ value || 'initial' === $ value || 'inherit' === $ value || 'normal' === $ value ) { return $ value ; } if ( ! preg_match ( '#[0-9]#' , $ value ) ) { return '' ; } if ( false !== strpos ( $ value , 'calc(' ) ) { return $ value ; } $ raw_value = self :: filter_number ( $ value ) ; $ unit_used = '' ; $ units = [ 'fr' , 'rem' , 'em' , 'ex' , '%' , 'px' , 'cm' , 'mm' , 'in' , 'pt' , 'pc' , 'ch' , 'vh' , 'vw' , 'vmin' , 'vmax' ] ; foreach ( $ units as $ unit ) { if ( false !== strpos ( $ value , $ unit ) ) { $ unit_used = $ unit ; } } if ( 'em' === $ unit_used && false !== strpos ( $ value , 'rem' ) ) { $ unit_used = 'rem' ; } return $ raw_value . $ unit_used ; }
|
Sanitizes css dimensions .
|
9,224
|
public function add_tooltip ( $ field_id , $ tooltip ) { $ this -> tooltips_content [ $ field_id ] = [ 'id' => sanitize_key ( $ field_id ) , 'content' => wp_kses_post ( $ tooltip ) , ] ; }
|
Allows us to add a tooltip to any control .
|
9,225
|
public function register_partials ( $ wp_customize ) { if ( ! isset ( $ wp_customize -> selective_refresh ) ) { return ; } $ fields = Kirki :: $ fields ; foreach ( $ fields as $ field ) { if ( isset ( $ field [ 'partial_refresh' ] ) && ! empty ( $ field [ 'partial_refresh' ] ) ) { foreach ( $ field [ 'partial_refresh' ] as $ partial_refresh => $ partial_refresh_args ) { if ( isset ( $ partial_refresh_args [ 'render_callback' ] ) && isset ( $ partial_refresh_args [ 'selector' ] ) ) { $ partial_refresh_args = wp_parse_args ( $ partial_refresh_args , [ 'settings' => $ field [ 'settings' ] , ] ) ; $ wp_customize -> selective_refresh -> add_partial ( $ partial_refresh , $ partial_refresh_args ) ; } } } } }
|
Parses all fields and searches for the partial_refresh argument inside them . If that argument is found then it starts parsing the array of arguments . Registers a selective_refresh in the customizer for each one of them .
|
9,226
|
public function sanitize_repeater_setting ( $ value ) { if ( ! is_array ( $ value ) ) { $ value = json_decode ( urldecode ( $ value ) ) ; } if ( empty ( $ value ) || ! is_array ( $ value ) ) { $ value = [ ] ; } foreach ( $ value as $ key => $ val ) { $ value [ $ key ] = ( array ) $ val ; if ( empty ( $ val ) ) { unset ( $ value [ $ key ] ) ; } } if ( is_array ( $ value ) ) { $ value = array_values ( $ value ) ; } return $ value ; }
|
Convert the JSON encoded setting coming from Customizer to an Array .
|
9,227
|
protected function init ( ) { foreach ( array_keys ( Kirki :: $ config ) as $ config_id ) { if ( 'async' === $ this -> get_method ( ) ) { new Async ( $ config_id , $ this , $ this -> fonts_google ) ; } new Embed ( $ config_id , $ this , $ this -> fonts_google ) ; } }
|
Init other objects depending on the method we ll be using .
|
9,228
|
public static function get_value ( $ config_id = '' , $ field_id = '' ) { $ value = '' ; if ( ( '' === $ field_id ) && '' !== $ config_id ) { $ field_id = $ config_id ; $ config_id = 'global' ; } $ config_id = ( '' === $ config_id ) ? 'global' : $ config_id ; if ( ! isset ( Kirki :: $ config [ $ config_id ] ) ) { $ config_id = 'global' ; } if ( 'theme_mod' === Kirki :: $ config [ $ config_id ] [ 'option_type' ] ) { $ default_value = null ; if ( isset ( Kirki :: $ fields [ $ field_id ] ) && isset ( Kirki :: $ fields [ $ field_id ] [ 'default' ] ) ) { $ default_value = Kirki :: $ fields [ $ field_id ] [ 'default' ] ; } $ value = get_theme_mod ( $ field_id , $ default_value ) ; return apply_filters ( 'kirki_values_get_value' , $ value , $ field_id ) ; } if ( 'option' === Kirki :: $ config [ $ config_id ] [ 'option_type' ] ) { if ( '' !== Kirki :: $ config [ $ config_id ] [ 'option_name' ] ) { $ options = get_option ( Kirki :: $ config [ $ config_id ] [ 'option_name' ] ) ; if ( ! isset ( Kirki :: $ fields [ $ field_id ] ) && isset ( Kirki :: $ fields [ Kirki :: $ config [ $ config_id ] [ 'option_name' ] . '[' . $ field_id . ']' ] ) ) { $ field_id = Kirki :: $ config [ $ config_id ] [ 'option_name' ] . '[' . $ field_id . ']' ; } $ setting_modified = str_replace ( ']' , '' , str_replace ( Kirki :: $ config [ $ config_id ] [ 'option_name' ] . '[' , '' , $ field_id ) ) ; $ default_value = ( isset ( Kirki :: $ fields [ $ field_id ] ) && isset ( Kirki :: $ fields [ $ field_id ] [ 'default' ] ) ) ? Kirki :: $ fields [ $ field_id ] [ 'default' ] : '' ; $ value = ( isset ( $ options [ $ setting_modified ] ) ) ? $ options [ $ setting_modified ] : $ default_value ; $ value = maybe_unserialize ( $ value ) ; return apply_filters ( 'kirki_values_get_value' , $ value , $ field_id ) ; } $ value = get_option ( $ field_id , Kirki :: $ fields [ $ field_id ] [ 'default' ] ) ; return apply_filters ( 'kirki_values_get_value' , $ value , $ field_id ) ; } return apply_filters ( 'kirki_values_get_value' , $ value , $ field_id ) ; }
|
Get the value of a field .
|
9,229
|
public static function get_sanitized_field_value ( $ field ) { $ value = $ field [ 'default' ] ; if ( isset ( $ field [ 'option_type' ] ) && 'theme_mod' === $ field [ 'option_type' ] ) { $ value = get_theme_mod ( $ field [ 'settings' ] , $ field [ 'default' ] ) ; } elseif ( isset ( $ field [ 'option_type' ] ) && 'option' === $ field [ 'option_type' ] ) { if ( isset ( $ field [ 'option_name' ] ) && '' !== $ field [ 'option_name' ] ) { $ all_values = get_option ( $ field [ 'option_name' ] , [ ] ) ; $ sub_setting_id = str_replace ( [ ']' , $ field [ 'option_name' ] . '[' ] , '' , $ field [ 'settings' ] ) ; if ( isset ( $ all_values [ $ sub_setting_id ] ) ) { $ value = $ all_values [ $ sub_setting_id ] ; } } else { $ value = get_option ( $ field [ 'settings' ] , $ field [ 'default' ] ) ; } } return $ value ; }
|
Gets the value or fallsback to default .
|
9,230
|
public function field_add_control_args ( $ args ) { if ( isset ( $ args [ 'active_callback' ] ) ) { if ( is_array ( $ args [ 'active_callback' ] ) ) { if ( ! is_callable ( $ args [ 'active_callback' ] ) ) { foreach ( $ args [ 'active_callback' ] as $ key => $ val ) { if ( is_callable ( $ val ) ) { unset ( $ args [ 'active_callback' ] [ $ key ] ) ; } } if ( isset ( $ args [ 'active_callback' ] [ 0 ] ) ) { $ args [ 'required' ] = $ args [ 'active_callback' ] ; } } } if ( ! empty ( $ args [ 'required' ] ) ) { $ args [ 'active_callback' ] = '__return_true' ; return ; } if ( '__return_true' === $ args [ 'active_callback' ] ) { return ; } if ( ! is_callable ( $ args [ 'active_callback' ] ) ) { $ args [ 'active_callback' ] = '__return_true' ; } } return $ args ; }
|
Filter control arguments .
|
9,231
|
public function postmessage ( ) { wp_enqueue_script ( 'kirki_auto_css_vars' , URL :: get_from_path ( __DIR__ . '/script.js' ) , [ 'jquery' , 'customize-preview' ] , KIRKI_VERSION , true ) ; $ fields = array_merge ( Kirki :: $ fields , $ this -> fields ) ; $ data = [ ] ; foreach ( $ fields as $ field ) { if ( isset ( $ field [ 'transport' ] ) && 'postMessage' === $ field [ 'transport' ] && isset ( $ field [ 'css_vars' ] ) && ! empty ( $ field [ 'css_vars' ] ) ) { $ data [ ] = $ field ; } } wp_localize_script ( 'kirki_auto_css_vars' , 'kirkiCssVarFields' , $ data ) ; }
|
Enqueues the script that handles postMessage and adds variables to it using the wp_localize_script function . The rest is handled via JS .
|
9,232
|
final private function add_settings ( $ args = [ ] ) { $ classname = false ; if ( isset ( $ args [ 'option_type' ] ) && array_key_exists ( $ args [ 'option_type' ] , $ this -> setting_types ) ) { $ classname = $ this -> setting_types [ $ args [ 'option_type' ] ] ; } if ( ! isset ( $ args [ 'type' ] ) || ! array_key_exists ( $ args [ 'type' ] , $ this -> setting_types ) ) { $ args [ 'type' ] = 'default' ; } $ classname = ! $ classname ? $ this -> setting_types [ $ args [ 'type' ] ] : $ classname ; if ( isset ( $ args [ 'settings' ] ) && is_array ( $ args [ 'settings' ] ) ) { if ( ! isset ( $ args [ 'default' ] ) || ! is_array ( $ args [ 'default' ] ) ) { $ args [ 'default' ] = [ ] ; } foreach ( $ args [ 'settings' ] as $ key => $ value ) { $ default = ( isset ( $ defaults [ $ key ] ) ) ? $ defaults [ $ key ] : '' ; $ this -> add_setting ( $ classname , $ value , $ default , $ args [ 'option_type' ] , $ args [ 'capability' ] , $ args [ 'transport' ] , $ args [ 'sanitize_callback' ] ) ; } } $ this -> add_setting ( $ classname , $ args [ 'settings' ] , $ args [ 'default' ] , $ args [ 'option_type' ] , $ args [ 'capability' ] , $ args [ 'transport' ] , $ args [ 'sanitize_callback' ] ) ; }
|
Adds the settings for this field . If settings are defined as an array then it goes through them and calls the add_setting method . If not an array then it just calls add_setting
|
9,233
|
final private function add_setting ( $ classname , $ setting , $ default , $ type , $ capability , $ transport , $ sanitize_callback ) { $ this -> wp_customize -> add_setting ( new $ classname ( $ this -> wp_customize , $ setting , [ 'default' => $ default , 'type' => $ type , 'capability' => $ capability , 'transport' => $ transport , 'sanitize_callback' => $ sanitize_callback , ] ) ) ; }
|
This is where we re finally adding the setting to the Customizer .
|
9,234
|
public function customize_controls_enqueue_scripts ( ) { $ sections = Kirki :: $ sections ; $ panels = Kirki :: $ panels ; foreach ( $ sections as $ section ) { if ( isset ( $ section [ 'icon' ] ) ) { $ this -> add_icon ( $ section [ 'id' ] , $ section [ 'icon' ] , 'section' ) ; } } foreach ( $ panels as $ panel ) { if ( isset ( $ panel [ 'icon' ] ) ) { $ this -> add_icon ( $ panel [ 'id' ] , $ panel [ 'icon' ] , 'panel' ) ; } } wp_enqueue_script ( 'kirki_panel_and_section_icons' , URL :: get_from_path ( __DIR__ . '/icons.js' ) , [ 'jquery' , 'customize-base' , 'customize-controls' ] , KIRKI_VERSION , true ) ; wp_localize_script ( 'kirki_panel_and_section_icons' , 'kirkiIcons' , self :: $ icons ) ; }
|
Format the script in a way that will be compatible with WordPress .
|
9,235
|
public static function array_replace_recursive ( $ array , $ array1 ) { if ( function_exists ( 'array_replace_recursive' ) ) { return array_replace_recursive ( $ array , $ array1 ) ; } $ args = func_get_args ( ) ; $ array = $ args [ 0 ] ; if ( ! is_array ( $ array ) ) { return $ array ; } $ count = count ( $ args ) ; for ( $ i = 1 ; $ i < $ count ; $ i ++ ) { if ( is_array ( $ args [ $ i ] ) ) { $ array = self :: recurse ( $ array , $ args [ $ i ] ) ; } } return $ array ; }
|
Recursive replace in arrays .
|
9,236
|
public static function recurse ( $ array , $ array1 ) { foreach ( $ array1 as $ key => $ value ) { if ( ! isset ( $ array [ $ key ] ) || ( isset ( $ array [ $ key ] ) && ! is_array ( $ array [ $ key ] ) ) ) { $ array [ $ key ] = [ ] ; } if ( is_array ( $ value ) ) { $ value = self :: recurse ( $ array [ $ key ] , $ value ) ; } $ array [ $ key ] = $ value ; } return $ array ; }
|
Helper method to be used from the array_replace_recursive method .
|
9,237
|
public static function init_filesystem ( ) { $ credentials = [ ] ; if ( ! defined ( 'FS_METHOD' ) ) { define ( 'FS_METHOD' , 'direct' ) ; } $ method = defined ( 'FS_METHOD' ) ? FS_METHOD : false ; if ( 'ftpext' === $ method ) { $ credentials [ 'hostname' ] = defined ( 'FTP_HOST' ) ? preg_replace ( '|\w+://|' , '' , FTP_HOST ) : null ; $ credentials [ 'username' ] = defined ( 'FTP_USER' ) ? FTP_USER : null ; $ credentials [ 'password' ] = defined ( 'FTP_PASS' ) ? FTP_PASS : null ; if ( strpos ( $ credentials [ 'hostname' ] , ':' ) && null !== $ credentials [ 'hostname' ] ) { list ( $ credentials [ 'hostname' ] , $ credentials [ 'port' ] ) = explode ( ':' , $ credentials [ 'hostname' ] , 2 ) ; if ( ! is_numeric ( $ credentials [ 'port' ] ) ) { unset ( $ credentials [ 'port' ] ) ; } } else { unset ( $ credentials [ 'port' ] ) ; } if ( ( defined ( 'FTP_SSL' ) && FTP_SSL ) && 'ftpext' === $ method ) { $ credentials [ 'connection_type' ] = 'ftps' ; } elseif ( ! array_filter ( $ credentials ) ) { $ credentials [ 'connection_type' ] = null ; } else { $ credentials [ 'connection_type' ] = 'ftp' ; } } global $ wp_filesystem ; if ( empty ( $ wp_filesystem ) ) { require_once wp_normalize_path ( ABSPATH . '/wp-admin/includes/file.php' ) ; WP_Filesystem ( $ credentials ) ; } return $ wp_filesystem ; }
|
Initialize the WP_Filesystem
|
9,238
|
public static function get_image_id ( $ url ) { global $ wpdb ; if ( empty ( $ url ) ) { return 0 ; } $ attachment = wp_cache_get ( 'kirki_image_id_' . md5 ( $ url ) , null ) ; if ( false === $ attachment ) { $ attachment = $ wpdb -> get_col ( $ wpdb -> prepare ( "SELECT ID FROM $wpdb->posts WHERE guid = %s;" , $ url ) ) ; wp_cache_add ( 'kirki_image_id_' . md5 ( $ url ) , $ attachment , null ) ; } if ( ! empty ( $ attachment ) ) { return $ attachment [ 0 ] ; } return 0 ; }
|
Returns the attachment object
|
9,239
|
public static function get_image_from_url ( $ url ) { $ image_id = self :: get_image_id ( $ url ) ; $ image = wp_get_attachment_image_src ( $ image_id , 'full' ) ; return [ 'url' => $ image [ 0 ] , 'width' => $ image [ 1 ] , 'height' => $ image [ 2 ] , 'thumbnail' => $ image [ 3 ] , ] ; }
|
Returns an array of the attachment s properties .
|
9,240
|
public static function get_posts ( $ args ) { if ( is_string ( $ args ) ) { $ args = add_query_arg ( [ 'suppress_filters' => false , ] ) ; } elseif ( is_array ( $ args ) && ! isset ( $ args [ 'suppress_filters' ] ) ) { $ args [ 'suppress_filters' ] = false ; } $ posts = get_posts ( $ args ) ; $ items = [ ] ; foreach ( $ posts as $ post ) { $ items [ $ post -> ID ] = $ post -> post_title ; } wp_reset_postdata ( ) ; return $ items ; }
|
Get an array of posts .
|
9,241
|
public static function get_taxonomies ( ) { $ items = [ ] ; $ taxonomies = get_taxonomies ( [ 'public' => true , ] ) ; foreach ( $ taxonomies as $ taxonomy ) { $ id = $ taxonomy ; $ taxonomy = get_taxonomy ( $ taxonomy ) ; $ items [ $ id ] = $ taxonomy -> labels -> name ; } return $ items ; }
|
Get an array of publicly - querable taxonomies .
|
9,242
|
public static function get_post_types ( ) { $ items = [ ] ; $ post_types = get_post_types ( [ 'public' => true , ] , 'objects' ) ; foreach ( $ post_types as $ post_type ) { $ items [ $ post_type -> name ] = $ post_type -> labels -> name ; } return $ items ; }
|
Get an array of publicly - querable post - types .
|
9,243
|
public static function get_terms ( $ taxonomies ) { $ items = [ ] ; $ terms = get_terms ( $ taxonomies ) ; foreach ( $ terms as $ term ) { $ items [ $ term -> term_id ] = $ term -> name ; } return $ items ; }
|
Get an array of terms from a taxonomy
|
9,244
|
public static function compare_values ( $ value1 , $ value2 , $ operator ) { if ( '===' === $ operator ) { return $ value1 === $ value2 ; } if ( '!==' === $ operator ) { return $ value1 !== $ value2 ; } if ( ( '!=' === $ operator || 'not equal' === $ operator ) ) { return $ value1 != $ value2 ; } if ( ( '>=' === $ operator || 'greater or equal' === $ operator || 'equal or greater' === $ operator ) ) { return $ value2 >= $ value1 ; } if ( ( '<=' === $ operator || 'smaller or equal' === $ operator || 'equal or smaller' === $ operator ) ) { return $ value2 <= $ value1 ; } if ( ( '>' === $ operator || 'greater' === $ operator ) ) { return $ value2 > $ value1 ; } if ( ( '<' === $ operator || 'smaller' === $ operator ) ) { return $ value2 < $ value1 ; } if ( 'contains' === $ operator || 'in' === $ operator ) { if ( is_array ( $ value1 ) && is_array ( $ value2 ) ) { foreach ( $ value2 as $ val ) { if ( in_array ( $ val , $ value1 ) ) { return true ; } } return false ; } if ( is_array ( $ value1 ) && ! is_array ( $ value2 ) ) { return in_array ( $ value2 , $ value1 ) ; } if ( is_array ( $ value2 ) && ! is_array ( $ value1 ) ) { return in_array ( $ value1 , $ value2 ) ; } return ( false !== strrpos ( $ value1 , $ value2 ) || false !== strpos ( $ value2 , $ value1 ) ) ; } return $ value1 == $ value2 ; }
|
Compares the 2 values given the condition
|
9,245
|
public function add_panel ( $ args ) { global $ wp_customize ; if ( ! isset ( $ args [ 'type' ] ) || ! array_key_exists ( $ args [ 'type' ] , $ this -> panel_types ) ) { $ args [ 'type' ] = 'default' ; } $ panel_classname = $ this -> panel_types [ $ args [ 'type' ] ] ; $ wp_customize -> add_panel ( new $ panel_classname ( $ wp_customize , $ args [ 'id' ] , $ args ) ) ; }
|
Add the panel using the Customizer API .
|
9,246
|
public function process_fonts ( ) { if ( empty ( $ this -> fonts ) ) { return ; } foreach ( $ this -> fonts as $ font => $ variants ) { if ( ! array_key_exists ( $ font , $ this -> google_fonts ) ) { unset ( $ this -> fonts [ $ font ] ) ; continue ; } $ font_variants = [ ] ; if ( isset ( $ this -> google_fonts [ $ font ] [ 'variants' ] ) ) { $ font_variants = $ this -> google_fonts [ $ font ] [ 'variants' ] ; } foreach ( $ variants as $ variant ) { if ( ! in_array ( strval ( $ variant ) , $ font_variants , true ) ) { $ variant_key = array_search ( $ variant , $ this -> fonts [ $ font ] , true ) ; unset ( $ this -> fonts [ $ font ] [ $ variant_key ] ) ; continue ; } } } }
|
Determines the vbalidity of the selected font as well as its properties . This is vital to make sure that the google - font script that we ll generate later does not contain any invalid options .
|
9,247
|
public static function get_all_fonts ( ) { $ standard_fonts = self :: get_standard_fonts ( ) ; $ google_fonts = self :: get_google_fonts ( ) ; return apply_filters ( 'kirki_fonts_all' , array_merge ( $ standard_fonts , $ google_fonts ) ) ; }
|
Compile font options from different sources .
|
9,248
|
public static function get_all_variants ( ) { return [ '100' => esc_html__ ( 'Ultra-Light 100' , 'kirki' ) , '100light' => esc_html__ ( 'Ultra-Light 100' , 'kirki' ) , '100italic' => esc_html__ ( 'Ultra-Light 100 Italic' , 'kirki' ) , '200' => esc_html__ ( 'Light 200' , 'kirki' ) , '200italic' => esc_html__ ( 'Light 200 Italic' , 'kirki' ) , '300' => esc_html__ ( 'Book 300' , 'kirki' ) , '300italic' => esc_html__ ( 'Book 300 Italic' , 'kirki' ) , '400' => esc_html__ ( 'Normal 400' , 'kirki' ) , 'regular' => esc_html__ ( 'Normal 400' , 'kirki' ) , 'italic' => esc_html__ ( 'Normal 400 Italic' , 'kirki' ) , '500' => esc_html__ ( 'Medium 500' , 'kirki' ) , '500italic' => esc_html__ ( 'Medium 500 Italic' , 'kirki' ) , '600' => esc_html__ ( 'Semi-Bold 600' , 'kirki' ) , '600bold' => esc_html__ ( 'Semi-Bold 600' , 'kirki' ) , '600italic' => esc_html__ ( 'Semi-Bold 600 Italic' , 'kirki' ) , '700' => esc_html__ ( 'Bold 700' , 'kirki' ) , '700italic' => esc_html__ ( 'Bold 700 Italic' , 'kirki' ) , '800' => esc_html__ ( 'Extra-Bold 800' , 'kirki' ) , '800bold' => esc_html__ ( 'Extra-Bold 800' , 'kirki' ) , '800italic' => esc_html__ ( 'Extra-Bold 800 Italic' , 'kirki' ) , '900' => esc_html__ ( 'Ultra-Bold 900' , 'kirki' ) , '900bold' => esc_html__ ( 'Ultra-Bold 900' , 'kirki' ) , '900italic' => esc_html__ ( 'Ultra-Bold 900 Italic' , 'kirki' ) , ] ; }
|
Returns an array of all available variants .
|
9,249
|
public static function is_google_font ( $ fontname ) { if ( is_string ( $ fontname ) ) { $ fonts = self :: get_google_fonts ( ) ; return isset ( $ fonts [ $ fontname ] ) ; } return false ; }
|
Determine if a font - name is a valid google font or not .
|
9,250
|
public static function get_font_choices ( ) { $ fonts = self :: get_all_fonts ( ) ; $ fonts_array = [ ] ; foreach ( $ fonts as $ key => $ args ) { $ fonts_array [ $ key ] = $ key ; } return $ fonts_array ; }
|
Gets available options for a font .
|
9,251
|
public static function get_instance ( $ id = 'global' , $ args = [ ] ) { if ( empty ( $ id ) ) { $ id = 'global' ; } $ id_md5 = md5 ( $ id ) ; if ( ! isset ( self :: $ instances [ $ id_md5 ] ) ) { self :: $ instances [ $ id_md5 ] = new self ( $ id , $ args ) ; } return self :: $ instances [ $ id_md5 ] ; }
|
Use this method to get an instance of your config . Each config has its own instance of this object .
|
9,252
|
public static function get_config_ids ( ) { $ configs = [ ] ; foreach ( self :: $ instances as $ instance ) { $ configs [ ] = $ instance -> id ; } return array_unique ( $ configs ) ; }
|
Get the IDs of all current configs .
|
9,253
|
protected function set_type ( ) { global $ wp_version ; if ( version_compare ( $ wp_version , '4.8' ) >= 0 ) { $ this -> type = 'kirki-editor' ; return ; } $ this -> type = 'kirki-generic' ; if ( ! is_array ( $ this -> choices ) ) { $ this -> choices = [ ] ; } $ this -> choices [ 'element' ] = 'textarea' ; $ this -> choices [ 'rows' ] = '5' ; }
|
Sets the control type .
|
9,254
|
public function sanitize ( $ value = [ ] ) { if ( is_string ( $ value ) || is_numeric ( $ value ) ) { return [ sanitize_text_field ( $ value ) , ] ; } $ sanitized_value = [ ] ; foreach ( $ value as $ sub_value ) { if ( isset ( $ this -> choices [ $ sub_value ] ) ) { $ sanitized_value [ ] = sanitize_text_field ( $ sub_value ) ; } } return $ sanitized_value ; }
|
Sanitizes sortable values .
|
9,255
|
public static function get_option ( $ config_id = '' , $ field_id = '' ) { if ( class_exists ( 'Kirki' ) ) { return Kirki :: get_option ( $ config_id , $ field_id ) ; } $ default = '' ; if ( isset ( self :: $ fields [ $ field_id ] ) && isset ( self :: $ fields [ $ field_id ] [ 'default' ] ) ) { $ default = self :: $ fields [ $ field_id ] [ 'default' ] ; } if ( isset ( self :: $ config [ $ config_id ] ) ) { if ( 'option' === self :: $ config [ $ config_id ] [ 'option_type' ] ) { if ( isset ( self :: $ config [ $ config_id ] [ 'option_name' ] ) && ! empty ( self :: $ config [ $ config_id ] [ 'option_name' ] ) ) { $ all_options = get_option ( self :: $ config [ $ config_id ] [ 'option_name' ] , array ( ) ) ; return ( ! isset ( $ all_options [ $ field_id ] ) ) ? $ default : maybe_unserialize ( $ all_options [ $ field_id ] ) ; } $ dummy = md5 ( $ config_id . '_UNDEFINED_VALUE' ) ; $ value = get_option ( $ field_id , $ dummy ) ; return ( $ dummy === $ value ) ? $ default : $ value ; } return get_theme_mod ( $ field_id , $ default ) ; } }
|
Get the value of an option from the db .
|
9,256
|
public static function add_field ( $ config_id , $ args ) { if ( class_exists ( 'Kirki' ) ) { Kirki :: add_field ( $ config_id , $ args ) ; return ; } if ( isset ( $ args [ 'settings' ] ) && isset ( $ args [ 'type' ] ) ) { if ( ! isset ( $ args [ 'kirki_config' ] ) ) { $ args [ 'kirki_config' ] = $ config_id ; } self :: $ fields [ $ args [ 'settings' ] ] = $ args ; } }
|
Create a new field
|
9,257
|
public function enqueue_styles ( ) { if ( class_exists ( 'Kirki' ) ) { return ; } $ styles = $ this -> get_styles ( ) ; if ( ! empty ( $ styles ) ) { $ current_theme = ( wp_get_theme ( ) ) ; wp_enqueue_style ( $ current_theme -> stylesheet . '_no-kirki' , get_stylesheet_uri ( ) , array ( ) , '1.0' ) ; wp_add_inline_style ( $ current_theme -> stylesheet . '_no-kirki' , $ styles ) ; } }
|
Enqueues the stylesheet .
|
9,258
|
public function enqueue_fonts ( ) { if ( empty ( self :: $ fields ) || ! is_array ( self :: $ fields ) ) { return ; } foreach ( self :: $ fields as $ field ) { if ( isset ( $ field [ 'type' ] ) && 'typography' === $ field [ 'type' ] ) { if ( ! isset ( $ field [ 'kirki_config' ] ) || ! isset ( $ field [ 'settings' ] ) ) { continue ; } $ value = self :: get_option ( $ field [ 'kirki_config' ] , $ field [ 'settings' ] ) ; if ( isset ( $ value [ 'font-family' ] ) ) { $ url = '//fonts.googleapis.com/css?family=' . str_replace ( ' ' , '+' , $ value [ 'font-family' ] ) ; $ value [ 'variant' ] = ( isset ( $ value [ 'variant' ] ) ) ? $ value [ 'variant' ] : '' ; $ url .= ( empty ( $ value [ 'variant' ] ) ) ? '' : ':' . $ value [ 'variant' ] ; $ key = md5 ( $ value [ 'font-family' ] . $ value [ 'variant' ] ) ; $ url_is_valid = get_transient ( $ key ) ; if ( false === $ url_is_valid ) { $ response = wp_remote_get ( 'https:' . $ url ) ; if ( ! is_array ( $ response ) ) { set_transient ( $ key , null , 12 * HOUR_IN_SECONDS ) ; continue ; } if ( isset ( $ response [ 'response' ] ) && isset ( $ response [ 'response' ] [ 'code' ] ) ) { if ( 200 === $ response [ 'response' ] [ 'code' ] ) { set_transient ( $ key , true , 7 * 24 * HOUR_IN_SECONDS ) ; $ url_is_valid = true ; } } } if ( $ url_is_valid ) { wp_enqueue_style ( $ key , $ url , array ( ) , '1.0' ) ; } } } } }
|
Enqueue google fonts .
|
9,259
|
private function add_main_field ( $ config_id , $ args ) { Kirki :: add_field ( $ config_id , wp_parse_args ( [ 'type' => 'kirki-generic' , 'sanitize_callback' => isset ( $ args [ 'sanitize_callback' ] ) ? $ args [ 'sanitize_callback' ] : [ __CLASS__ , 'sanitize' ] , 'choices' => [ 'type' => 'hidden' , 'parent_type' => 'kirki-typography' , ] , ] , $ args ) ) ; }
|
Adds the main field .
|
9,260
|
public static function sanitize ( $ value ) { if ( ! is_array ( $ value ) ) { return [ ] ; } foreach ( $ value as $ key => $ val ) { switch ( $ key ) { case 'font-family' : $ value [ 'font-family' ] = sanitize_text_field ( $ val ) ; break ; case 'font-weight' : if ( isset ( $ value [ 'variant' ] ) ) { break ; } $ value [ 'variant' ] = $ val ; if ( isset ( $ value [ 'font-style' ] ) && 'italic' === $ value [ 'font-style' ] ) { $ value [ 'variant' ] = ( '400' !== $ val || 400 !== $ val ) ? $ value [ 'variant' ] . 'italic' : 'italic' ; } break ; case 'variant' : $ value [ 'variant' ] = ( 400 === $ val || '400' === $ val ) ? 'regular' : $ val ; $ value [ 'font-weight' ] = filter_var ( $ value [ 'variant' ] , FILTER_SANITIZE_NUMBER_FLOAT , FILTER_FLAG_ALLOW_FRACTION ) ; $ value [ 'font-weight' ] = ( 'regular' === $ value [ 'variant' ] || 'italic' === $ value [ 'variant' ] ) ? 400 : ( string ) absint ( $ value [ 'font-weight' ] ) ; if ( ! isset ( $ value [ 'font-style' ] ) ) { $ value [ 'font-style' ] = ( false === strpos ( $ value [ 'variant' ] , 'italic' ) ) ? 'normal' : 'italic' ; } break ; case 'font-size' : case 'letter-spacing' : case 'word-spacing' : case 'line-height' : $ value [ $ key ] = '' === trim ( $ value [ $ key ] ) ? '' : sanitize_text_field ( $ val ) ; break ; case 'text-align' : if ( ! in_array ( $ val , [ '' , 'inherit' , 'left' , 'center' , 'right' , 'justify' ] , true ) ) { $ value [ 'text-align' ] = '' ; } break ; case 'text-transform' : if ( ! in_array ( $ val , [ '' , 'none' , 'capitalize' , 'uppercase' , 'lowercase' , 'initial' , 'inherit' ] , true ) ) { $ value [ 'text-transform' ] = '' ; } break ; case 'text-decoration' : if ( ! in_array ( $ val , [ '' , 'none' , 'underline' , 'overline' , 'line-through' , 'initial' , 'inherit' ] , true ) ) { $ value [ 'text-transform' ] = '' ; } break ; case 'color' : $ value [ 'color' ] = '' === $ value [ 'color' ] ? '' : \ ariColor :: newColor ( $ val ) -> toCSS ( 'hex' ) ; break ; } } return $ value ; }
|
Sanitizes typography controls
|
9,261
|
public function enqueue_scripts ( ) { wp_enqueue_style ( 'kirki-control-typography-style' , URL :: get_from_path ( dirname ( __DIR__ ) . '/assets/styles/style.css' ) , [ ] , '1.0' ) ; wp_enqueue_script ( 'kirki-typography' , URL :: get_from_path ( dirname ( __DIR__ ) . '/assets/scripts/script.js' ) , [ ] , '1.0' , true ) ; wp_localize_script ( 'kirki-typography' , 'kirkiTypographyControls' , self :: $ typography_controls ) ; if ( ! self :: $ gfonts_var_added ) { echo '<script>kirkiGoogleFonts=' ; $ google = new GoogleFonts ( ) ; $ google -> print_googlefonts_json ( false ) ; echo ';</script>' ; self :: $ gfonts_var_added = true ; } }
|
Enqueue scripts & styles .
|
9,262
|
protected function set_field ( ) { $ properties = get_class_vars ( __CLASS__ ) ; $ this -> set_option_type ( ) ; $ this -> set_settings ( ) ; foreach ( $ properties as $ property => $ value ) { if ( in_array ( $ property , [ 'option_name' , 'option_type' , 'settings' ] , true ) ) { continue ; } if ( method_exists ( $ this , 'set_' . $ property ) ) { $ method_name = 'set_' . $ property ; $ this -> $ method_name ( ) ; } } $ args = get_object_vars ( $ this ) ; foreach ( array_keys ( $ args ) as $ key ) { $ args [ $ key ] = $ this -> $ key ; } Kirki :: $ fields [ $ this -> settings ] = $ args ; }
|
Processes the field arguments
|
9,263
|
protected function set_option_type ( ) { if ( 'options' === $ this -> option_type ) { $ this -> option_type = 'option' ; } if ( 'theme_mods' === $ this -> option_type ) { _doing_it_wrong ( __METHOD__ , sprintf ( esc_html ( 'Typo found in field %s - "theme_mods" vs "theme_mod"' , 'kirki' ) , esc_html ( $ this -> settings ) ) , '3.0.10' ) ; $ this -> option_type = 'theme_mod' ; } }
|
Make sure we re using the correct option_type
|
9,264
|
protected function set_partial_refresh ( ) { if ( ! is_array ( $ this -> partial_refresh ) ) { $ this -> partial_refresh = [ ] ; } foreach ( $ this -> partial_refresh as $ id => $ args ) { if ( ! is_array ( $ args ) || ! isset ( $ args [ 'selector' ] ) || ! isset ( $ args [ 'render_callback' ] ) || ! is_callable ( $ args [ 'render_callback' ] ) ) { _doing_it_wrong ( __METHOD__ , sprintf ( esc_html__ ( '"partial_refresh" invalid entry in field %s' , 'kirki' ) , esc_html ( $ this -> settings ) ) , '3.0.10' ) ; unset ( $ this -> partial_refresh [ $ id ] ) ; continue ; } } if ( ! empty ( $ this -> partial_refresh ) ) { $ this -> transport = 'postMessage' ; } }
|
Modifications for partial refreshes .
|
9,265
|
protected function set_settings ( ) { if ( ! is_array ( $ this -> settings ) ) { $ this -> settings = [ 'kirki_placeholder_setting' => $ this -> settings , ] ; } $ settings = [ ] ; foreach ( $ this -> settings as $ setting_key => $ setting_value ) { $ settings [ $ setting_key ] = $ setting_value ; if ( 'option' === $ this -> option_type && '' !== $ this -> option_name && ( false === strpos ( $ setting_key , '[' ) ) ) { $ settings [ $ setting_key ] = "{$this->option_name}[{$setting_value}]" ; } } $ this -> settings = $ settings ; if ( isset ( $ this -> settings [ 'kirki_placeholder_setting' ] ) ) { $ this -> settings = $ this -> settings [ 'kirki_placeholder_setting' ] ; } }
|
Sets the settings . If we re using serialized options it makes sure that settings are properly formatted . We ll also be escaping all setting names here for consistency .
|
9,266
|
public function copyUntilUnless ( string $ string , string $ unless ) { $ lastPos = $ this -> pos ; $ this -> fastForward ( 1 ) ; $ foundString = $ this -> copyUntil ( $ string , true , true ) ; $ position = strcspn ( $ foundString , $ unless ) ; if ( $ position == strlen ( $ foundString ) ) { return $ string . $ foundString ; } $ this -> pos = $ lastPos ; return '' ; }
|
Copies the content until the string is found and return it unless the unless is found in the substring .
|
9,267
|
public function copyByToken ( string $ token , bool $ char = false , bool $ escape = false ) { $ string = $ this -> $ token ; return $ this -> copyUntil ( $ string , $ char , $ escape ) ; }
|
Copies the content until it reaches the token string .
|
9,268
|
public function skip ( string $ string , bool $ copy = false ) { $ len = strspn ( $ this -> content , $ string , $ this -> pos ) ; $ return = $ this ; if ( $ copy ) { $ return = substr ( $ this -> content , $ this -> pos , $ len ) ; } $ this -> pos += $ len ; return $ return ; }
|
Skip a given set of characters .
|
9,269
|
public function propagateEncoding ( Encode $ encode ) : void { $ this -> encode = $ encode ; $ this -> tag -> setEncoding ( $ encode ) ; foreach ( $ this -> children as $ id => $ child ) { $ node = $ child [ 'node' ] ; $ node -> propagateEncoding ( $ encode ) ; } }
|
Sets the encoding class to this node and propagates it to all its children .
|
9,270
|
public function insertBefore ( AbstractNode $ child , int $ id ) : bool { return $ this -> addChild ( $ child , $ id ) ; }
|
Insert element before child with provided id
|
9,271
|
public function insertAfter ( AbstractNode $ child , int $ id ) : bool { if ( ! isset ( $ this -> children [ $ id ] ) ) { return false ; } if ( $ this -> children [ $ id ] [ 'next' ] ) { return $ this -> addChild ( $ child , $ this -> children [ $ id ] [ 'next' ] ) ; } $ this -> clear ( ) ; return $ this -> addChild ( $ child ) ; }
|
Insert element before after with provided id
|
9,272
|
public function removeChild ( int $ id ) : InnerNode { if ( ! isset ( $ this -> children [ $ id ] ) ) { return $ this ; } $ next = $ this -> children [ $ id ] [ 'next' ] ; $ prev = $ this -> children [ $ id ] [ 'prev' ] ; if ( ! is_null ( $ next ) ) { $ this -> children [ $ next ] [ 'prev' ] = $ prev ; } if ( ! is_null ( $ prev ) ) { $ this -> children [ $ prev ] [ 'next' ] = $ next ; } unset ( $ this -> children [ $ id ] ) ; $ this -> clear ( ) ; return $ this ; }
|
Removes the child by id .
|
9,273
|
public function hasNextChild ( int $ id ) { $ child = $ this -> getChild ( $ id ) ; return $ this -> children [ $ child -> id ( ) ] [ 'next' ] ; }
|
Check if has next Child
|
9,274
|
public function isDescendant ( int $ id ) : bool { if ( $ this -> isChild ( $ id ) ) { return true ; } foreach ( $ this -> children as $ childId => $ child ) { $ node = $ child [ 'node' ] ; if ( $ node instanceof InnerNode && $ node -> hasChildren ( ) && $ node -> isDescendant ( $ id ) ) { return true ; } } return false ; }
|
Checks if the given node id is a descendant of the current node .
|
9,275
|
public function setStyleAttributeValue ( $ attr_key , $ attr_value ) : void { $ style_array = $ this -> getStyleAttributeArray ( ) ; $ style_array [ $ attr_key ] = $ attr_value ; $ style_string = '' ; foreach ( $ style_array as $ key => $ value ) { $ style_string .= $ key . ':' . $ value . ';' ; } $ this -> setAttribute ( 'style' , $ style_string ) ; }
|
Set inline style attribute value .
|
9,276
|
public function getStyleAttributeArray ( ) : array { $ value = $ this -> getAttribute ( 'style' ) [ 'value' ] ; if ( $ value === null ) { return [ ] ; } $ value = explode ( ';' , substr ( trim ( $ value ) , 0 , - 1 ) ) ; $ result = [ ] ; foreach ( $ value as $ attr ) { $ attr = explode ( ':' , $ attr ) ; $ result [ $ attr [ 0 ] ] = $ attr [ 1 ] ; } return $ result ; }
|
Get style attribute in array
|
9,277
|
public function setAttributes ( array $ attr ) { foreach ( $ attr as $ key => $ value ) { $ this -> setAttribute ( $ key , $ value ) ; } return $ this ; }
|
Sets the attributes for this tag
|
9,278
|
public function getAttributes ( ) { $ return = [ ] ; foreach ( $ this -> attr as $ attr => $ info ) { $ return [ $ attr ] = $ this -> getAttribute ( $ attr ) ; } return $ return ; }
|
Returns all attributes of this tag .
|
9,279
|
public function makeOpeningTag ( ) { $ return = '<' . $ this -> name ; foreach ( $ this -> attr as $ key => $ info ) { $ info = $ this -> getAttribute ( $ key ) ; $ val = $ info [ 'value' ] ; if ( is_null ( $ val ) ) { $ return .= ' ' . $ key ; } elseif ( $ info [ 'doubleQuote' ] ) { $ return .= ' ' . $ key . '="' . $ val . '"' ; } else { $ return .= ' ' . $ key . '=\'' . $ val . '\'' ; } } if ( $ this -> selfClosing && $ this -> trailingSlash ) { return $ return . ' />' ; } else { return $ return . '>' ; } }
|
Generates the opening tag for this object .
|
9,280
|
public function text ( ) : string { if ( ! is_null ( $ this -> encode ) ) { if ( ! is_null ( $ this -> convertedText ) ) { return $ this -> convertedText ; } $ text = $ this -> encode -> convert ( $ this -> text ) ; $ this -> convertedText = $ text ; return $ text ; } else { return $ this -> text ; } }
|
Returns the text of this node .
|
9,281
|
public function setText ( string $ text ) : void { $ this -> text = $ text ; if ( ! is_null ( $ this -> encode ) ) { $ text = $ this -> encode -> convert ( $ text ) ; $ this -> convertedText = $ text ; } }
|
Sets the text for this node .
|
9,282
|
public function addNoSlashTag ( $ tag ) : Dom { if ( ! is_array ( $ tag ) ) { $ tag = [ $ tag ] ; } foreach ( $ tag as $ value ) { $ this -> noSlash [ ] = $ value ; } return $ this ; }
|
Adds a tag to the list of self closing tags that should not have a trailing slash
|
9,283
|
public function removeNoSlashTag ( $ tag ) : Dom { if ( ! is_array ( $ tag ) ) { $ tag = [ $ tag ] ; } $ this -> noSlash = array_diff ( $ this -> noSlash , $ tag ) ; return $ this ; }
|
Removes a tag from the list of no - slash tags .
|
9,284
|
protected function parse ( ) : void { $ this -> root = new HtmlNode ( 'root' ) ; $ activeNode = $ this -> root ; while ( ! is_null ( $ activeNode ) ) { $ str = $ this -> content -> copyUntil ( '<' ) ; if ( $ str == '' ) { $ info = $ this -> parseTag ( ) ; if ( ! $ info [ 'status' ] ) { $ activeNode = null ; continue ; } if ( $ info [ 'closing' ] ) { $ foundOpeningTag = true ; $ originalNode = $ activeNode ; while ( $ activeNode -> getTag ( ) -> name ( ) != $ info [ 'tag' ] ) { $ activeNode = $ activeNode -> getParent ( ) ; if ( is_null ( $ activeNode ) ) { $ activeNode = $ originalNode ; $ foundOpeningTag = false ; break ; } } if ( $ foundOpeningTag ) { $ activeNode = $ activeNode -> getParent ( ) ; } continue ; } if ( ! isset ( $ info [ 'node' ] ) ) { continue ; } $ node = $ info [ 'node' ] ; $ activeNode -> addChild ( $ node ) ; if ( ! $ node -> getTag ( ) -> isSelfClosing ( ) ) { $ activeNode = $ node ; } } else if ( $ this -> options -> whitespaceTextNode || trim ( $ str ) != '' ) { $ textNode = new TextNode ( $ str , $ this -> options -> removeDoubleSpace ) ; $ activeNode -> addChild ( $ textNode ) ; } } }
|
Attempts to parse the html in content .
|
9,285
|
protected function detectCharset ( ) : bool { $ encode = new Encode ; $ encode -> from ( $ this -> defaultCharset ) ; $ encode -> to ( $ this -> defaultCharset ) ; if ( ! is_null ( $ this -> options -> enforceEncoding ) ) { $ encode -> from ( $ this -> options -> enforceEncoding ) ; $ encode -> to ( $ this -> options -> enforceEncoding ) ; return false ; } $ meta = $ this -> root -> find ( 'meta[http-equiv=Content-Type]' , 0 ) ; if ( is_null ( $ meta ) ) { $ this -> root -> propagateEncoding ( $ encode ) ; return false ; } $ content = $ meta -> content ; if ( empty ( $ content ) ) { $ this -> root -> propagateEncoding ( $ encode ) ; return false ; } $ matches = [ ] ; if ( preg_match ( '/charset=(.+)/' , $ content , $ matches ) ) { $ encode -> from ( trim ( $ matches [ 1 ] ) ) ; $ this -> root -> propagateEncoding ( $ encode ) ; return true ; } $ this -> root -> propagateEncoding ( $ encode ) ; return false ; }
|
Attempts to detect the charset that the html was sent in .
|
9,286
|
public function find ( AbstractNode $ node ) : Collection { $ results = new Collection ; foreach ( $ this -> selectors as $ selector ) { $ nodes = [ $ node ] ; if ( count ( $ selector ) == 0 ) { continue ; } $ options = [ ] ; foreach ( $ selector as $ rule ) { if ( $ rule [ 'alterNext' ] ) { $ options [ ] = $ this -> alterNext ( $ rule ) ; continue ; } $ nodes = $ this -> seek ( $ nodes , $ rule , $ options ) ; $ options = [ ] ; } foreach ( $ nodes as $ result ) { $ results [ ] = $ result ; } } return $ results ; }
|
Attempts to find the selectors starting from the given node object .
|
9,287
|
protected function flattenOptions ( array $ optionsArray ) { $ options = [ ] ; foreach ( $ optionsArray as $ optionArray ) { foreach ( $ optionArray as $ key => $ option ) { $ options [ $ key ] = $ option ; } } return $ options ; }
|
Flattens the option array .
|
9,288
|
protected function getNextChild ( AbstractNode $ node , AbstractNode $ currentChild ) { try { $ child = $ node -> nextChild ( $ currentChild -> id ( ) ) ; } catch ( ChildNotFoundException $ e ) { $ child = null ; } return $ child ; }
|
Returns the next child or null if no more children .
|
9,289
|
protected function checkTag ( array $ rule , AbstractNode $ node ) : bool { if ( ! empty ( $ rule [ 'tag' ] ) && $ rule [ 'tag' ] != $ node -> getTag ( ) -> name ( ) && $ rule [ 'tag' ] != '*' ) { return false ; } return true ; }
|
Checks tag condition from rules against node .
|
9,290
|
protected function checkKey ( array $ rule , AbstractNode $ node ) : bool { if ( $ rule [ 'noKey' ] ) { if ( ! is_null ( $ node -> getAttribute ( $ rule [ 'key' ] ) ) ) { return false ; } } else { if ( $ rule [ 'key' ] != 'plaintext' && ! $ node -> hasAttribute ( $ rule [ 'key' ] ) ) { return false ; } } return true ; }
|
Checks key condition from rules against node .
|
9,291
|
public function checkComparison ( array $ rule , AbstractNode $ node ) : bool { if ( $ rule [ 'key' ] == 'plaintext' ) { $ nodeValue = $ node -> text ( ) ; } else { $ nodeValue = $ node -> getAttribute ( $ rule [ 'key' ] ) ; } $ check = $ this -> match ( $ rule [ 'operator' ] , $ rule [ 'value' ] , $ nodeValue ) ; if ( ! $ check && $ rule [ 'key' ] == 'class' ) { $ nodeClasses = explode ( ' ' , $ node -> getAttribute ( 'class' ) ) ; foreach ( $ nodeClasses as $ class ) { if ( ! empty ( $ class ) ) { $ check = $ this -> match ( $ rule [ 'operator' ] , $ rule [ 'value' ] , $ class ) ; } if ( $ check ) { break ; } } } return $ check ; }
|
Checks comparison condition from rules against node .
|
9,292
|
public function setOptions ( array $ options ) : Options { foreach ( $ options as $ key => $ option ) { $ this -> options [ $ key ] = $ option ; } return $ this ; }
|
Sets a new options param to override the current option array .
|
9,293
|
public function offsetGet ( $ offset ) { return isset ( $ this -> collection [ $ offset ] ) ? $ this -> collection [ $ offset ] : null ; }
|
Gets a node at the given offset or null
|
9,294
|
public function each ( callable $ callback ) { foreach ( $ this -> collection as $ key => $ value ) { $ callback ( $ value , $ key ) ; } }
|
Similar to jQuery each method . Calls the callback with each Node in this collection .
|
9,295
|
public function parseSelectorString ( string $ selector ) : array { $ selectors = [ ] ; $ matches = [ ] ; preg_match_all ( $ this -> pattern , trim ( $ selector ) . ' ' , $ matches , PREG_SET_ORDER ) ; $ result = [ ] ; foreach ( $ matches as $ match ) { $ tag = strtolower ( trim ( $ match [ 1 ] ) ) ; $ operator = '=' ; $ key = null ; $ value = null ; $ noKey = false ; $ alterNext = false ; if ( $ tag == '>' ) { $ alterNext = true ; } if ( ! empty ( $ match [ 2 ] ) ) { $ key = 'id' ; $ value = $ match [ 2 ] ; } if ( ! empty ( $ match [ 3 ] ) ) { $ key = 'class' ; $ value = $ match [ 3 ] ; } if ( ! empty ( $ match [ 4 ] ) ) { $ key = strtolower ( $ match [ 4 ] ) ; } if ( ! empty ( $ match [ 5 ] ) ) { $ operator = $ match [ 5 ] ; } if ( ! empty ( $ match [ 6 ] ) ) { $ value = $ match [ 6 ] ; } if ( isset ( $ key [ 0 ] ) && $ key [ 0 ] == '!' ) { $ key = substr ( $ key , 1 ) ; $ noKey = true ; } $ result [ ] = [ 'tag' => $ tag , 'key' => $ key , 'value' => $ value , 'operator' => $ operator , 'noKey' => $ noKey , 'alterNext' => $ alterNext , ] ; if ( trim ( $ match [ 7 ] ) == ',' ) { $ selectors [ ] = $ result ; $ result = [ ] ; } } if ( count ( $ result ) > 0 ) { $ selectors [ ] = $ result ; } return $ selectors ; }
|
Parses the selector string
|
9,296
|
public function propagateEncoding ( Encode $ encode ) { $ this -> encode = $ encode ; $ this -> tag -> setEncoding ( $ encode ) ; }
|
Sets the encoding class to this node .
|
9,297
|
public function isAncestor ( int $ id ) : Bool { if ( ! is_null ( $ this -> getAncestor ( $ id ) ) ) { return true ; } return false ; }
|
Checks if the given node id is an ancestor of the current node .
|
9,298
|
public function hasNextSibling ( ) : bool { try { $ this -> nextSibling ( ) ; return true ; } catch ( ParentNotFoundException $ e ) { return false ; } catch ( ChildNotFoundException $ e ) { return false ; } }
|
Checks if the current node has a next sibling .
|
9,299
|
public function setAttribute ( string $ key , $ value ) : AbstractNode { $ this -> tag -> setAttribute ( $ key , $ value ) ; $ this -> clear ( ) ; return $ this ; }
|
A wrapper method that simply calls the setAttribute method on the tag of this node .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.