idx
int64
0
241k
question
stringlengths
64
6.21k
target
stringlengths
5
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' ] ) && $ confi...
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...
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' ] , ...
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 -> ge...
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...
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_s...
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_{$co...
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 !=...
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-f...
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 ( 'customiz...
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 ( ! cla...
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 ::...
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 (...
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 [ 'backgro...
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]#' , ...
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' ...
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 ...
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 ] ) ) { $ con...
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' ] ) && 'optio...
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 [ 'act...
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 ( $ ...
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_exi...
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'...
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...
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 ) ; f...
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 ] , $ val...
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...
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 )...
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 ( ...
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 ( ( '>=' === $ oper...
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_classnam...
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...
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 20...
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 -> ch...
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_v...
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 :: $ fi...
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 :...
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_sty...
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' ] ) )...
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' =>...
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...
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...
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 ( $ t...
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 -> setting...
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 ( $ ar...
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' === $ t...
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 . $ found...
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 ( ...
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...
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 fals...
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 -> setAttribut...
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 [ $ a...
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 . '="' . $ ...
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 ; ...
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 -...
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 -> a...
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 (...
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 = '=' ;...
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 .