repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
aristath/kirki | packages/kirki-framework/module-css/src/Module.php | Module.loop_controls | public static function loop_controls( $config_id ) {
// Get an instance of the Generator class.
// This will make sure google fonts and backup fonts are loaded.
Generator::get_instance();
$fields = array_merge( Kirki::$fields, self::get_fields_by_config( $config_id ) );
$css = [];
// Early exit if no fields are found.
if ( empty( $fields ) ) {
return;
}
foreach ( $fields as $field ) {
// Only process fields that belong to $config_id.
if ( isset( $field['kirki_config'] ) && $config_id !== $field['kirki_config'] ) {
continue;
}
if ( true === apply_filters( "kirki_{$config_id}_css_skip_hidden", true ) ) {
// Only continue if field dependencies are met.
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;
}
}
}
// Only continue if $field['output'] is set.
if ( isset( $field['output'] ) && ! empty( $field['output'] ) ) {
$css = Helper::array_replace_recursive( $css, Generator::css( $field ) );
// Add the globals.
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 ) );
}
} | php | public static function loop_controls( $config_id ) {
// Get an instance of the Generator class.
// This will make sure google fonts and backup fonts are loaded.
Generator::get_instance();
$fields = array_merge( Kirki::$fields, self::get_fields_by_config( $config_id ) );
$css = [];
// Early exit if no fields are found.
if ( empty( $fields ) ) {
return;
}
foreach ( $fields as $field ) {
// Only process fields that belong to $config_id.
if ( isset( $field['kirki_config'] ) && $config_id !== $field['kirki_config'] ) {
continue;
}
if ( true === apply_filters( "kirki_{$config_id}_css_skip_hidden", true ) ) {
// Only continue if field dependencies are met.
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;
}
}
}
// Only continue if $field['output'] is set.
if ( isset( $field['output'] ) && ! empty( $field['output'] ) ) {
$css = Helper::array_replace_recursive( $css, Generator::css( $field ) );
// Add the globals.
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 ) );
}
} | [
"public",
"static",
"function",
"loop_controls",
"(",
"$",
"config_id",
")",
"{",
"// Get an instance of the Generator class.",
"// This will make sure google fonts and backup fonts are loaded.",
"Generator",
"::",
"get_instance",
"(",
")",
";",
"$",
"fields",
"=",
"array_merge",
"(",
"Kirki",
"::",
"$",
"fields",
",",
"self",
"::",
"get_fields_by_config",
"(",
"$",
"config_id",
")",
")",
";",
"$",
"css",
"=",
"[",
"]",
";",
"// Early exit if no fields are found.",
"if",
"(",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"// Only process fields that belong to $config_id.",
"if",
"(",
"isset",
"(",
"$",
"field",
"[",
"'kirki_config'",
"]",
")",
"&&",
"$",
"config_id",
"!==",
"$",
"field",
"[",
"'kirki_config'",
"]",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"true",
"===",
"apply_filters",
"(",
"\"kirki_{$config_id}_css_skip_hidden\"",
",",
"true",
")",
")",
"{",
"// Only continue if field dependencies are met.",
"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",
";",
"}",
"}",
"}",
"// Only continue if $field['output'] is set.",
"if",
"(",
"isset",
"(",
"$",
"field",
"[",
"'output'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"field",
"[",
"'output'",
"]",
")",
")",
"{",
"$",
"css",
"=",
"Helper",
"::",
"array_replace_recursive",
"(",
"$",
"css",
",",
"Generator",
"::",
"css",
"(",
"$",
"field",
")",
")",
";",
"// Add the globals.",
"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.
@static
@access public
@param string $config_id The configuration ID. | [
"Loop",
"through",
"all",
"fields",
"and",
"create",
"an",
"array",
"of",
"style",
"definitions",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-css/src/Module.php#L285-L343 | train |
aristath/kirki | packages/kirki-framework/field/src/Field.php | Field.filter_setting_args | 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;
} | php | 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;
} | [
"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.
@access public
@since 0.1
@param array $args The field arguments.
@param WP_Customize_Manager $wp_customize The customizer instance.
@return array | [
"Filter",
"setting",
"args",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/field/src/Field.php#L123-L134 | train |
aristath/kirki | packages/kirki-framework/field/src/Field.php | Field.add_setting | public function add_setting( $wp_customize ) {
/**
* Allow filtering the arguments.
*
* @since 0.1
* @param array $this->args The arguments.
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return array Return the arguments.
*/
$args = apply_filters( 'kirki_field_add_setting_args', $this->args, $wp_customize );
if ( isset( $args['settings'] ) ) {
$wp_customize->add_setting( $args['settings'], $args );
}
} | php | public function add_setting( $wp_customize ) {
/**
* Allow filtering the arguments.
*
* @since 0.1
* @param array $this->args The arguments.
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return array Return the arguments.
*/
$args = apply_filters( 'kirki_field_add_setting_args', $this->args, $wp_customize );
if ( isset( $args['settings'] ) ) {
$wp_customize->add_setting( $args['settings'], $args );
}
} | [
"public",
"function",
"add_setting",
"(",
"$",
"wp_customize",
")",
"{",
"/**\n\t\t * Allow filtering the arguments.\n\t\t *\n\t\t * @since 0.1\n\t\t * @param array $this->args The arguments.\n\t\t * @param WP_Customize_Manager $wp_customize The customizer instance.\n\t\t * @return array Return the arguments.\n\t\t */",
"$",
"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.
@access public
@since 0.1
@param WP_Customize_Manager $wp_customize The customizer instance.
@return void | [
"Registers",
"the",
"setting",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/field/src/Field.php#L157-L171 | train |
aristath/kirki | packages/kirki-framework/field/src/Field.php | Field.add_control | public function add_control( $wp_customize ) {
$control_class = $this->control_class;
// If no class-name is defined, early exit.
if ( ! $control_class ) {
return;
}
/**
* Allow filtering the arguments.
*
* @since 0.1
* @param array $this->args The arguments.
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return array Return the arguments.
*/
$args = apply_filters( 'kirki_field_add_control_args', $this->args, $wp_customize );
$wp_customize->add_control( new $control_class( $wp_customize, $args['settings'], $args ) );
} | php | public function add_control( $wp_customize ) {
$control_class = $this->control_class;
// If no class-name is defined, early exit.
if ( ! $control_class ) {
return;
}
/**
* Allow filtering the arguments.
*
* @since 0.1
* @param array $this->args The arguments.
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return array Return the arguments.
*/
$args = apply_filters( 'kirki_field_add_control_args', $this->args, $wp_customize );
$wp_customize->add_control( new $control_class( $wp_customize, $args['settings'], $args ) );
} | [
"public",
"function",
"add_control",
"(",
"$",
"wp_customize",
")",
"{",
"$",
"control_class",
"=",
"$",
"this",
"->",
"control_class",
";",
"// If no class-name is defined, early exit.",
"if",
"(",
"!",
"$",
"control_class",
")",
"{",
"return",
";",
"}",
"/**\n\t\t * Allow filtering the arguments.\n\t\t *\n\t\t * @since 0.1\n\t\t * @param array $this->args The arguments.\n\t\t * @param WP_Customize_Manager $wp_customize The customizer instance.\n\t\t * @return array Return the arguments.\n\t\t */",
"$",
"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.
@access public
@since 0.1
@param WP_Customize_Manager $wp_customize The customizer instance.
@return void | [
"Registers",
"the",
"control",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/field/src/Field.php#L181-L200 | train |
aristath/kirki | packages/kirki-framework/googlefonts/src/GoogleFonts.php | GoogleFonts.get_google_fonts_by_args | 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;
} | php | 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;
} | [
"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.
@access public
@since 0.1
@param array $args The arguments.
@return array | [
"Returns",
"an",
"array",
"of",
"google",
"-",
"fonts",
"matching",
"our",
"arguments",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/googlefonts/src/GoogleFonts.php#L116-L134 | train |
aristath/kirki | packages/kirki-framework/module-webfonts/src/Helper.php | Helper.get_remote_url_contents | 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;
} | php | 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;
} | [
"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.
@static
@access public
@since 3.0.36
@param string $url The URL we want to get.
@param array $args An array of arguments for the wp_remote_retrieve_body() function.
@return string The contents of the remote URL. | [
"Gets",
"the",
"remote",
"URL",
"contents",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-webfonts/src/Helper.php#L37-L47 | train |
aristath/kirki | packages/kirki-framework/module-webfonts/src/Helper.php | Helper.get_root_path | public static function get_root_path() {
// Get the upload directory for this site.
$upload_dir = wp_upload_dir();
$path = untrailingslashit( wp_normalize_path( $upload_dir['basedir'] ) ) . '/webfonts';
// If the folder doesn't exist, create it.
if ( ! file_exists( $path ) ) {
wp_mkdir_p( $path );
}
// Return the path.
return apply_filters( 'kirki_googlefonts_root_path', $path );
} | php | public static function get_root_path() {
// Get the upload directory for this site.
$upload_dir = wp_upload_dir();
$path = untrailingslashit( wp_normalize_path( $upload_dir['basedir'] ) ) . '/webfonts';
// If the folder doesn't exist, create it.
if ( ! file_exists( $path ) ) {
wp_mkdir_p( $path );
}
// Return the path.
return apply_filters( 'kirki_googlefonts_root_path', $path );
} | [
"public",
"static",
"function",
"get_root_path",
"(",
")",
"{",
"// Get the upload directory for this site.",
"$",
"upload_dir",
"=",
"wp_upload_dir",
"(",
")",
";",
"$",
"path",
"=",
"untrailingslashit",
"(",
"wp_normalize_path",
"(",
"$",
"upload_dir",
"[",
"'basedir'",
"]",
")",
")",
".",
"'/webfonts'",
";",
"// If the folder doesn't exist, create it.",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"wp_mkdir_p",
"(",
"$",
"path",
")",
";",
"}",
"// Return the path.",
"return",
"apply_filters",
"(",
"'kirki_googlefonts_root_path'",
",",
"$",
"path",
")",
";",
"}"
] | Gets the root fonts folder path.
Other paths are built based on this.
@static
@since 3.0.36
@access public
@return string | [
"Gets",
"the",
"root",
"fonts",
"folder",
"path",
".",
"Other",
"paths",
"are",
"built",
"based",
"on",
"this",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-webfonts/src/Helper.php#L58-L71 | train |
aristath/kirki | packages/kirki-framework/module-webfonts/src/Helper.php | Helper.get_filename_from_url | 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;
} | php | 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;
} | [
"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.
@static
@access private
@since 3.0.28
@param string $url The URL.
@return string The filename. | [
"Gets",
"the",
"filename",
"by",
"breaking",
"-",
"down",
"the",
"URL",
"parts",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-webfonts/src/Helper.php#L82-L89 | train |
aristath/kirki | packages/kirki-framework/module-webfonts/src/Helper.php | Helper.download_font_file | public static function download_font_file( $url ) {
// Gives us access to the download_url() and wp_handle_sideload() functions.
require_once ABSPATH . 'wp-admin/includes/file.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude
$timeout_seconds = 5;
// Download file to temp dir.
$temp_file = download_url( $url, $timeout_seconds );
if ( is_wp_error( $temp_file ) ) {
return false;
}
// Array based on $_FILE as seen in PHP file uploads.
$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,
];
// Move the temporary file into the uploads directory.
$results = wp_handle_sideload( $file, $overrides );
if ( empty( $results['error'] ) ) {
return $results['url'];
}
return false;
} | php | public static function download_font_file( $url ) {
// Gives us access to the download_url() and wp_handle_sideload() functions.
require_once ABSPATH . 'wp-admin/includes/file.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude
$timeout_seconds = 5;
// Download file to temp dir.
$temp_file = download_url( $url, $timeout_seconds );
if ( is_wp_error( $temp_file ) ) {
return false;
}
// Array based on $_FILE as seen in PHP file uploads.
$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,
];
// Move the temporary file into the uploads directory.
$results = wp_handle_sideload( $file, $overrides );
if ( empty( $results['error'] ) ) {
return $results['url'];
}
return false;
} | [
"public",
"static",
"function",
"download_font_file",
"(",
"$",
"url",
")",
"{",
"// Gives us access to the download_url() and wp_handle_sideload() functions.",
"require_once",
"ABSPATH",
".",
"'wp-admin/includes/file.php'",
";",
"// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude",
"$",
"timeout_seconds",
"=",
"5",
";",
"// Download file to temp dir.",
"$",
"temp_file",
"=",
"download_url",
"(",
"$",
"url",
",",
"$",
"timeout_seconds",
")",
";",
"if",
"(",
"is_wp_error",
"(",
"$",
"temp_file",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Array based on $_FILE as seen in PHP file uploads.",
"$",
"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",
",",
"]",
";",
"// Move the temporary file into the uploads directory.",
"$",
"results",
"=",
"wp_handle_sideload",
"(",
"$",
"file",
",",
"$",
"overrides",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"results",
"[",
"'error'",
"]",
")",
")",
"{",
"return",
"$",
"results",
"[",
"'url'",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Downloads a font-file and saves it locally.
@access public
@since 3.0.28
@param string $url The URL of the file we want to get.
@return bool | [
"Downloads",
"a",
"font",
"-",
"file",
"and",
"saves",
"it",
"locally",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-webfonts/src/Helper.php#L99-L135 | train |
aristath/kirki | packages/kirki-framework/module-webfonts/src/Helper.php | Helper.get_root_url | public static function get_root_url() {
// Get the upload directory for this site.
$upload_dir = wp_upload_dir();
// The URL.
$url = trailingslashit( $upload_dir['baseurl'] );
// Take care of domain mapping.
// When using domain mapping we have to make sure that the URL to the file
// does not include the original domain but instead the mapped domain.
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' );
} | php | public static function get_root_url() {
// Get the upload directory for this site.
$upload_dir = wp_upload_dir();
// The URL.
$url = trailingslashit( $upload_dir['baseurl'] );
// Take care of domain mapping.
// When using domain mapping we have to make sure that the URL to the file
// does not include the original domain but instead the mapped domain.
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' );
} | [
"public",
"static",
"function",
"get_root_url",
"(",
")",
"{",
"// Get the upload directory for this site.",
"$",
"upload_dir",
"=",
"wp_upload_dir",
"(",
")",
";",
"// The URL.",
"$",
"url",
"=",
"trailingslashit",
"(",
"$",
"upload_dir",
"[",
"'baseurl'",
"]",
")",
";",
"// Take care of domain mapping.",
"// When using domain mapping we have to make sure that the URL to the file",
"// does not include the original domain but instead the mapped domain.",
"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.
@static
@since 3.0.36
@access public
@return string | [
"Gets",
"the",
"root",
"folder",
"url",
".",
"Other",
"urls",
"are",
"built",
"based",
"on",
"this",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-webfonts/src/Helper.php#L146-L166 | train |
aristath/kirki | packages/kirki-framework/module-editor-styles/src/Module.php | Module.init | public function init() {
$this->set_configs();
$this->set_enabled();
$this->set_modules_css();
$this->set_google_fonts();
$this->set_modules_webfonts();
$this->add_hooks();
} | php | public function init() {
$this->set_configs();
$this->set_enabled();
$this->set_modules_css();
$this->set_google_fonts();
$this->set_modules_webfonts();
$this->add_hooks();
} | [
"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.
Sets class properties and add necessary hooks.
@since 3.0.35 | [
"Initialize",
"Module",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-editor-styles/src/Module.php#L100-L107 | train |
aristath/kirki | packages/kirki-framework/module-editor-styles/src/Module.php | Module.enqueue | public function enqueue( $settings ) {
$styles = $this->get_styles();
if ( ! empty( $styles ) ) {
$settings['styles'][] = [ 'css' => $styles ];
}
return $settings;
} | php | public function enqueue( $settings ) {
$styles = $this->get_styles();
if ( ! empty( $styles ) ) {
$settings['styles'][] = [ 'css' => $styles ];
}
return $settings;
} | [
"public",
"function",
"enqueue",
"(",
"$",
"settings",
")",
"{",
"$",
"styles",
"=",
"$",
"this",
"->",
"get_styles",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"styles",
")",
")",
"{",
"$",
"settings",
"[",
"'styles'",
"]",
"[",
"]",
"=",
"[",
"'css'",
"=>",
"$",
"styles",
"]",
";",
"}",
"return",
"$",
"settings",
";",
"}"
] | Enqueue styles to Gutenberg Editor.
@access public
@param array $settings The settings for styles.
@since 3.0.35 | [
"Enqueue",
"styles",
"to",
"Gutenberg",
"Editor",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-editor-styles/src/Module.php#L161-L169 | train |
aristath/kirki | packages/kirki-framework/module-editor-styles/src/Module.php | Module.get_styles | 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 ); // phpcs:ignore PHPCompatibility.Syntax.NewDynamicAccessToStatic
$styles = apply_filters( "kirki_gutenberg_{$config_id}_dynamic_css", $styles );
if ( empty( $styles ) ) {
continue;
}
}
return $styles;
} | php | 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 ); // phpcs:ignore PHPCompatibility.Syntax.NewDynamicAccessToStatic
$styles = apply_filters( "kirki_gutenberg_{$config_id}_dynamic_css", $styles );
if ( empty( $styles ) ) {
continue;
}
}
return $styles;
} | [
"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",
")",
";",
"// phpcs:ignore PHPCompatibility.Syntax.NewDynamicAccessToStatic",
"$",
"styles",
"=",
"apply_filters",
"(",
"\"kirki_gutenberg_{$config_id}_dynamic_css\"",
",",
"$",
"styles",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"styles",
")",
")",
"{",
"continue",
";",
"}",
"}",
"return",
"$",
"styles",
";",
"}"
] | Gets the styles to add to Gutenberg Editor.
@access public
@since 3.0.35
@return string $styles String containing inline styles to add to Gutenberg. | [
"Gets",
"the",
"styles",
"to",
"add",
"to",
"Gutenberg",
"Editor",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-editor-styles/src/Module.php#L179-L199 | train |
aristath/kirki | packages/kirki-framework/module-editor-styles/src/Module.php | Module.is_disabled | 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;
} | php | 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;
} | [
"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.
Feature can be disabled by KIRKI_NO_OUTPUT constant,
gutenbeg_support argument, and disabled output argument.
@access public
@param array $args An array of arguments.
@since 3.0.35
@return bool $disabled Is gutenberg integration feature disabled? | [
"Helper",
"method",
"to",
"check",
"if",
"feature",
"is",
"disabled",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-editor-styles/src/Module.php#L213-L229 | train |
aristath/kirki | packages/kirki-framework/module-editor-styles/src/Module.php | Module.enqueue_fontawesome | 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 ) ) { // phpcs:ignore PHPCompatibility.Syntax.NewDynamicAccessToStatic
wp_enqueue_script( 'kirki-fontawesome-font', 'https://use.fontawesome.com/30858dc40a.js', [], '4.0.7', true );
}
return;
}
} | php | 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 ) ) { // phpcs:ignore PHPCompatibility.Syntax.NewDynamicAccessToStatic
wp_enqueue_script( 'kirki-fontawesome-font', 'https://use.fontawesome.com/30858dc40a.js', [], '4.0.7', true );
}
return;
}
} | [
"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",
")",
")",
"{",
"// phpcs:ignore PHPCompatibility.Syntax.NewDynamicAccessToStatic",
"wp_enqueue_script",
"(",
"'kirki-fontawesome-font'",
",",
"'https://use.fontawesome.com/30858dc40a.js'",
",",
"[",
"]",
",",
"'4.0.7'",
",",
"true",
")",
";",
"}",
"return",
";",
"}",
"}"
] | Enqueue fontawesome in Gutenberg Editor.
@access public
@since 3.0.35 | [
"Enqueue",
"fontawesome",
"in",
"Gutenberg",
"Editor",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-editor-styles/src/Module.php#L237-L250 | train |
aristath/kirki | packages/kirki-framework/core/src/Init.php | Init.add_to_customizer | 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 );
} | php | 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 );
} | [
"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. | [
"Helper",
"function",
"that",
"adds",
"the",
"fields",
"sections",
"and",
"panels",
"to",
"the",
"customizer",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Init.php#L93-L99 | train |
aristath/kirki | packages/kirki-framework/core/src/Init.php | Init.register_control_types | 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 );
}
}
} | php | 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 );
}
}
} | [
"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 | [
"Register",
"control",
"types"
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Init.php#L104-L135 | train |
aristath/kirki | packages/kirki-framework/core/src/Init.php | Init.add_panels | public function add_panels() {
if ( ! empty( Kirki::$panels ) ) {
foreach ( Kirki::$panels as $panel_args ) {
// Extra checks for nested panels.
if ( isset( $panel_args['panel'] ) ) {
if ( isset( Kirki::$panels[ $panel_args['panel'] ] ) ) {
// Set the type to nested.
$panel_args['type'] = 'kirki-nested';
}
}
new Panel( $panel_args );
}
}
} | php | public function add_panels() {
if ( ! empty( Kirki::$panels ) ) {
foreach ( Kirki::$panels as $panel_args ) {
// Extra checks for nested panels.
if ( isset( $panel_args['panel'] ) ) {
if ( isset( Kirki::$panels[ $panel_args['panel'] ] ) ) {
// Set the type to nested.
$panel_args['type'] = 'kirki-nested';
}
}
new Panel( $panel_args );
}
}
} | [
"public",
"function",
"add_panels",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"Kirki",
"::",
"$",
"panels",
")",
")",
"{",
"foreach",
"(",
"Kirki",
"::",
"$",
"panels",
"as",
"$",
"panel_args",
")",
"{",
"// Extra checks for nested panels.",
"if",
"(",
"isset",
"(",
"$",
"panel_args",
"[",
"'panel'",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"Kirki",
"::",
"$",
"panels",
"[",
"$",
"panel_args",
"[",
"'panel'",
"]",
"]",
")",
")",
"{",
"// Set the type to nested.",
"$",
"panel_args",
"[",
"'type'",
"]",
"=",
"'kirki-nested'",
";",
"}",
"}",
"new",
"Panel",
"(",
"$",
"panel_args",
")",
";",
"}",
"}",
"}"
] | Register our panels to the WordPress Customizer.
@access public | [
"Register",
"our",
"panels",
"to",
"the",
"WordPress",
"Customizer",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Init.php#L142-L156 | train |
aristath/kirki | packages/kirki-framework/core/src/Init.php | Init.add_sections | public function add_sections() {
if ( ! empty( Kirki::$sections ) ) {
foreach ( Kirki::$sections as $section_args ) {
// Extra checks for nested sections.
if ( isset( $section_args['section'] ) ) {
if ( isset( Kirki::$sections[ $section_args['section'] ] ) ) {
// Set the type to nested.
$section_args['type'] = 'kirki-nested';
// We need to check if the parent section is nested inside a panel.
$parent_section = Kirki::$sections[ $section_args['section'] ];
if ( isset( $parent_section['panel'] ) ) {
$section_args['panel'] = $parent_section['panel'];
}
}
}
new Section( $section_args );
}
}
} | php | public function add_sections() {
if ( ! empty( Kirki::$sections ) ) {
foreach ( Kirki::$sections as $section_args ) {
// Extra checks for nested sections.
if ( isset( $section_args['section'] ) ) {
if ( isset( Kirki::$sections[ $section_args['section'] ] ) ) {
// Set the type to nested.
$section_args['type'] = 'kirki-nested';
// We need to check if the parent section is nested inside a panel.
$parent_section = Kirki::$sections[ $section_args['section'] ];
if ( isset( $parent_section['panel'] ) ) {
$section_args['panel'] = $parent_section['panel'];
}
}
}
new Section( $section_args );
}
}
} | [
"public",
"function",
"add_sections",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"Kirki",
"::",
"$",
"sections",
")",
")",
"{",
"foreach",
"(",
"Kirki",
"::",
"$",
"sections",
"as",
"$",
"section_args",
")",
"{",
"// Extra checks for nested sections.",
"if",
"(",
"isset",
"(",
"$",
"section_args",
"[",
"'section'",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"Kirki",
"::",
"$",
"sections",
"[",
"$",
"section_args",
"[",
"'section'",
"]",
"]",
")",
")",
"{",
"// Set the type to nested.",
"$",
"section_args",
"[",
"'type'",
"]",
"=",
"'kirki-nested'",
";",
"// We need to check if the parent section is nested inside a panel.",
"$",
"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.
@var object The WordPress Customizer object | [
"Register",
"our",
"sections",
"to",
"the",
"WordPress",
"Customizer",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Init.php#L163-L181 | train |
aristath/kirki | packages/kirki-framework/core/src/Init.php | Init.fields_from_filters | 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 );
}
}
} | php | 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 );
}
}
} | [
"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.
@access private
@since 2.0.0 | [
"Process",
"fields",
"added",
"using",
"the",
"kirki_fields",
"and",
"kirki_controls",
"filter",
".",
"These",
"filters",
"are",
"no",
"longer",
"used",
"this",
"is",
"simply",
"for",
"backwards",
"-",
"compatibility",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Init.php#L214-L224 | train |
aristath/kirki | packages/kirki-framework/control-select/src/Field/Select.php | Select.sanitize | 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 );
} | php | 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 );
} | [
"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.
@access public
@since 1.0
@param array $value The value.
@return string|array | [
"Sanitizes",
"select",
"control",
"values",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/control-select/src/Field/Select.php#L86-L97 | train |
aristath/kirki | packages/kirki-framework/control-background/src/Field/Background.php | Background.sanitize | 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;
} | php | 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;
} | [
"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
@static
@access public
@since 1.0
@param array $value The value.
@return array | [
"Sanitizes",
"background",
"controls"
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/control-background/src/Field/Background.php#L249-L318 | train |
aristath/kirki | packages/kirki-framework/core/src/Sanitize_Values.php | Sanitize_Values.dropdown_pages | public static function dropdown_pages( $page_id, $setting ) {
// Ensure $input is an absolute integer.
$page_id = absint( $page_id );
// If $page_id is an ID of a published page, return it; otherwise, return the default.
return ( 'publish' === get_post_status( $page_id ) ? $page_id : $setting->default );
} | php | public static function dropdown_pages( $page_id, $setting ) {
// Ensure $input is an absolute integer.
$page_id = absint( $page_id );
// If $page_id is an ID of a published page, return it; otherwise, return the default.
return ( 'publish' === get_post_status( $page_id ) ? $page_id : $setting->default );
} | [
"public",
"static",
"function",
"dropdown_pages",
"(",
"$",
"page_id",
",",
"$",
"setting",
")",
"{",
"// Ensure $input is an absolute integer.",
"$",
"page_id",
"=",
"absint",
"(",
"$",
"page_id",
")",
";",
"// If $page_id is an ID of a published page, return it; otherwise, return the default.",
"return",
"(",
"'publish'",
"===",
"get_post_status",
"(",
"$",
"page_id",
")",
"?",
"$",
"page_id",
":",
"$",
"setting",
"->",
"default",
")",
";",
"}"
] | Drop-down Pages sanitization callback.
- Sanitization: dropdown-pages
- Control: dropdown-pages
Sanitization callback for 'dropdown-pages' type controls. This callback sanitizes `$page_id`
as an absolute integer, and then validates that $input is the ID of a published page.
@see absint() https://developer.wordpress.org/reference/functions/absint/
@see get_post_status() https://developer.wordpress.org/reference/functions/get_post_status/
@param int $page_id Page ID.
@param WP_Customize_Setting $setting Setting instance.
@return int|string Page ID if the page is published; otherwise, the setting default. | [
"Drop",
"-",
"down",
"Pages",
"sanitization",
"callback",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Sanitize_Values.php#L76-L83 | train |
aristath/kirki | packages/kirki-framework/core/src/Sanitize_Values.php | Sanitize_Values.css_dimension | public static function css_dimension( $value ) {
// Trim it.
$value = trim( $value );
// If the value is round, then return 50%.
if ( 'round' === $value ) {
$value = '50%';
}
// If the value is empty, return empty.
if ( '' === $value ) {
return '';
}
// If auto, inherit or initial, return the value.
if ( 'auto' === $value || 'initial' === $value || 'inherit' === $value || 'normal' === $value ) {
return $value;
}
// Return empty if there are no numbers in the value.
if ( ! preg_match( '#[0-9]#', $value ) ) {
return '';
}
// If we're using calc() then return the value.
if ( false !== strpos( $value, 'calc(' ) ) {
return $value;
}
// The raw value without the units.
$raw_value = self::filter_number( $value );
$unit_used = '';
// An array of all valid CSS units. Their order was carefully chosen for this evaluation, don't mix it up!!!
$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;
}
}
// Hack for rem values.
if ( 'em' === $unit_used && false !== strpos( $value, 'rem' ) ) {
$unit_used = 'rem';
}
return $raw_value . $unit_used;
} | php | public static function css_dimension( $value ) {
// Trim it.
$value = trim( $value );
// If the value is round, then return 50%.
if ( 'round' === $value ) {
$value = '50%';
}
// If the value is empty, return empty.
if ( '' === $value ) {
return '';
}
// If auto, inherit or initial, return the value.
if ( 'auto' === $value || 'initial' === $value || 'inherit' === $value || 'normal' === $value ) {
return $value;
}
// Return empty if there are no numbers in the value.
if ( ! preg_match( '#[0-9]#', $value ) ) {
return '';
}
// If we're using calc() then return the value.
if ( false !== strpos( $value, 'calc(' ) ) {
return $value;
}
// The raw value without the units.
$raw_value = self::filter_number( $value );
$unit_used = '';
// An array of all valid CSS units. Their order was carefully chosen for this evaluation, don't mix it up!!!
$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;
}
}
// Hack for rem values.
if ( 'em' === $unit_used && false !== strpos( $value, 'rem' ) ) {
$unit_used = 'rem';
}
return $raw_value . $unit_used;
} | [
"public",
"static",
"function",
"css_dimension",
"(",
"$",
"value",
")",
"{",
"// Trim it.",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"// If the value is round, then return 50%.",
"if",
"(",
"'round'",
"===",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"'50%'",
";",
"}",
"// If the value is empty, return empty.",
"if",
"(",
"''",
"===",
"$",
"value",
")",
"{",
"return",
"''",
";",
"}",
"// If auto, inherit or initial, return the value.",
"if",
"(",
"'auto'",
"===",
"$",
"value",
"||",
"'initial'",
"===",
"$",
"value",
"||",
"'inherit'",
"===",
"$",
"value",
"||",
"'normal'",
"===",
"$",
"value",
")",
"{",
"return",
"$",
"value",
";",
"}",
"// Return empty if there are no numbers in the value.",
"if",
"(",
"!",
"preg_match",
"(",
"'#[0-9]#'",
",",
"$",
"value",
")",
")",
"{",
"return",
"''",
";",
"}",
"// If we're using calc() then return the value.",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"value",
",",
"'calc('",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"// The raw value without the units.",
"$",
"raw_value",
"=",
"self",
"::",
"filter_number",
"(",
"$",
"value",
")",
";",
"$",
"unit_used",
"=",
"''",
";",
"// An array of all valid CSS units. Their order was carefully chosen for this evaluation, don't mix it up!!!",
"$",
"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",
";",
"}",
"}",
"// Hack for rem values.",
"if",
"(",
"'em'",
"===",
"$",
"unit_used",
"&&",
"false",
"!==",
"strpos",
"(",
"$",
"value",
",",
"'rem'",
")",
")",
"{",
"$",
"unit_used",
"=",
"'rem'",
";",
"}",
"return",
"$",
"raw_value",
".",
"$",
"unit_used",
";",
"}"
] | Sanitizes css dimensions.
@static
@access public
@since 2.2.0
@param string $value The value to be sanitized.
@return string | [
"Sanitizes",
"css",
"dimensions",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Sanitize_Values.php#L94-L142 | train |
aristath/kirki | packages/kirki-framework/module-tooltips/src/Module.php | Module.add_tooltip | public function add_tooltip( $field_id, $tooltip ) {
$this->tooltips_content[ $field_id ] = [
'id' => sanitize_key( $field_id ),
'content' => wp_kses_post( $tooltip ),
];
} | php | public function add_tooltip( $field_id, $tooltip ) {
$this->tooltips_content[ $field_id ] = [
'id' => sanitize_key( $field_id ),
'content' => wp_kses_post( $tooltip ),
];
} | [
"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.
@access public
@since 4.2.0
@param string $field_id The field-ID.
@param string $tooltip The tooltip content. | [
"Allows",
"us",
"to",
"add",
"a",
"tooltip",
"to",
"any",
"control",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-tooltips/src/Module.php#L103-L108 | train |
aristath/kirki | packages/kirki-framework/module-selective-refresh/src/Module.php | Module.register_partials | public function register_partials( $wp_customize ) {
// Abort if selective refresh is not available.
if ( ! isset( $wp_customize->selective_refresh ) ) {
return;
}
// Get an array of all fields.
$fields = Kirki::$fields;
// Start parsing the fields.
foreach ( $fields as $field ) {
if ( isset( $field['partial_refresh'] ) && ! empty( $field['partial_refresh'] ) ) {
// Start going through each item in the array of partial refreshes.
foreach ( $field['partial_refresh'] as $partial_refresh => $partial_refresh_args ) {
// If we have all we need, create the selective refresh call.
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 );
}
}
}
}
} | php | public function register_partials( $wp_customize ) {
// Abort if selective refresh is not available.
if ( ! isset( $wp_customize->selective_refresh ) ) {
return;
}
// Get an array of all fields.
$fields = Kirki::$fields;
// Start parsing the fields.
foreach ( $fields as $field ) {
if ( isset( $field['partial_refresh'] ) && ! empty( $field['partial_refresh'] ) ) {
// Start going through each item in the array of partial refreshes.
foreach ( $field['partial_refresh'] as $partial_refresh => $partial_refresh_args ) {
// If we have all we need, create the selective refresh call.
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 );
}
}
}
}
} | [
"public",
"function",
"register_partials",
"(",
"$",
"wp_customize",
")",
"{",
"// Abort if selective refresh is not available.",
"if",
"(",
"!",
"isset",
"(",
"$",
"wp_customize",
"->",
"selective_refresh",
")",
")",
"{",
"return",
";",
"}",
"// Get an array of all fields.",
"$",
"fields",
"=",
"Kirki",
"::",
"$",
"fields",
";",
"// Start parsing the fields.",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"field",
"[",
"'partial_refresh'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"field",
"[",
"'partial_refresh'",
"]",
")",
")",
"{",
"// Start going through each item in the array of partial refreshes.",
"foreach",
"(",
"$",
"field",
"[",
"'partial_refresh'",
"]",
"as",
"$",
"partial_refresh",
"=>",
"$",
"partial_refresh_args",
")",
"{",
"// If we have all we need, create the selective refresh call.",
"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.
@param object $wp_customize WP_Customize_Manager. | [
"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",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-selective-refresh/src/Module.php#L64-L92 | train |
aristath/kirki | packages/kirki-framework/control-repeater/src/Settings/Repeater.php | Repeater.sanitize_repeater_setting | public function sanitize_repeater_setting( $value ) {
if ( ! is_array( $value ) ) {
$value = json_decode( urldecode( $value ) );
}
if ( empty( $value ) || ! is_array( $value ) ) {
$value = [];
}
// Make sure that every row is an array, not an object.
foreach ( $value as $key => $val ) {
$value[ $key ] = (array) $val;
if ( empty( $val ) ) {
unset( $value[ $key ] );
}
}
// Reindex array.
if ( is_array( $value ) ) {
$value = array_values( $value );
}
return $value;
} | php | public function sanitize_repeater_setting( $value ) {
if ( ! is_array( $value ) ) {
$value = json_decode( urldecode( $value ) );
}
if ( empty( $value ) || ! is_array( $value ) ) {
$value = [];
}
// Make sure that every row is an array, not an object.
foreach ( $value as $key => $val ) {
$value[ $key ] = (array) $val;
if ( empty( $val ) ) {
unset( $value[ $key ] );
}
}
// Reindex array.
if ( is_array( $value ) ) {
$value = array_values( $value );
}
return $value;
} | [
"public",
"function",
"sanitize_repeater_setting",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"json_decode",
"(",
"urldecode",
"(",
"$",
"value",
")",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
"||",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"[",
"]",
";",
"}",
"// Make sure that every row is an array, not an object.",
"foreach",
"(",
"$",
"value",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"value",
"[",
"$",
"key",
"]",
"=",
"(",
"array",
")",
"$",
"val",
";",
"if",
"(",
"empty",
"(",
"$",
"val",
")",
")",
"{",
"unset",
"(",
"$",
"value",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"// Reindex array.",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"array_values",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Convert the JSON encoded setting coming from Customizer to an Array.
@access public
@since 1.0
@param string $value URL Encoded JSON Value.
@return array | [
"Convert",
"the",
"JSON",
"encoded",
"setting",
"coming",
"from",
"Customizer",
"to",
"an",
"Array",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/control-repeater/src/Settings/Repeater.php#L55-L77 | train |
aristath/kirki | packages/kirki-framework/module-webfonts/src/Module.php | Module.init | 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 );
}
} | php | 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 );
}
} | [
"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.
@access protected
@since 3.0.0 | [
"Init",
"other",
"objects",
"depending",
"on",
"the",
"method",
"we",
"ll",
"be",
"using",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-webfonts/src/Module.php#L94-L101 | train |
aristath/kirki | packages/kirki-framework/core/src/Values.php | Values.get_value | public static function get_value( $config_id = '', $field_id = '' ) {
// Make sure value is defined.
$value = '';
// This allows us to skip the $config_id argument.
// If we skip adding a $config_id, use the 'global' configuration.
if ( ( '' === $field_id ) && '' !== $config_id ) {
$field_id = $config_id;
$config_id = 'global';
}
// If $config_id is empty, set it to 'global'.
$config_id = ( '' === $config_id ) ? 'global' : $config_id;
// Fallback to 'global' if $config_id is not found.
if ( ! isset( Kirki::$config[ $config_id ] ) ) {
$config_id = 'global';
}
if ( 'theme_mod' === Kirki::$config[ $config_id ]['option_type'] ) {
// We're using theme_mods so just get the value using get_theme_mod.
$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'] ) {
// We're using options.
if ( '' !== Kirki::$config[ $config_id ]['option_name'] ) {
// Options are serialized as a single option in the db.
// We'll have to get the option and then get the item from the array.
$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 );
}
// Each option separately saved in the db.
$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 );
} | php | public static function get_value( $config_id = '', $field_id = '' ) {
// Make sure value is defined.
$value = '';
// This allows us to skip the $config_id argument.
// If we skip adding a $config_id, use the 'global' configuration.
if ( ( '' === $field_id ) && '' !== $config_id ) {
$field_id = $config_id;
$config_id = 'global';
}
// If $config_id is empty, set it to 'global'.
$config_id = ( '' === $config_id ) ? 'global' : $config_id;
// Fallback to 'global' if $config_id is not found.
if ( ! isset( Kirki::$config[ $config_id ] ) ) {
$config_id = 'global';
}
if ( 'theme_mod' === Kirki::$config[ $config_id ]['option_type'] ) {
// We're using theme_mods so just get the value using get_theme_mod.
$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'] ) {
// We're using options.
if ( '' !== Kirki::$config[ $config_id ]['option_name'] ) {
// Options are serialized as a single option in the db.
// We'll have to get the option and then get the item from the array.
$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 );
}
// Each option separately saved in the db.
$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 );
} | [
"public",
"static",
"function",
"get_value",
"(",
"$",
"config_id",
"=",
"''",
",",
"$",
"field_id",
"=",
"''",
")",
"{",
"// Make sure value is defined.",
"$",
"value",
"=",
"''",
";",
"// This allows us to skip the $config_id argument.",
"// If we skip adding a $config_id, use the 'global' configuration.",
"if",
"(",
"(",
"''",
"===",
"$",
"field_id",
")",
"&&",
"''",
"!==",
"$",
"config_id",
")",
"{",
"$",
"field_id",
"=",
"$",
"config_id",
";",
"$",
"config_id",
"=",
"'global'",
";",
"}",
"// If $config_id is empty, set it to 'global'.",
"$",
"config_id",
"=",
"(",
"''",
"===",
"$",
"config_id",
")",
"?",
"'global'",
":",
"$",
"config_id",
";",
"// Fallback to 'global' if $config_id is not found.",
"if",
"(",
"!",
"isset",
"(",
"Kirki",
"::",
"$",
"config",
"[",
"$",
"config_id",
"]",
")",
")",
"{",
"$",
"config_id",
"=",
"'global'",
";",
"}",
"if",
"(",
"'theme_mod'",
"===",
"Kirki",
"::",
"$",
"config",
"[",
"$",
"config_id",
"]",
"[",
"'option_type'",
"]",
")",
"{",
"// We're using theme_mods so just get the value using get_theme_mod.",
"$",
"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'",
"]",
")",
"{",
"// We're using options.",
"if",
"(",
"''",
"!==",
"Kirki",
"::",
"$",
"config",
"[",
"$",
"config_id",
"]",
"[",
"'option_name'",
"]",
")",
"{",
"// Options are serialized as a single option in the db.",
"// We'll have to get the option and then get the item from the array.",
"$",
"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",
")",
";",
"}",
"// Each option separately saved in the db.",
"$",
"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.
@static
@access public
@param string $config_id The configuration ID. @see Kirki\Core\Config.
@param string $field_id The field ID.
@return string|array | [
"Get",
"the",
"value",
"of",
"a",
"field",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Values.php#L32-L89 | train |
aristath/kirki | packages/kirki-framework/core/src/Values.php | Values.get_sanitized_field_value | 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;
} | php | 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;
} | [
"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.
@static
@access public
@param array $field The field aruments.
@return string|array | [
"Gets",
"the",
"value",
"or",
"fallsback",
"to",
"default",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Values.php#L99-L115 | train |
aristath/kirki | packages/kirki-framework/module-field-dependencies/src/Module.php | Module.field_add_control_args | public function field_add_control_args( $args ) {
if ( isset( $args['active_callback'] ) ) {
if ( is_array( $args['active_callback'] ) ) {
if ( ! is_callable( $args['active_callback'] ) ) {
// Bugfix for https://github.com/aristath/kirki/issues/1961.
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;
}
// No need to proceed any further if we're using the default value.
if ( '__return_true' === $args['active_callback'] ) {
return;
}
// Make sure the function is callable, otherwise fallback to __return_true.
if ( ! is_callable( $args['active_callback'] ) ) {
$args['active_callback'] = '__return_true';
}
}
return $args;
} | php | public function field_add_control_args( $args ) {
if ( isset( $args['active_callback'] ) ) {
if ( is_array( $args['active_callback'] ) ) {
if ( ! is_callable( $args['active_callback'] ) ) {
// Bugfix for https://github.com/aristath/kirki/issues/1961.
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;
}
// No need to proceed any further if we're using the default value.
if ( '__return_true' === $args['active_callback'] ) {
return;
}
// Make sure the function is callable, otherwise fallback to __return_true.
if ( ! is_callable( $args['active_callback'] ) ) {
$args['active_callback'] = '__return_true';
}
}
return $args;
} | [
"public",
"function",
"field_add_control_args",
"(",
"$",
"args",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"args",
"[",
"'active_callback'",
"]",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"args",
"[",
"'active_callback'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"args",
"[",
"'active_callback'",
"]",
")",
")",
"{",
"// Bugfix for https://github.com/aristath/kirki/issues/1961.",
"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",
";",
"}",
"// No need to proceed any further if we're using the default value.",
"if",
"(",
"'__return_true'",
"===",
"$",
"args",
"[",
"'active_callback'",
"]",
")",
"{",
"return",
";",
"}",
"// Make sure the function is callable, otherwise fallback to __return_true.",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"args",
"[",
"'active_callback'",
"]",
")",
")",
"{",
"$",
"args",
"[",
"'active_callback'",
"]",
"=",
"'__return_true'",
";",
"}",
"}",
"return",
"$",
"args",
";",
"}"
] | Filter control arguments.
@access public
@since 1.0
@param array $args The field arguments.
@return array | [
"Filter",
"control",
"arguments",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-field-dependencies/src/Module.php#L73-L105 | train |
aristath/kirki | packages/kirki-framework/module-css-vars/src/Module.php | Module.postmessage | 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 );
} | php | 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 );
} | [
"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.
@access public
@since 3.0.28
@return void | [
"Enqueues",
"the",
"script",
"that",
"handles",
"postMessage",
"and",
"adds",
"variables",
"to",
"it",
"using",
"the",
"wp_localize_script",
"function",
".",
"The",
"rest",
"is",
"handled",
"via",
"JS",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-css-vars/src/Module.php#L176-L186 | train |
aristath/kirki | packages/kirki-framework/core/src/Settings.php | Settings.add_settings | final private function add_settings( $args = [] ) {
// Get the classname we'll be using to create our setting(s).
$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 settings are defined as an array, then we need to go through them
// and call add_setting for each one of them separately.
if ( isset( $args['settings'] ) && is_array( $args['settings'] ) ) {
// Make sure defaults have been defined.
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'] );
} | php | final private function add_settings( $args = [] ) {
// Get the classname we'll be using to create our setting(s).
$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 settings are defined as an array, then we need to go through them
// and call add_setting for each one of them separately.
if ( isset( $args['settings'] ) && is_array( $args['settings'] ) ) {
// Make sure defaults have been defined.
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'] );
} | [
"final",
"private",
"function",
"add_settings",
"(",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"// Get the classname we'll be using to create our setting(s).",
"$",
"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 settings are defined as an array, then we need to go through them",
"// and call add_setting for each one of them separately.",
"if",
"(",
"isset",
"(",
"$",
"args",
"[",
"'settings'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"args",
"[",
"'settings'",
"]",
")",
")",
"{",
"// Make sure defaults have been defined.",
"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
@access private
@param array $args The field definition as sanitized in Kirki\Core\Field. | [
"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"
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Settings.php#L69-L95 | train |
aristath/kirki | packages/kirki-framework/core/src/Settings.php | Settings.add_setting | 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,
]
)
);
} | php | 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,
]
)
);
} | [
"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.
@access private
@param string $classname The name of the class that will be used to create this setting.
We're getting this from $this->setting_types.
@param string $setting The setting-name.
If settings is an array, then this method is called per-setting.
@param string|array $default Default value for this setting.
@param string $type The data type we're using. Valid options: theme_mod|option.
@param string $capability @see https://codex.wordpress.org/Roles_and_Capabilities.
@param string $transport Use refresh|postMessage.
@param string|array $sanitize_callback A callable sanitization function or method. | [
"This",
"is",
"where",
"we",
"re",
"finally",
"adding",
"the",
"setting",
"to",
"the",
"Customizer",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Settings.php#L111-L127 | train |
aristath/kirki | packages/kirki-framework/module-section-icons/src/Module.php | Module.customize_controls_enqueue_scripts | public function customize_controls_enqueue_scripts() {
$sections = Kirki::$sections;
$panels = Kirki::$panels;
// Parse sections and find ones with icons.
foreach ( $sections as $section ) {
if ( isset( $section['icon'] ) ) {
$this->add_icon( $section['id'], $section['icon'], 'section' );
}
}
// Parse panels and find ones with icons.
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 );
} | php | public function customize_controls_enqueue_scripts() {
$sections = Kirki::$sections;
$panels = Kirki::$panels;
// Parse sections and find ones with icons.
foreach ( $sections as $section ) {
if ( isset( $section['icon'] ) ) {
$this->add_icon( $section['id'], $section['icon'], 'section' );
}
}
// Parse panels and find ones with icons.
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 );
} | [
"public",
"function",
"customize_controls_enqueue_scripts",
"(",
")",
"{",
"$",
"sections",
"=",
"Kirki",
"::",
"$",
"sections",
";",
"$",
"panels",
"=",
"Kirki",
"::",
"$",
"panels",
";",
"// Parse sections and find ones with icons.",
"foreach",
"(",
"$",
"sections",
"as",
"$",
"section",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"section",
"[",
"'icon'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"add_icon",
"(",
"$",
"section",
"[",
"'id'",
"]",
",",
"$",
"section",
"[",
"'icon'",
"]",
",",
"'section'",
")",
";",
"}",
"}",
"// Parse panels and find ones with icons.",
"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. | [
"Format",
"the",
"script",
"in",
"a",
"way",
"that",
"will",
"be",
"compatible",
"with",
"WordPress",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-section-icons/src/Module.php#L88-L108 | train |
aristath/kirki | packages/kirki-framework/core/src/Helper.php | Helper.array_replace_recursive | public static function array_replace_recursive( $array, $array1 ) {
if ( function_exists( 'array_replace_recursive' ) ) {
return array_replace_recursive( $array, $array1 );
}
/**
* Handle the arguments, merge one by one.
*
* In PHP 7 func_get_args() changed the way it behaves but this doesn't mean anything in this case
* sinc ethis method is only used when the array_replace_recursive() function doesn't exist
* and that was introduced in PHP v5.3.
*
* Once WordPress-Core raises its minimum requirements we''' be able to remove this fallback completely.
*/
$args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue
$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;
} | php | public static function array_replace_recursive( $array, $array1 ) {
if ( function_exists( 'array_replace_recursive' ) ) {
return array_replace_recursive( $array, $array1 );
}
/**
* Handle the arguments, merge one by one.
*
* In PHP 7 func_get_args() changed the way it behaves but this doesn't mean anything in this case
* sinc ethis method is only used when the array_replace_recursive() function doesn't exist
* and that was introduced in PHP v5.3.
*
* Once WordPress-Core raises its minimum requirements we''' be able to remove this fallback completely.
*/
$args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue
$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;
} | [
"public",
"static",
"function",
"array_replace_recursive",
"(",
"$",
"array",
",",
"$",
"array1",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'array_replace_recursive'",
")",
")",
"{",
"return",
"array_replace_recursive",
"(",
"$",
"array",
",",
"$",
"array1",
")",
";",
"}",
"/**\n\t\t * Handle the arguments, merge one by one.\n\t\t *\n\t\t * In PHP 7 func_get_args() changed the way it behaves but this doesn't mean anything in this case\n\t\t * sinc ethis method is only used when the array_replace_recursive() function doesn't exist\n\t\t * and that was introduced in PHP v5.3.\n\t\t *\n\t\t * Once WordPress-Core raises its minimum requirements we''' be able to remove this fallback completely.\n\t\t */",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"// phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue",
"$",
"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.
@static
@access public
@param array $array The first array.
@param array $array1 The second array.
@return mixed | [
"Recursive",
"replace",
"in",
"arrays",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Helper.php#L34-L60 | train |
aristath/kirki | packages/kirki-framework/core/src/Helper.php | Helper.recurse | public static function recurse( $array, $array1 ) {
foreach ( $array1 as $key => $value ) {
// Create new key in $array, if it is empty or not an array.
if ( ! isset( $array[ $key ] ) || ( isset( $array[ $key ] ) && ! is_array( $array[ $key ] ) ) ) {
$array[ $key ] = [];
}
// Overwrite the value in the base array.
if ( is_array( $value ) ) {
$value = self::recurse( $array[ $key ], $value );
}
$array[ $key ] = $value;
}
return $array;
} | php | public static function recurse( $array, $array1 ) {
foreach ( $array1 as $key => $value ) {
// Create new key in $array, if it is empty or not an array.
if ( ! isset( $array[ $key ] ) || ( isset( $array[ $key ] ) && ! is_array( $array[ $key ] ) ) ) {
$array[ $key ] = [];
}
// Overwrite the value in the base array.
if ( is_array( $value ) ) {
$value = self::recurse( $array[ $key ], $value );
}
$array[ $key ] = $value;
}
return $array;
} | [
"public",
"static",
"function",
"recurse",
"(",
"$",
"array",
",",
"$",
"array1",
")",
"{",
"foreach",
"(",
"$",
"array1",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// Create new key in $array, if it is empty or not an array.",
"if",
"(",
"!",
"isset",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
"||",
"(",
"isset",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
"&&",
"!",
"is_array",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
")",
")",
"{",
"$",
"array",
"[",
"$",
"key",
"]",
"=",
"[",
"]",
";",
"}",
"// Overwrite the value in the base array.",
"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.
@static
@access public
@param array $array The first array.
@param array $array1 The second array.
@return array | [
"Helper",
"method",
"to",
"be",
"used",
"from",
"the",
"array_replace_recursive",
"method",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Helper.php#L71-L86 | train |
aristath/kirki | packages/kirki-framework/core/src/Helper.php | Helper.init_filesystem | public static function init_filesystem() {
$credentials = [];
if ( ! defined( 'FS_METHOD' ) ) {
define( 'FS_METHOD', 'direct' );
}
$method = defined( 'FS_METHOD' ) ? FS_METHOD : false;
if ( 'ftpext' === $method ) {
// If defined, set it to that, Else, set to NULL.
$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;
// Set FTP port.
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'] );
}
// Set connection type.
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';
}
}
// The WordPress filesystem.
global $wp_filesystem;
if ( empty( $wp_filesystem ) ) {
require_once wp_normalize_path( ABSPATH . '/wp-admin/includes/file.php' ); // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude
WP_Filesystem( $credentials );
}
return $wp_filesystem;
} | php | public static function init_filesystem() {
$credentials = [];
if ( ! defined( 'FS_METHOD' ) ) {
define( 'FS_METHOD', 'direct' );
}
$method = defined( 'FS_METHOD' ) ? FS_METHOD : false;
if ( 'ftpext' === $method ) {
// If defined, set it to that, Else, set to NULL.
$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;
// Set FTP port.
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'] );
}
// Set connection type.
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';
}
}
// The WordPress filesystem.
global $wp_filesystem;
if ( empty( $wp_filesystem ) ) {
require_once wp_normalize_path( ABSPATH . '/wp-admin/includes/file.php' ); // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude
WP_Filesystem( $credentials );
}
return $wp_filesystem;
} | [
"public",
"static",
"function",
"init_filesystem",
"(",
")",
"{",
"$",
"credentials",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"defined",
"(",
"'FS_METHOD'",
")",
")",
"{",
"define",
"(",
"'FS_METHOD'",
",",
"'direct'",
")",
";",
"}",
"$",
"method",
"=",
"defined",
"(",
"'FS_METHOD'",
")",
"?",
"FS_METHOD",
":",
"false",
";",
"if",
"(",
"'ftpext'",
"===",
"$",
"method",
")",
"{",
"// If defined, set it to that, Else, set to NULL.",
"$",
"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",
";",
"// Set FTP port.",
"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'",
"]",
")",
";",
"}",
"// Set connection type.",
"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'",
";",
"}",
"}",
"// The WordPress filesystem.",
"global",
"$",
"wp_filesystem",
";",
"if",
"(",
"empty",
"(",
"$",
"wp_filesystem",
")",
")",
"{",
"require_once",
"wp_normalize_path",
"(",
"ABSPATH",
".",
"'/wp-admin/includes/file.php'",
")",
";",
"// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude",
"WP_Filesystem",
"(",
"$",
"credentials",
")",
";",
"}",
"return",
"$",
"wp_filesystem",
";",
"}"
] | Initialize the WP_Filesystem
@static
@access public
@return object WP_Filesystem | [
"Initialize",
"the",
"WP_Filesystem"
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Helper.php#L95-L139 | train |
aristath/kirki | packages/kirki-framework/core/src/Helper.php | Helper.get_image_id | 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 ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
wp_cache_add( 'kirki_image_id_' . md5( $url ), $attachment, null );
}
if ( ! empty( $attachment ) ) {
return $attachment[0];
}
return 0;
} | php | 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 ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
wp_cache_add( 'kirki_image_id_' . md5( $url ), $attachment, null );
}
if ( ! empty( $attachment ) ) {
return $attachment[0];
}
return 0;
} | [
"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",
")",
")",
";",
"// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery",
"wp_cache_add",
"(",
"'kirki_image_id_'",
".",
"md5",
"(",
"$",
"url",
")",
",",
"$",
"attachment",
",",
"null",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"attachment",
")",
")",
"{",
"return",
"$",
"attachment",
"[",
"0",
"]",
";",
"}",
"return",
"0",
";",
"}"
] | Returns the attachment object
@static
@access public
@see https://pippinsplugins.com/retrieve-attachment-id-from-image-url/
@param string $url URL to the image.
@return int|string Numeric ID of the attachement. | [
"Returns",
"the",
"attachment",
"object"
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Helper.php#L150-L166 | train |
aristath/kirki | packages/kirki-framework/core/src/Helper.php | Helper.get_image_from_url | 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],
];
} | php | 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],
];
} | [
"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.
@param string $url URL to the image.
@return array | [
"Returns",
"an",
"array",
"of",
"the",
"attachment",
"s",
"properties",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Helper.php#L174-L184 | train |
aristath/kirki | packages/kirki-framework/core/src/Helper.php | Helper.get_posts | 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;
}
// Get the posts.
// TODO: WordPress.VIP.RestrictedFunctions.get_posts_get_posts.
$posts = get_posts( $args );
// Properly format the array.
$items = [];
foreach ( $posts as $post ) {
$items[ $post->ID ] = $post->post_title;
}
wp_reset_postdata();
return $items;
} | php | 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;
}
// Get the posts.
// TODO: WordPress.VIP.RestrictedFunctions.get_posts_get_posts.
$posts = get_posts( $args );
// Properly format the array.
$items = [];
foreach ( $posts as $post ) {
$items[ $post->ID ] = $post->post_title;
}
wp_reset_postdata();
return $items;
} | [
"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",
";",
"}",
"// Get the posts.",
"// TODO: WordPress.VIP.RestrictedFunctions.get_posts_get_posts.",
"$",
"posts",
"=",
"get_posts",
"(",
"$",
"args",
")",
";",
"// Properly format the array.",
"$",
"items",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"posts",
"as",
"$",
"post",
")",
"{",
"$",
"items",
"[",
"$",
"post",
"->",
"ID",
"]",
"=",
"$",
"post",
"->",
"post_title",
";",
"}",
"wp_reset_postdata",
"(",
")",
";",
"return",
"$",
"items",
";",
"}"
] | Get an array of posts.
@static
@access public
@param array $args Define arguments for the get_posts function.
@return array | [
"Get",
"an",
"array",
"of",
"posts",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Helper.php#L194-L217 | train |
aristath/kirki | packages/kirki-framework/core/src/Helper.php | Helper.get_taxonomies | public static function get_taxonomies() {
$items = [];
// Get the taxonomies.
$taxonomies = get_taxonomies(
[
'public' => true,
]
);
// Build the array.
foreach ( $taxonomies as $taxonomy ) {
$id = $taxonomy;
$taxonomy = get_taxonomy( $taxonomy );
$items[ $id ] = $taxonomy->labels->name;
}
return $items;
} | php | public static function get_taxonomies() {
$items = [];
// Get the taxonomies.
$taxonomies = get_taxonomies(
[
'public' => true,
]
);
// Build the array.
foreach ( $taxonomies as $taxonomy ) {
$id = $taxonomy;
$taxonomy = get_taxonomy( $taxonomy );
$items[ $id ] = $taxonomy->labels->name;
}
return $items;
} | [
"public",
"static",
"function",
"get_taxonomies",
"(",
")",
"{",
"$",
"items",
"=",
"[",
"]",
";",
"// Get the taxonomies.",
"$",
"taxonomies",
"=",
"get_taxonomies",
"(",
"[",
"'public'",
"=>",
"true",
",",
"]",
")",
";",
"// Build the array.",
"foreach",
"(",
"$",
"taxonomies",
"as",
"$",
"taxonomy",
")",
"{",
"$",
"id",
"=",
"$",
"taxonomy",
";",
"$",
"taxonomy",
"=",
"get_taxonomy",
"(",
"$",
"taxonomy",
")",
";",
"$",
"items",
"[",
"$",
"id",
"]",
"=",
"$",
"taxonomy",
"->",
"labels",
"->",
"name",
";",
"}",
"return",
"$",
"items",
";",
"}"
] | Get an array of publicly-querable taxonomies.
@static
@access public
@return array | [
"Get",
"an",
"array",
"of",
"publicly",
"-",
"querable",
"taxonomies",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Helper.php#L226-L244 | train |
aristath/kirki | packages/kirki-framework/core/src/Helper.php | Helper.get_post_types | public static function get_post_types() {
$items = [];
// Get the post types.
$post_types = get_post_types(
[
'public' => true,
],
'objects'
);
// Build the array.
foreach ( $post_types as $post_type ) {
$items[ $post_type->name ] = $post_type->labels->name;
}
return $items;
} | php | public static function get_post_types() {
$items = [];
// Get the post types.
$post_types = get_post_types(
[
'public' => true,
],
'objects'
);
// Build the array.
foreach ( $post_types as $post_type ) {
$items[ $post_type->name ] = $post_type->labels->name;
}
return $items;
} | [
"public",
"static",
"function",
"get_post_types",
"(",
")",
"{",
"$",
"items",
"=",
"[",
"]",
";",
"// Get the post types.",
"$",
"post_types",
"=",
"get_post_types",
"(",
"[",
"'public'",
"=>",
"true",
",",
"]",
",",
"'objects'",
")",
";",
"// Build the array.",
"foreach",
"(",
"$",
"post_types",
"as",
"$",
"post_type",
")",
"{",
"$",
"items",
"[",
"$",
"post_type",
"->",
"name",
"]",
"=",
"$",
"post_type",
"->",
"labels",
"->",
"name",
";",
"}",
"return",
"$",
"items",
";",
"}"
] | Get an array of publicly-querable post-types.
@static
@access public
@return array | [
"Get",
"an",
"array",
"of",
"publicly",
"-",
"querable",
"post",
"-",
"types",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Helper.php#L253-L270 | train |
aristath/kirki | packages/kirki-framework/core/src/Helper.php | Helper.get_terms | public static function get_terms( $taxonomies ) {
$items = [];
// Get the post types.
$terms = get_terms( $taxonomies );
// Build the array.
foreach ( $terms as $term ) {
$items[ $term->term_id ] = $term->name;
}
return $items;
} | php | public static function get_terms( $taxonomies ) {
$items = [];
// Get the post types.
$terms = get_terms( $taxonomies );
// Build the array.
foreach ( $terms as $term ) {
$items[ $term->term_id ] = $term->name;
}
return $items;
} | [
"public",
"static",
"function",
"get_terms",
"(",
"$",
"taxonomies",
")",
"{",
"$",
"items",
"=",
"[",
"]",
";",
"// Get the post types.",
"$",
"terms",
"=",
"get_terms",
"(",
"$",
"taxonomies",
")",
";",
"// Build the array.",
"foreach",
"(",
"$",
"terms",
"as",
"$",
"term",
")",
"{",
"$",
"items",
"[",
"$",
"term",
"->",
"term_id",
"]",
"=",
"$",
"term",
"->",
"name",
";",
"}",
"return",
"$",
"items",
";",
"}"
] | Get an array of terms from a taxonomy
@static
@access public
@param string|array $taxonomies See https://developer.wordpress.org/reference/functions/get_terms/ for details.
@return array | [
"Get",
"an",
"array",
"of",
"terms",
"from",
"a",
"taxonomy"
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Helper.php#L280-L292 | train |
aristath/kirki | packages/kirki-framework/core/src/Helper.php | Helper.compare_values | 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; // phpcs:ignore WordPress.PHP.StrictComparisons
}
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 ) ) { // phpcs:ignore WordPress.PHP.StrictInArray
return true;
}
}
return false;
}
if ( is_array( $value1 ) && ! is_array( $value2 ) ) {
return in_array( $value2, $value1 ); // phpcs:ignore WordPress.PHP.StrictInArray
}
if ( is_array( $value2 ) && ! is_array( $value1 ) ) {
return in_array( $value1, $value2 ); // phpcs:ignore WordPress.PHP.StrictInArray
}
return ( false !== strrpos( $value1, $value2 ) || false !== strpos( $value2, $value1 ) );
}
return $value1 == $value2; // phpcs:ignore WordPress.PHP.StrictComparisons
} | php | 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; // phpcs:ignore WordPress.PHP.StrictComparisons
}
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 ) ) { // phpcs:ignore WordPress.PHP.StrictInArray
return true;
}
}
return false;
}
if ( is_array( $value1 ) && ! is_array( $value2 ) ) {
return in_array( $value2, $value1 ); // phpcs:ignore WordPress.PHP.StrictInArray
}
if ( is_array( $value2 ) && ! is_array( $value1 ) ) {
return in_array( $value1, $value2 ); // phpcs:ignore WordPress.PHP.StrictInArray
}
return ( false !== strrpos( $value1, $value2 ) || false !== strpos( $value2, $value1 ) );
}
return $value1 == $value2; // phpcs:ignore WordPress.PHP.StrictComparisons
} | [
"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",
";",
"// phpcs:ignore WordPress.PHP.StrictComparisons",
"}",
"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",
")",
")",
"{",
"// phpcs:ignore WordPress.PHP.StrictInArray",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value1",
")",
"&&",
"!",
"is_array",
"(",
"$",
"value2",
")",
")",
"{",
"return",
"in_array",
"(",
"$",
"value2",
",",
"$",
"value1",
")",
";",
"// phpcs:ignore WordPress.PHP.StrictInArray",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value2",
")",
"&&",
"!",
"is_array",
"(",
"$",
"value1",
")",
")",
"{",
"return",
"in_array",
"(",
"$",
"value1",
",",
"$",
"value2",
")",
";",
"// phpcs:ignore WordPress.PHP.StrictInArray",
"}",
"return",
"(",
"false",
"!==",
"strrpos",
"(",
"$",
"value1",
",",
"$",
"value2",
")",
"||",
"false",
"!==",
"strpos",
"(",
"$",
"value2",
",",
"$",
"value1",
")",
")",
";",
"}",
"return",
"$",
"value1",
"==",
"$",
"value2",
";",
"// phpcs:ignore WordPress.PHP.StrictComparisons",
"}"
] | Compares the 2 values given the condition
@param mixed $value1 The 1st value in the comparison.
@param mixed $value2 The 2nd value in the comparison.
@param string $operator The operator we'll use for the comparison.
@return boolean whether The comparison has succeded (true) or failed (false). | [
"Compares",
"the",
"2",
"values",
"given",
"the",
"condition"
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Helper.php#L331-L371 | train |
aristath/kirki | packages/kirki-framework/core/src/Panel.php | Panel.add_panel | 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 ) );
} | php | 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 ) );
} | [
"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.
@param array $args The panel arguments. | [
"Add",
"the",
"panel",
"using",
"the",
"Customizer",
"API",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Panel.php#L46-L55 | train |
aristath/kirki | packages/kirki-framework/module-webfonts/src/Google.php | Google.process_fonts | public function process_fonts() {
// Early exit if font-family is empty.
if ( empty( $this->fonts ) ) {
return;
}
foreach ( $this->fonts as $font => $variants ) {
// Determine if this is indeed a google font or not.
// If it's not, then just remove it from the array.
if ( ! array_key_exists( $font, $this->google_fonts ) ) {
unset( $this->fonts[ $font ] );
continue;
}
// Get all valid font variants for this font.
$font_variants = [];
if ( isset( $this->google_fonts[ $font ]['variants'] ) ) {
$font_variants = $this->google_fonts[ $font ]['variants'];
}
foreach ( $variants as $variant ) {
// If this is not a valid variant for this font-family
// then unset it and move on to the next one.
if ( ! in_array( strval( $variant ), $font_variants, true ) ) {
$variant_key = array_search( $variant, $this->fonts[ $font ], true );
unset( $this->fonts[ $font ][ $variant_key ] );
continue;
}
}
}
} | php | public function process_fonts() {
// Early exit if font-family is empty.
if ( empty( $this->fonts ) ) {
return;
}
foreach ( $this->fonts as $font => $variants ) {
// Determine if this is indeed a google font or not.
// If it's not, then just remove it from the array.
if ( ! array_key_exists( $font, $this->google_fonts ) ) {
unset( $this->fonts[ $font ] );
continue;
}
// Get all valid font variants for this font.
$font_variants = [];
if ( isset( $this->google_fonts[ $font ]['variants'] ) ) {
$font_variants = $this->google_fonts[ $font ]['variants'];
}
foreach ( $variants as $variant ) {
// If this is not a valid variant for this font-family
// then unset it and move on to the next one.
if ( ! in_array( strval( $variant ), $font_variants, true ) ) {
$variant_key = array_search( $variant, $this->fonts[ $font ], true );
unset( $this->fonts[ $font ][ $variant_key ] );
continue;
}
}
}
} | [
"public",
"function",
"process_fonts",
"(",
")",
"{",
"// Early exit if font-family is empty.",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"fonts",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"fonts",
"as",
"$",
"font",
"=>",
"$",
"variants",
")",
"{",
"// Determine if this is indeed a google font or not.",
"// If it's not, then just remove it from the array.",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"font",
",",
"$",
"this",
"->",
"google_fonts",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"fonts",
"[",
"$",
"font",
"]",
")",
";",
"continue",
";",
"}",
"// Get all valid font variants for this font.",
"$",
"font_variants",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"google_fonts",
"[",
"$",
"font",
"]",
"[",
"'variants'",
"]",
")",
")",
"{",
"$",
"font_variants",
"=",
"$",
"this",
"->",
"google_fonts",
"[",
"$",
"font",
"]",
"[",
"'variants'",
"]",
";",
"}",
"foreach",
"(",
"$",
"variants",
"as",
"$",
"variant",
")",
"{",
"// If this is not a valid variant for this font-family",
"// then unset it and move on to the next one.",
"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. | [
"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",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-webfonts/src/Google.php#L196-L228 | train |
aristath/kirki | packages/kirki-framework/module-webfonts/src/Fonts.php | Fonts.get_all_fonts | 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 ) );
} | php | 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 ) );
} | [
"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.
@return array All available fonts. | [
"Compile",
"font",
"options",
"from",
"different",
"sources",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-webfonts/src/Fonts.php#L74-L78 | train |
aristath/kirki | packages/kirki-framework/module-webfonts/src/Fonts.php | Fonts.get_all_variants | 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' ),
];
} | php | 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' ),
];
} | [
"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.
@static
@access public
@return array | [
"Returns",
"an",
"array",
"of",
"all",
"available",
"variants",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-webfonts/src/Fonts.php#L176-L202 | train |
aristath/kirki | packages/kirki-framework/module-webfonts/src/Fonts.php | Fonts.is_google_font | public static function is_google_font( $fontname ) {
if ( is_string( $fontname ) ) {
$fonts = self::get_google_fonts();
return isset( $fonts[ $fontname ] );
}
return false;
} | php | public static function is_google_font( $fontname ) {
if ( is_string( $fontname ) ) {
$fonts = self::get_google_fonts();
return isset( $fonts[ $fontname ] );
}
return false;
} | [
"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.
@static
@access public
@param string $fontname The name of the font we want to check.
@return bool | [
"Determine",
"if",
"a",
"font",
"-",
"name",
"is",
"a",
"valid",
"google",
"font",
"or",
"not",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-webfonts/src/Fonts.php#L212-L218 | train |
aristath/kirki | packages/kirki-framework/module-webfonts/src/Fonts.php | Fonts.get_font_choices | 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;
} | php | 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;
} | [
"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.
@static
@access public
@return array | [
"Gets",
"available",
"options",
"for",
"a",
"font",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/module-webfonts/src/Fonts.php#L227-L234 | train |
aristath/kirki | packages/kirki-framework/core/src/Config.php | Config.get_instance | 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 ];
} | php | 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 ];
} | [
"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.
@static
@access public
@param string $id Config ID.
@param array $args {
Optional. Arguments to override config defaults.
@type string $capability @see https://codex.wordpress.org/Roles_and_Capabilities
@type string $option_type theme_mod or option.
@type string $option_name If we want to used serialized options,
this is where we'll be adding the option name.
All fields using this config will be items in that array.
@type array $compiler Not yet fully implemented
@type bool $disable_output If set to true, no CSS will be generated
from fields using this configuration.
}
@return Kirki\Core\Config | [
"Use",
"this",
"method",
"to",
"get",
"an",
"instance",
"of",
"your",
"config",
".",
"Each",
"config",
"has",
"its",
"own",
"instance",
"of",
"this",
"object",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Config.php#L143-L152 | train |
aristath/kirki | packages/kirki-framework/core/src/Config.php | Config.get_config_ids | public static function get_config_ids() {
$configs = [];
foreach ( self::$instances as $instance ) {
$configs[] = $instance->id;
}
return array_unique( $configs );
} | php | public static function get_config_ids() {
$configs = [];
foreach ( self::$instances as $instance ) {
$configs[] = $instance->id;
}
return array_unique( $configs );
} | [
"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.
@static
@access public
@since 3.0.22
@return array | [
"Get",
"the",
"IDs",
"of",
"all",
"current",
"configs",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Config.php#L162-L168 | train |
aristath/kirki | packages/kirki-framework/control-editor/src/Field/Editor.php | Editor.set_type | protected function set_type() {
global $wp_version;
if ( version_compare( $wp_version, '4.8' ) >= 0 ) {
$this->type = 'kirki-editor';
return;
}
// Fallback for older WordPress versions.
$this->type = 'kirki-generic';
if ( ! is_array( $this->choices ) ) {
$this->choices = [];
}
$this->choices['element'] = 'textarea';
$this->choices['rows'] = '5';
} | php | protected function set_type() {
global $wp_version;
if ( version_compare( $wp_version, '4.8' ) >= 0 ) {
$this->type = 'kirki-editor';
return;
}
// Fallback for older WordPress versions.
$this->type = 'kirki-generic';
if ( ! is_array( $this->choices ) ) {
$this->choices = [];
}
$this->choices['element'] = 'textarea';
$this->choices['rows'] = '5';
} | [
"protected",
"function",
"set_type",
"(",
")",
"{",
"global",
"$",
"wp_version",
";",
"if",
"(",
"version_compare",
"(",
"$",
"wp_version",
",",
"'4.8'",
")",
">=",
"0",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"'kirki-editor'",
";",
"return",
";",
"}",
"// Fallback for older WordPress versions.",
"$",
"this",
"->",
"type",
"=",
"'kirki-generic'",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"choices",
")",
")",
"{",
"$",
"this",
"->",
"choices",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"choices",
"[",
"'element'",
"]",
"=",
"'textarea'",
";",
"$",
"this",
"->",
"choices",
"[",
"'rows'",
"]",
"=",
"'5'",
";",
"}"
] | Sets the control type.
@access protected
@since 1.0
@return void | [
"Sets",
"the",
"control",
"type",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/control-editor/src/Field/Editor.php#L27-L42 | train |
aristath/kirki | packages/kirki-framework/control-sortable/src/Field/Sortable.php | Sortable.sanitize | 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;
} | php | 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;
} | [
"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.
@access public
@since 1.0
@param array $value The checkbox value.
@return array | [
"Sanitizes",
"sortable",
"values",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/control-sortable/src/Field/Sortable.php#L52-L65 | train |
aristath/kirki | docs/files/class-my-theme-kirki.php | My_Theme_Kirki.get_option | public static function get_option( $config_id = '', $field_id = '' ) {
// if Kirki exists, use it.
if ( class_exists( 'Kirki' ) ) {
return Kirki::get_option( $config_id, $field_id );
}
// Kirki does not exist, continue with our custom implementation.
// Get the default value of the field.
$default = '';
if ( isset( self::$fields[ $field_id ] ) && isset( self::$fields[ $field_id ]['default'] ) ) {
$default = self::$fields[ $field_id ]['default'];
}
// Make sure the config is defined.
if ( isset( self::$config[ $config_id ] ) ) {
if ( 'option' === self::$config[ $config_id ]['option_type'] ) {
// check if we're using serialized options.
if ( isset( self::$config[ $config_id ]['option_name'] ) && ! empty( self::$config[ $config_id ]['option_name'] ) ) {
// Get all our options.
$all_options = get_option( self::$config[ $config_id ]['option_name'], array() );
// If our option is not saved, return the default value.
// If option was set, return its value unserialized.
return ( ! isset( $all_options[ $field_id ] ) ) ? $default : maybe_unserialize( $all_options[ $field_id ] );
}
// If we're not using serialized options, get the value and return it.
// We'll be using a dummy default here to check if the option has been set or not.
// We'll be using md5 to make sure it's randomish and impossible to be actually set by a user.
$dummy = md5( $config_id . '_UNDEFINED_VALUE' );
$value = get_option( $field_id, $dummy );
// setting has not been set, return default.
return ( $dummy === $value ) ? $default : $value;
}
// We're not using options so fallback to theme_mod.
return get_theme_mod( $field_id, $default );
}
} | php | public static function get_option( $config_id = '', $field_id = '' ) {
// if Kirki exists, use it.
if ( class_exists( 'Kirki' ) ) {
return Kirki::get_option( $config_id, $field_id );
}
// Kirki does not exist, continue with our custom implementation.
// Get the default value of the field.
$default = '';
if ( isset( self::$fields[ $field_id ] ) && isset( self::$fields[ $field_id ]['default'] ) ) {
$default = self::$fields[ $field_id ]['default'];
}
// Make sure the config is defined.
if ( isset( self::$config[ $config_id ] ) ) {
if ( 'option' === self::$config[ $config_id ]['option_type'] ) {
// check if we're using serialized options.
if ( isset( self::$config[ $config_id ]['option_name'] ) && ! empty( self::$config[ $config_id ]['option_name'] ) ) {
// Get all our options.
$all_options = get_option( self::$config[ $config_id ]['option_name'], array() );
// If our option is not saved, return the default value.
// If option was set, return its value unserialized.
return ( ! isset( $all_options[ $field_id ] ) ) ? $default : maybe_unserialize( $all_options[ $field_id ] );
}
// If we're not using serialized options, get the value and return it.
// We'll be using a dummy default here to check if the option has been set or not.
// We'll be using md5 to make sure it's randomish and impossible to be actually set by a user.
$dummy = md5( $config_id . '_UNDEFINED_VALUE' );
$value = get_option( $field_id, $dummy );
// setting has not been set, return default.
return ( $dummy === $value ) ? $default : $value;
}
// We're not using options so fallback to theme_mod.
return get_theme_mod( $field_id, $default );
}
} | [
"public",
"static",
"function",
"get_option",
"(",
"$",
"config_id",
"=",
"''",
",",
"$",
"field_id",
"=",
"''",
")",
"{",
"// if Kirki exists, use it.",
"if",
"(",
"class_exists",
"(",
"'Kirki'",
")",
")",
"{",
"return",
"Kirki",
"::",
"get_option",
"(",
"$",
"config_id",
",",
"$",
"field_id",
")",
";",
"}",
"// Kirki does not exist, continue with our custom implementation.",
"// Get the default value of the field.",
"$",
"default",
"=",
"''",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"fields",
"[",
"$",
"field_id",
"]",
")",
"&&",
"isset",
"(",
"self",
"::",
"$",
"fields",
"[",
"$",
"field_id",
"]",
"[",
"'default'",
"]",
")",
")",
"{",
"$",
"default",
"=",
"self",
"::",
"$",
"fields",
"[",
"$",
"field_id",
"]",
"[",
"'default'",
"]",
";",
"}",
"// Make sure the config is defined.",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"config",
"[",
"$",
"config_id",
"]",
")",
")",
"{",
"if",
"(",
"'option'",
"===",
"self",
"::",
"$",
"config",
"[",
"$",
"config_id",
"]",
"[",
"'option_type'",
"]",
")",
"{",
"// check if we're using serialized options.",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"config",
"[",
"$",
"config_id",
"]",
"[",
"'option_name'",
"]",
")",
"&&",
"!",
"empty",
"(",
"self",
"::",
"$",
"config",
"[",
"$",
"config_id",
"]",
"[",
"'option_name'",
"]",
")",
")",
"{",
"// Get all our options.",
"$",
"all_options",
"=",
"get_option",
"(",
"self",
"::",
"$",
"config",
"[",
"$",
"config_id",
"]",
"[",
"'option_name'",
"]",
",",
"array",
"(",
")",
")",
";",
"// If our option is not saved, return the default value.",
"// If option was set, return its value unserialized.",
"return",
"(",
"!",
"isset",
"(",
"$",
"all_options",
"[",
"$",
"field_id",
"]",
")",
")",
"?",
"$",
"default",
":",
"maybe_unserialize",
"(",
"$",
"all_options",
"[",
"$",
"field_id",
"]",
")",
";",
"}",
"// If we're not using serialized options, get the value and return it.",
"// We'll be using a dummy default here to check if the option has been set or not.",
"// We'll be using md5 to make sure it's randomish and impossible to be actually set by a user.",
"$",
"dummy",
"=",
"md5",
"(",
"$",
"config_id",
".",
"'_UNDEFINED_VALUE'",
")",
";",
"$",
"value",
"=",
"get_option",
"(",
"$",
"field_id",
",",
"$",
"dummy",
")",
";",
"// setting has not been set, return default.",
"return",
"(",
"$",
"dummy",
"===",
"$",
"value",
")",
"?",
"$",
"default",
":",
"$",
"value",
";",
"}",
"// We're not using options so fallback to theme_mod.",
"return",
"get_theme_mod",
"(",
"$",
"field_id",
",",
"$",
"default",
")",
";",
"}",
"}"
] | Get the value of an option from the db.
@param string $config_id The ID of the configuration corresponding to this field.
@param string $field_id The field_id (defined as 'settings' in the field arguments).
@return mixed The saved value of the field. | [
"Get",
"the",
"value",
"of",
"an",
"option",
"from",
"the",
"db",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/docs/files/class-my-theme-kirki.php#L66-L108 | train |
aristath/kirki | docs/files/class-my-theme-kirki.php | My_Theme_Kirki.add_field | public static function add_field( $config_id, $args ) {
// if Kirki exists, use it.
if ( class_exists( 'Kirki' ) ) {
Kirki::add_field( $config_id, $args );
return;
}
// Kirki was not located, so we'll need to add our fields here.
// Check that the "settings" & "type" arguments have been defined.
if ( isset( $args['settings'] ) && isset( $args['type'] ) ) {
// Make sure we add the config_id to the field itself.
// This will make it easier to get the value when generating the CSS later.
if ( ! isset( $args['kirki_config'] ) ) {
$args['kirki_config'] = $config_id;
}
self::$fields[ $args['settings'] ] = $args;
}
} | php | public static function add_field( $config_id, $args ) {
// if Kirki exists, use it.
if ( class_exists( 'Kirki' ) ) {
Kirki::add_field( $config_id, $args );
return;
}
// Kirki was not located, so we'll need to add our fields here.
// Check that the "settings" & "type" arguments have been defined.
if ( isset( $args['settings'] ) && isset( $args['type'] ) ) {
// Make sure we add the config_id to the field itself.
// This will make it easier to get the value when generating the CSS later.
if ( ! isset( $args['kirki_config'] ) ) {
$args['kirki_config'] = $config_id;
}
self::$fields[ $args['settings'] ] = $args;
}
} | [
"public",
"static",
"function",
"add_field",
"(",
"$",
"config_id",
",",
"$",
"args",
")",
"{",
"// if Kirki exists, use it.",
"if",
"(",
"class_exists",
"(",
"'Kirki'",
")",
")",
"{",
"Kirki",
"::",
"add_field",
"(",
"$",
"config_id",
",",
"$",
"args",
")",
";",
"return",
";",
"}",
"// Kirki was not located, so we'll need to add our fields here.",
"// Check that the \"settings\" & \"type\" arguments have been defined.",
"if",
"(",
"isset",
"(",
"$",
"args",
"[",
"'settings'",
"]",
")",
"&&",
"isset",
"(",
"$",
"args",
"[",
"'type'",
"]",
")",
")",
"{",
"// Make sure we add the config_id to the field itself.",
"// This will make it easier to get the value when generating the CSS later.",
"if",
"(",
"!",
"isset",
"(",
"$",
"args",
"[",
"'kirki_config'",
"]",
")",
")",
"{",
"$",
"args",
"[",
"'kirki_config'",
"]",
"=",
"$",
"config_id",
";",
"}",
"self",
"::",
"$",
"fields",
"[",
"$",
"args",
"[",
"'settings'",
"]",
"]",
"=",
"$",
"args",
";",
"}",
"}"
] | Create a new field
@param string $config_id The configuration ID.
@param array $args The field's arguments.
@return null | [
"Create",
"a",
"new",
"field"
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/docs/files/class-my-theme-kirki.php#L166-L185 | train |
aristath/kirki | docs/files/class-my-theme-kirki.php | My_Theme_Kirki.enqueue_styles | public function enqueue_styles() {
// If Kirki exists there's no need to proceed any further.
if ( class_exists( 'Kirki' ) ) {
return;
}
// Get our inline styles.
$styles = $this->get_styles();
// If we have some styles to add, add them now.
if ( ! empty( $styles ) ) {
// Enqueue the theme's style.css file.
$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 );
}
} | php | public function enqueue_styles() {
// If Kirki exists there's no need to proceed any further.
if ( class_exists( 'Kirki' ) ) {
return;
}
// Get our inline styles.
$styles = $this->get_styles();
// If we have some styles to add, add them now.
if ( ! empty( $styles ) ) {
// Enqueue the theme's style.css file.
$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 );
}
} | [
"public",
"function",
"enqueue_styles",
"(",
")",
"{",
"// If Kirki exists there's no need to proceed any further.",
"if",
"(",
"class_exists",
"(",
"'Kirki'",
")",
")",
"{",
"return",
";",
"}",
"// Get our inline styles.",
"$",
"styles",
"=",
"$",
"this",
"->",
"get_styles",
"(",
")",
";",
"// If we have some styles to add, add them now.",
"if",
"(",
"!",
"empty",
"(",
"$",
"styles",
")",
")",
"{",
"// Enqueue the theme's style.css file.",
"$",
"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.
@access public
@return null | [
"Enqueues",
"the",
"stylesheet",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/docs/files/class-my-theme-kirki.php#L193-L211 | train |
aristath/kirki | docs/files/class-my-theme-kirki.php | My_Theme_Kirki.enqueue_fonts | public function enqueue_fonts() {
// Check if we need to exit early.
if ( empty( self::$fields ) || ! is_array( self::$fields ) ) {
return;
}
foreach ( self::$fields as $field ) {
// Process typography fields.
if ( isset( $field['type'] ) && 'typography' === $field['type'] ) {
// Check if we've got everything we need.
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'] );
// Check that the URL is valid. we're going to use transients to make this faster.
$url_is_valid = get_transient( $key );
// If transient does not exist.
if ( false === $url_is_valid ) {
$response = wp_remote_get( 'https:' . $url );
if ( ! is_array( $response ) ) {
// The url was not properly formatted,
// cache for 12 hours and continue to the next field.
set_transient( $key, null, 12 * HOUR_IN_SECONDS );
continue;
}
// Check the response headers.
if ( isset( $response['response'] ) && isset( $response['response']['code'] ) ) {
if ( 200 === $response['response']['code'] ) {
// URL was ok. Set transient to true and cache for a week.
set_transient( $key, true, 7 * 24 * HOUR_IN_SECONDS );
$url_is_valid = true;
}
}
}
// If the font-link is valid, enqueue it.
if ( $url_is_valid ) {
wp_enqueue_style( $key, $url, array(), '1.0' );
}
}
}
}
} | php | public function enqueue_fonts() {
// Check if we need to exit early.
if ( empty( self::$fields ) || ! is_array( self::$fields ) ) {
return;
}
foreach ( self::$fields as $field ) {
// Process typography fields.
if ( isset( $field['type'] ) && 'typography' === $field['type'] ) {
// Check if we've got everything we need.
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'] );
// Check that the URL is valid. we're going to use transients to make this faster.
$url_is_valid = get_transient( $key );
// If transient does not exist.
if ( false === $url_is_valid ) {
$response = wp_remote_get( 'https:' . $url );
if ( ! is_array( $response ) ) {
// The url was not properly formatted,
// cache for 12 hours and continue to the next field.
set_transient( $key, null, 12 * HOUR_IN_SECONDS );
continue;
}
// Check the response headers.
if ( isset( $response['response'] ) && isset( $response['response']['code'] ) ) {
if ( 200 === $response['response']['code'] ) {
// URL was ok. Set transient to true and cache for a week.
set_transient( $key, true, 7 * 24 * HOUR_IN_SECONDS );
$url_is_valid = true;
}
}
}
// If the font-link is valid, enqueue it.
if ( $url_is_valid ) {
wp_enqueue_style( $key, $url, array(), '1.0' );
}
}
}
}
} | [
"public",
"function",
"enqueue_fonts",
"(",
")",
"{",
"// Check if we need to exit early.",
"if",
"(",
"empty",
"(",
"self",
"::",
"$",
"fields",
")",
"||",
"!",
"is_array",
"(",
"self",
"::",
"$",
"fields",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"self",
"::",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"// Process typography fields.",
"if",
"(",
"isset",
"(",
"$",
"field",
"[",
"'type'",
"]",
")",
"&&",
"'typography'",
"===",
"$",
"field",
"[",
"'type'",
"]",
")",
"{",
"// Check if we've got everything we need.",
"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'",
"]",
")",
";",
"// Check that the URL is valid. we're going to use transients to make this faster.",
"$",
"url_is_valid",
"=",
"get_transient",
"(",
"$",
"key",
")",
";",
"// If transient does not exist.",
"if",
"(",
"false",
"===",
"$",
"url_is_valid",
")",
"{",
"$",
"response",
"=",
"wp_remote_get",
"(",
"'https:'",
".",
"$",
"url",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"response",
")",
")",
"{",
"// The url was not properly formatted,",
"// cache for 12 hours and continue to the next field.",
"set_transient",
"(",
"$",
"key",
",",
"null",
",",
"12",
"*",
"HOUR_IN_SECONDS",
")",
";",
"continue",
";",
"}",
"// Check the response headers.",
"if",
"(",
"isset",
"(",
"$",
"response",
"[",
"'response'",
"]",
")",
"&&",
"isset",
"(",
"$",
"response",
"[",
"'response'",
"]",
"[",
"'code'",
"]",
")",
")",
"{",
"if",
"(",
"200",
"===",
"$",
"response",
"[",
"'response'",
"]",
"[",
"'code'",
"]",
")",
"{",
"// URL was ok. Set transient to true and cache for a week.",
"set_transient",
"(",
"$",
"key",
",",
"true",
",",
"7",
"*",
"24",
"*",
"HOUR_IN_SECONDS",
")",
";",
"$",
"url_is_valid",
"=",
"true",
";",
"}",
"}",
"}",
"// If the font-link is valid, enqueue it.",
"if",
"(",
"$",
"url_is_valid",
")",
"{",
"wp_enqueue_style",
"(",
"$",
"key",
",",
"$",
"url",
",",
"array",
"(",
")",
",",
"'1.0'",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Enqueue google fonts.
@access public
@return null | [
"Enqueue",
"google",
"fonts",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/docs/files/class-my-theme-kirki.php#L364-L420 | train |
aristath/kirki | packages/kirki-framework/field-typography/src/Field/Typography.php | Typography.add_main_field | private function add_main_field( $config_id, $args ) {
/**
* Add a hidden field, the label & description.
*/
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
)
);
} | php | private function add_main_field( $config_id, $args ) {
/**
* Add a hidden field, the label & description.
*/
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
)
);
} | [
"private",
"function",
"add_main_field",
"(",
"$",
"config_id",
",",
"$",
"args",
")",
"{",
"/**\n\t\t * Add a hidden field, the label & description.\n\t\t */",
"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.
@access private
@since 1.0
@param string $config_id The config-ID.
@param array $args The field arguments.
@return void | [
"Adds",
"the",
"main",
"field",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/field-typography/src/Field/Typography.php#L78-L97 | train |
aristath/kirki | packages/kirki-framework/field-typography/src/Field/Typography.php | Typography.sanitize | 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':
// Use 'regular' instead of 400 for font-variant.
$value['variant'] = ( 400 === $val || '400' === $val ) ? 'regular' : $val;
// Get font-weight from variant.
$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'] );
// Get font-style from variant.
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;
} | php | 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':
// Use 'regular' instead of 400 for font-variant.
$value['variant'] = ( 400 === $val || '400' === $val ) ? 'regular' : $val;
// Get font-weight from variant.
$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'] );
// Get font-style from variant.
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;
} | [
"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'",
":",
"// Use 'regular' instead of 400 for font-variant.",
"$",
"value",
"[",
"'variant'",
"]",
"=",
"(",
"400",
"===",
"$",
"val",
"||",
"'400'",
"===",
"$",
"val",
")",
"?",
"'regular'",
":",
"$",
"val",
";",
"// Get font-weight from variant.",
"$",
"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'",
"]",
")",
";",
"// Get font-style from variant.",
"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
@static
@since 1.0
@param array $value The value.
@return array | [
"Sanitizes",
"typography",
"controls"
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/field-typography/src/Field/Typography.php#L468-L528 | train |
aristath/kirki | packages/kirki-framework/field-typography/src/Field/Typography.php | Typography.enqueue_scripts | 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;
}
} | php | 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;
}
} | [
"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.
@access public
@since 1.0
@return void | [
"Enqueue",
"scripts",
"&",
"styles",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/field-typography/src/Field/Typography.php#L537-L550 | train |
aristath/kirki | packages/kirki-framework/core/src/Field.php | Field.set_field | protected function set_field() {
$properties = get_class_vars( __CLASS__ );
// Some things must run before the others.
$this->set_option_type();
$this->set_settings();
// Sanitize the properties, skipping the ones that have already run above.
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();
}
}
// Get all arguments with their values.
$args = get_object_vars( $this );
foreach ( array_keys( $args ) as $key ) {
$args[ $key ] = $this->$key;
}
// Add the field to the static $fields variable properly indexed.
Kirki::$fields[ $this->settings ] = $args;
} | php | protected function set_field() {
$properties = get_class_vars( __CLASS__ );
// Some things must run before the others.
$this->set_option_type();
$this->set_settings();
// Sanitize the properties, skipping the ones that have already run above.
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();
}
}
// Get all arguments with their values.
$args = get_object_vars( $this );
foreach ( array_keys( $args ) as $key ) {
$args[ $key ] = $this->$key;
}
// Add the field to the static $fields variable properly indexed.
Kirki::$fields[ $this->settings ] = $args;
} | [
"protected",
"function",
"set_field",
"(",
")",
"{",
"$",
"properties",
"=",
"get_class_vars",
"(",
"__CLASS__",
")",
";",
"// Some things must run before the others.",
"$",
"this",
"->",
"set_option_type",
"(",
")",
";",
"$",
"this",
"->",
"set_settings",
"(",
")",
";",
"// Sanitize the properties, skipping the ones that have already run above.",
"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",
"(",
")",
";",
"}",
"}",
"// Get all arguments with their values.",
"$",
"args",
"=",
"get_object_vars",
"(",
"$",
"this",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"args",
")",
"as",
"$",
"key",
")",
"{",
"$",
"args",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"$",
"key",
";",
"}",
"// Add the field to the static $fields variable properly indexed.",
"Kirki",
"::",
"$",
"fields",
"[",
"$",
"this",
"->",
"settings",
"]",
"=",
"$",
"args",
";",
"}"
] | Processes the field arguments
@access protected | [
"Processes",
"the",
"field",
"arguments"
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Field.php#L304-L332 | train |
aristath/kirki | packages/kirki-framework/core/src/Field.php | Field.set_option_type | protected function set_option_type() {
// Take care of common typos.
if ( 'options' === $this->option_type ) {
$this->option_type = 'option';
}
// Take care of common typos.
if ( 'theme_mods' === $this->option_type ) {
/* translators: %1$s represents the field ID where the error occurs. */
_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';
}
} | php | protected function set_option_type() {
// Take care of common typos.
if ( 'options' === $this->option_type ) {
$this->option_type = 'option';
}
// Take care of common typos.
if ( 'theme_mods' === $this->option_type ) {
/* translators: %1$s represents the field ID where the error occurs. */
_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';
}
} | [
"protected",
"function",
"set_option_type",
"(",
")",
"{",
"// Take care of common typos.",
"if",
"(",
"'options'",
"===",
"$",
"this",
"->",
"option_type",
")",
"{",
"$",
"this",
"->",
"option_type",
"=",
"'option'",
";",
"}",
"// Take care of common typos.",
"if",
"(",
"'theme_mods'",
"===",
"$",
"this",
"->",
"option_type",
")",
"{",
"/* translators: %1$s represents the field ID where the error occurs. */",
"_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
@access protected | [
"Make",
"sure",
"we",
"re",
"using",
"the",
"correct",
"option_type"
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Field.php#L348-L361 | train |
aristath/kirki | packages/kirki-framework/core/src/Field.php | Field.set_partial_refresh | 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'] ) ) {
/* translators: %1$s represents the field ID where the error occurs. */
_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';
}
} | php | 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'] ) ) {
/* translators: %1$s represents the field ID where the error occurs. */
_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';
}
} | [
"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'",
"]",
")",
")",
"{",
"/* translators: %1$s represents the field ID where the error occurs. */",
"_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.
@access protected | [
"Modifications",
"for",
"partial",
"refreshes",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Field.php#L368-L383 | train |
aristath/kirki | packages/kirki-framework/core/src/Field.php | Field.set_settings | protected function set_settings() {
// If settings is not an array, temporarily convert it to an array.
// This is just to allow us to process everything the same way and avoid code duplication.
// if settings is not an array then it will not be set as an array in the end.
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 we're using serialized options then we need to spice this up.
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'];
}
} | php | protected function set_settings() {
// If settings is not an array, temporarily convert it to an array.
// This is just to allow us to process everything the same way and avoid code duplication.
// if settings is not an array then it will not be set as an array in the end.
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 we're using serialized options then we need to spice this up.
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'];
}
} | [
"protected",
"function",
"set_settings",
"(",
")",
"{",
"// If settings is not an array, temporarily convert it to an array.",
"// This is just to allow us to process everything the same way and avoid code duplication.",
"// if settings is not an array then it will not be set as an array in the end.",
"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 we're using serialized options then we need to spice this up.",
"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.
@access protected | [
"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",
"."
] | b7549b52a3c470960d691357df262e6c9e9483f8 | https://github.com/aristath/kirki/blob/b7549b52a3c470960d691357df262e6c9e9483f8/packages/kirki-framework/core/src/Field.php#L392-L415 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Content.php | Content.copyUntilUnless | 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;
}
// rewind changes and return nothing
$this->pos = $lastPos;
return '';
} | php | 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;
}
// rewind changes and return nothing
$this->pos = $lastPos;
return '';
} | [
"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",
";",
"}",
"// rewind changes and return nothing",
"$",
"this",
"->",
"pos",
"=",
"$",
"lastPos",
";",
"return",
"''",
";",
"}"
] | Copies the content until the string is found and return it
unless the 'unless' is found in the substring.
@param string $string
@param string $unless
@return string | [
"Copies",
"the",
"content",
"until",
"the",
"string",
"is",
"found",
"and",
"return",
"it",
"unless",
"the",
"unless",
"is",
"found",
"in",
"the",
"substring",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Content.php#L185-L199 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Content.php | Content.copyByToken | public function copyByToken(string $token, bool $char = false, bool $escape = false)
{
$string = $this->$token;
return $this->copyUntil($string, $char, $escape);
} | php | public function copyByToken(string $token, bool $char = false, bool $escape = false)
{
$string = $this->$token;
return $this->copyUntil($string, $char, $escape);
} | [
"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.,
@param string $token
@param bool $char
@param bool $escape
@return string
@uses $this->copyUntil() | [
"Copies",
"the",
"content",
"until",
"it",
"reaches",
"the",
"token",
"string",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Content.php#L210-L215 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Content.php | Content.skip | public function skip(string $string, bool $copy = false)
{
$len = strspn($this->content, $string, $this->pos);
// make it chainable if they don't want a copy
$return = $this;
if ($copy) {
$return = substr($this->content, $this->pos, $len);
}
// update the position
$this->pos += $len;
return $return;
} | php | public function skip(string $string, bool $copy = false)
{
$len = strspn($this->content, $string, $this->pos);
// make it chainable if they don't want a copy
$return = $this;
if ($copy) {
$return = substr($this->content, $this->pos, $len);
}
// update the position
$this->pos += $len;
return $return;
} | [
"public",
"function",
"skip",
"(",
"string",
"$",
"string",
",",
"bool",
"$",
"copy",
"=",
"false",
")",
"{",
"$",
"len",
"=",
"strspn",
"(",
"$",
"this",
"->",
"content",
",",
"$",
"string",
",",
"$",
"this",
"->",
"pos",
")",
";",
"// make it chainable if they don't want a copy",
"$",
"return",
"=",
"$",
"this",
";",
"if",
"(",
"$",
"copy",
")",
"{",
"$",
"return",
"=",
"substr",
"(",
"$",
"this",
"->",
"content",
",",
"$",
"this",
"->",
"pos",
",",
"$",
"len",
")",
";",
"}",
"// update the position",
"$",
"this",
"->",
"pos",
"+=",
"$",
"len",
";",
"return",
"$",
"return",
";",
"}"
] | Skip a given set of characters.
@param string $string
@param bool $copy
@return Content|string | [
"Skip",
"a",
"given",
"set",
"of",
"characters",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Content.php#L224-L238 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom/InnerNode.php | InnerNode.propagateEncoding | public function propagateEncoding(Encode $encode): void
{
$this->encode = $encode;
$this->tag->setEncoding($encode);
// check children
foreach ($this->children as $id => $child) {
/** @var AbstractNode $node */
$node = $child['node'];
$node->propagateEncoding($encode);
}
} | php | public function propagateEncoding(Encode $encode): void
{
$this->encode = $encode;
$this->tag->setEncoding($encode);
// check children
foreach ($this->children as $id => $child) {
/** @var AbstractNode $node */
$node = $child['node'];
$node->propagateEncoding($encode);
}
} | [
"public",
"function",
"propagateEncoding",
"(",
"Encode",
"$",
"encode",
")",
":",
"void",
"{",
"$",
"this",
"->",
"encode",
"=",
"$",
"encode",
";",
"$",
"this",
"->",
"tag",
"->",
"setEncoding",
"(",
"$",
"encode",
")",
";",
"// check children",
"foreach",
"(",
"$",
"this",
"->",
"children",
"as",
"$",
"id",
"=>",
"$",
"child",
")",
"{",
"/** @var AbstractNode $node */",
"$",
"node",
"=",
"$",
"child",
"[",
"'node'",
"]",
";",
"$",
"node",
"->",
"propagateEncoding",
"(",
"$",
"encode",
")",
";",
"}",
"}"
] | Sets the encoding class to this node and propagates it
to all its children.
@param Encode $encode
@return void | [
"Sets",
"the",
"encoding",
"class",
"to",
"this",
"node",
"and",
"propagates",
"it",
"to",
"all",
"its",
"children",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom/InnerNode.php#L30-L40 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom/InnerNode.php | InnerNode.insertBefore | public function insertBefore(AbstractNode $child, int $id): bool
{
return $this->addChild($child, $id);
} | php | public function insertBefore(AbstractNode $child, int $id): bool
{
return $this->addChild($child, $id);
} | [
"public",
"function",
"insertBefore",
"(",
"AbstractNode",
"$",
"child",
",",
"int",
"$",
"id",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"addChild",
"(",
"$",
"child",
",",
"$",
"id",
")",
";",
"}"
] | Insert element before child with provided id
@param AbstractNode $child
@param int $id
@return bool | [
"Insert",
"element",
"before",
"child",
"with",
"provided",
"id"
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom/InnerNode.php#L184-L187 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom/InnerNode.php | InnerNode.insertAfter | 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']);
}
// clear cache
$this->clear();
return $this->addChild($child);
} | php | 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']);
}
// clear cache
$this->clear();
return $this->addChild($child);
} | [
"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'",
"]",
")",
";",
"}",
"// clear cache",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"return",
"$",
"this",
"->",
"addChild",
"(",
"$",
"child",
")",
";",
"}"
] | Insert element before after with provided id
@param AbstractNode $child
@param int $id
@return bool | [
"Insert",
"element",
"before",
"after",
"with",
"provided",
"id"
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom/InnerNode.php#L196-L210 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom/InnerNode.php | InnerNode.removeChild | public function removeChild(int $id): InnerNode
{
if ( ! isset($this->children[$id])) {
return $this;
}
// handle moving next and previous assignments.
$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;
}
// remove the child
unset($this->children[$id]);
//clear any cache
$this->clear();
return $this;
} | php | public function removeChild(int $id): InnerNode
{
if ( ! isset($this->children[$id])) {
return $this;
}
// handle moving next and previous assignments.
$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;
}
// remove the child
unset($this->children[$id]);
//clear any cache
$this->clear();
return $this;
} | [
"public",
"function",
"removeChild",
"(",
"int",
"$",
"id",
")",
":",
"InnerNode",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"children",
"[",
"$",
"id",
"]",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"// handle moving next and previous assignments.",
"$",
"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",
";",
"}",
"// remove the child",
"unset",
"(",
"$",
"this",
"->",
"children",
"[",
"$",
"id",
"]",
")",
";",
"//clear any cache",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Removes the child by id.
@param int $id
@return InnerNode
@chainable | [
"Removes",
"the",
"child",
"by",
"id",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom/InnerNode.php#L219-L242 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom/InnerNode.php | InnerNode.hasNextChild | public function hasNextChild(int $id)
{
$child= $this->getChild($id);
return $this->children[$child->id()]['next'];
} | php | public function hasNextChild(int $id)
{
$child= $this->getChild($id);
return $this->children[$child->id()]['next'];
} | [
"public",
"function",
"hasNextChild",
"(",
"int",
"$",
"id",
")",
"{",
"$",
"child",
"=",
"$",
"this",
"->",
"getChild",
"(",
"$",
"id",
")",
";",
"return",
"$",
"this",
"->",
"children",
"[",
"$",
"child",
"->",
"id",
"(",
")",
"]",
"[",
"'next'",
"]",
";",
"}"
] | Check if has next Child
@param int $id
@return mixed | [
"Check",
"if",
"has",
"next",
"Child"
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom/InnerNode.php#L250-L254 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom/InnerNode.php | InnerNode.isDescendant | public function isDescendant(int $id): bool
{
if ($this->isChild($id)) {
return true;
}
foreach ($this->children as $childId => $child) {
/** @var InnerNode $node */
$node = $child['node'];
if ($node instanceof InnerNode &&
$node->hasChildren() &&
$node->isDescendant($id)
) {
return true;
}
}
return false;
} | php | public function isDescendant(int $id): bool
{
if ($this->isChild($id)) {
return true;
}
foreach ($this->children as $childId => $child) {
/** @var InnerNode $node */
$node = $child['node'];
if ($node instanceof InnerNode &&
$node->hasChildren() &&
$node->isDescendant($id)
) {
return true;
}
}
return false;
} | [
"public",
"function",
"isDescendant",
"(",
"int",
"$",
"id",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"isChild",
"(",
"$",
"id",
")",
")",
"{",
"return",
"true",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"children",
"as",
"$",
"childId",
"=>",
"$",
"child",
")",
"{",
"/** @var InnerNode $node */",
"$",
"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.
@param int $id
@return bool | [
"Checks",
"if",
"the",
"given",
"node",
"id",
"is",
"a",
"descendant",
"of",
"the",
"current",
"node",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom/InnerNode.php#L402-L420 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom/Tag.php | Tag.setStyleAttributeValue | 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);
} | php | 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);
} | [
"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.
@param mixed $attr_key
@param mixed $attr_value | [
"Set",
"inline",
"style",
"attribute",
"value",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom/Tag.php#L187-L199 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom/Tag.php | Tag.getStyleAttributeArray | 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;
} | php | 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;
} | [
"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
@return array | [
"Get",
"style",
"attribute",
"in",
"array"
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom/Tag.php#L206-L222 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom/Tag.php | Tag.setAttributes | public function setAttributes(array $attr)
{
foreach ($attr as $key => $value) {
$this->setAttribute($key, $value);
}
return $this;
} | php | public function setAttributes(array $attr)
{
foreach ($attr as $key => $value) {
$this->setAttribute($key, $value);
}
return $this;
} | [
"public",
"function",
"setAttributes",
"(",
"array",
"$",
"attr",
")",
"{",
"foreach",
"(",
"$",
"attr",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets the attributes for this tag
@param array $attr
@return $this | [
"Sets",
"the",
"attributes",
"for",
"this",
"tag"
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom/Tag.php#L254-L261 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom/Tag.php | Tag.getAttributes | public function getAttributes()
{
$return = [];
foreach ($this->attr as $attr => $info) {
$return[$attr] = $this->getAttribute($attr);
}
return $return;
} | php | public function getAttributes()
{
$return = [];
foreach ($this->attr as $attr => $info) {
$return[$attr] = $this->getAttribute($attr);
}
return $return;
} | [
"public",
"function",
"getAttributes",
"(",
")",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"attr",
"as",
"$",
"attr",
"=>",
"$",
"info",
")",
"{",
"$",
"return",
"[",
"$",
"attr",
"]",
"=",
"$",
"this",
"->",
"getAttribute",
"(",
"$",
"attr",
")",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Returns all attributes of this tag.
@return array | [
"Returns",
"all",
"attributes",
"of",
"this",
"tag",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom/Tag.php#L268-L276 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom/Tag.php | Tag.makeOpeningTag | public function makeOpeningTag()
{
$return = '<'.$this->name;
// add the attributes
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.'>';
}
} | php | public function makeOpeningTag()
{
$return = '<'.$this->name;
// add the attributes
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.'>';
}
} | [
"public",
"function",
"makeOpeningTag",
"(",
")",
"{",
"$",
"return",
"=",
"'<'",
".",
"$",
"this",
"->",
"name",
";",
"// add the attributes",
"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.
@return string | [
"Generates",
"the",
"opening",
"tag",
"for",
"this",
"object",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom/Tag.php#L314-L336 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom/TextNode.php | TextNode.text | public function text(): string
{
// convert charset
if ( ! is_null($this->encode)) {
if ( ! is_null($this->convertedText)) {
// we already know the converted value
return $this->convertedText;
}
$text = $this->encode->convert($this->text);
// remember the conversion
$this->convertedText = $text;
return $text;
} else {
return $this->text;
}
} | php | public function text(): string
{
// convert charset
if ( ! is_null($this->encode)) {
if ( ! is_null($this->convertedText)) {
// we already know the converted value
return $this->convertedText;
}
$text = $this->encode->convert($this->text);
// remember the conversion
$this->convertedText = $text;
return $text;
} else {
return $this->text;
}
} | [
"public",
"function",
"text",
"(",
")",
":",
"string",
"{",
"// convert charset",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"encode",
")",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"convertedText",
")",
")",
"{",
"// we already know the converted value",
"return",
"$",
"this",
"->",
"convertedText",
";",
"}",
"$",
"text",
"=",
"$",
"this",
"->",
"encode",
"->",
"convert",
"(",
"$",
"this",
"->",
"text",
")",
";",
"// remember the conversion",
"$",
"this",
"->",
"convertedText",
"=",
"$",
"text",
";",
"return",
"$",
"text",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"text",
";",
"}",
"}"
] | Returns the text of this node.
@return string | [
"Returns",
"the",
"text",
"of",
"this",
"node",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom/TextNode.php#L59-L76 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom/TextNode.php | TextNode.setText | public function setText(string $text): void
{
$this->text = $text;
if ( ! is_null($this->encode)) {
$text = $this->encode->convert($text);
// remember the conversion
$this->convertedText = $text;
}
} | php | public function setText(string $text): void
{
$this->text = $text;
if ( ! is_null($this->encode)) {
$text = $this->encode->convert($text);
// remember the conversion
$this->convertedText = $text;
}
} | [
"public",
"function",
"setText",
"(",
"string",
"$",
"text",
")",
":",
"void",
"{",
"$",
"this",
"->",
"text",
"=",
"$",
"text",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"encode",
")",
")",
"{",
"$",
"text",
"=",
"$",
"this",
"->",
"encode",
"->",
"convert",
"(",
"$",
"text",
")",
";",
"// remember the conversion",
"$",
"this",
"->",
"convertedText",
"=",
"$",
"text",
";",
"}",
"}"
] | Sets the text for this node.
@var string $text
@return void | [
"Sets",
"the",
"text",
"for",
"this",
"node",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom/TextNode.php#L84-L94 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom.php | Dom.addNoSlashTag | public function addNoSlashTag($tag): Dom
{
if ( ! is_array($tag)) {
$tag = [$tag];
}
foreach ($tag as $value) {
$this->noSlash[] = $value;
}
return $this;
} | php | public function addNoSlashTag($tag): Dom
{
if ( ! is_array($tag)) {
$tag = [$tag];
}
foreach ($tag as $value) {
$this->noSlash[] = $value;
}
return $this;
} | [
"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
@param $tag
@return Dom
@chainable | [
"Adds",
"a",
"tag",
"to",
"the",
"list",
"of",
"self",
"closing",
"tags",
"that",
"should",
"not",
"have",
"a",
"trailing",
"slash"
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom.php#L315-L325 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom.php | Dom.removeNoSlashTag | public function removeNoSlashTag($tag): Dom
{
if ( ! is_array($tag)) {
$tag = [$tag];
}
$this->noSlash = array_diff($this->noSlash, $tag);
return $this;
} | php | public function removeNoSlashTag($tag): Dom
{
if ( ! is_array($tag)) {
$tag = [$tag];
}
$this->noSlash = array_diff($this->noSlash, $tag);
return $this;
} | [
"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.
@param $tag
@return Dom
@chainable | [
"Removes",
"a",
"tag",
"from",
"the",
"list",
"of",
"no",
"-",
"slash",
"tags",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom.php#L334-L342 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom.php | Dom.parse | protected function parse(): void
{
// add the root node
$this->root = new HtmlNode('root');
$activeNode = $this->root;
while ( ! is_null($activeNode)) {
$str = $this->content->copyUntil('<');
if ($str == '') {
$info = $this->parseTag();
if ( ! $info['status']) {
// we are done here
$activeNode = null;
continue;
}
// check if it was a closing tag
if ($info['closing']) {
$foundOpeningTag = true;
$originalNode = $activeNode;
while ($activeNode->getTag()->name() != $info['tag']) {
$activeNode = $activeNode->getParent();
if (is_null($activeNode)) {
// we could not find opening tag
$activeNode = $originalNode;
$foundOpeningTag = false;
break;
}
}
if ($foundOpeningTag) {
$activeNode = $activeNode->getParent();
}
continue;
}
if ( ! isset($info['node'])) {
continue;
}
/** @var AbstractNode $node */
$node = $info['node'];
$activeNode->addChild($node);
// check if node is self closing
if ( ! $node->getTag()->isSelfClosing()) {
$activeNode = $node;
}
} else if ($this->options->whitespaceTextNode ||
trim($str) != ''
) {
// we found text we care about
$textNode = new TextNode($str, $this->options->removeDoubleSpace);
$activeNode->addChild($textNode);
}
}
} | php | protected function parse(): void
{
// add the root node
$this->root = new HtmlNode('root');
$activeNode = $this->root;
while ( ! is_null($activeNode)) {
$str = $this->content->copyUntil('<');
if ($str == '') {
$info = $this->parseTag();
if ( ! $info['status']) {
// we are done here
$activeNode = null;
continue;
}
// check if it was a closing tag
if ($info['closing']) {
$foundOpeningTag = true;
$originalNode = $activeNode;
while ($activeNode->getTag()->name() != $info['tag']) {
$activeNode = $activeNode->getParent();
if (is_null($activeNode)) {
// we could not find opening tag
$activeNode = $originalNode;
$foundOpeningTag = false;
break;
}
}
if ($foundOpeningTag) {
$activeNode = $activeNode->getParent();
}
continue;
}
if ( ! isset($info['node'])) {
continue;
}
/** @var AbstractNode $node */
$node = $info['node'];
$activeNode->addChild($node);
// check if node is self closing
if ( ! $node->getTag()->isSelfClosing()) {
$activeNode = $node;
}
} else if ($this->options->whitespaceTextNode ||
trim($str) != ''
) {
// we found text we care about
$textNode = new TextNode($str, $this->options->removeDoubleSpace);
$activeNode->addChild($textNode);
}
}
} | [
"protected",
"function",
"parse",
"(",
")",
":",
"void",
"{",
"// add the root node",
"$",
"this",
"->",
"root",
"=",
"new",
"HtmlNode",
"(",
"'root'",
")",
";",
"$",
"activeNode",
"=",
"$",
"this",
"->",
"root",
";",
"while",
"(",
"!",
"is_null",
"(",
"$",
"activeNode",
")",
")",
"{",
"$",
"str",
"=",
"$",
"this",
"->",
"content",
"->",
"copyUntil",
"(",
"'<'",
")",
";",
"if",
"(",
"$",
"str",
"==",
"''",
")",
"{",
"$",
"info",
"=",
"$",
"this",
"->",
"parseTag",
"(",
")",
";",
"if",
"(",
"!",
"$",
"info",
"[",
"'status'",
"]",
")",
"{",
"// we are done here",
"$",
"activeNode",
"=",
"null",
";",
"continue",
";",
"}",
"// check if it was a closing tag",
"if",
"(",
"$",
"info",
"[",
"'closing'",
"]",
")",
"{",
"$",
"foundOpeningTag",
"=",
"true",
";",
"$",
"originalNode",
"=",
"$",
"activeNode",
";",
"while",
"(",
"$",
"activeNode",
"->",
"getTag",
"(",
")",
"->",
"name",
"(",
")",
"!=",
"$",
"info",
"[",
"'tag'",
"]",
")",
"{",
"$",
"activeNode",
"=",
"$",
"activeNode",
"->",
"getParent",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"activeNode",
")",
")",
"{",
"// we could not find opening tag",
"$",
"activeNode",
"=",
"$",
"originalNode",
";",
"$",
"foundOpeningTag",
"=",
"false",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"foundOpeningTag",
")",
"{",
"$",
"activeNode",
"=",
"$",
"activeNode",
"->",
"getParent",
"(",
")",
";",
"}",
"continue",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"info",
"[",
"'node'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"/** @var AbstractNode $node */",
"$",
"node",
"=",
"$",
"info",
"[",
"'node'",
"]",
";",
"$",
"activeNode",
"->",
"addChild",
"(",
"$",
"node",
")",
";",
"// check if node is self closing",
"if",
"(",
"!",
"$",
"node",
"->",
"getTag",
"(",
")",
"->",
"isSelfClosing",
"(",
")",
")",
"{",
"$",
"activeNode",
"=",
"$",
"node",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"options",
"->",
"whitespaceTextNode",
"||",
"trim",
"(",
"$",
"str",
")",
"!=",
"''",
")",
"{",
"// we found text we care about",
"$",
"textNode",
"=",
"new",
"TextNode",
"(",
"$",
"str",
",",
"$",
"this",
"->",
"options",
"->",
"removeDoubleSpace",
")",
";",
"$",
"activeNode",
"->",
"addChild",
"(",
"$",
"textNode",
")",
";",
"}",
"}",
"}"
] | Attempts to parse the html in content. | [
"Attempts",
"to",
"parse",
"the",
"html",
"in",
"content",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom.php#L530-L584 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom.php | Dom.detectCharset | protected function detectCharset(): bool
{
// set the default
$encode = new Encode;
$encode->from($this->defaultCharset);
$encode->to($this->defaultCharset);
if ( ! is_null($this->options->enforceEncoding)) {
// they want to enforce the given encoding
$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)) {
// could not find meta tag
$this->root->propagateEncoding($encode);
return false;
}
$content = $meta->content;
if (empty($content)) {
// could not find 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;
}
// no charset found
$this->root->propagateEncoding($encode);
return false;
} | php | protected function detectCharset(): bool
{
// set the default
$encode = new Encode;
$encode->from($this->defaultCharset);
$encode->to($this->defaultCharset);
if ( ! is_null($this->options->enforceEncoding)) {
// they want to enforce the given encoding
$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)) {
// could not find meta tag
$this->root->propagateEncoding($encode);
return false;
}
$content = $meta->content;
if (empty($content)) {
// could not find 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;
}
// no charset found
$this->root->propagateEncoding($encode);
return false;
} | [
"protected",
"function",
"detectCharset",
"(",
")",
":",
"bool",
"{",
"// set the default",
"$",
"encode",
"=",
"new",
"Encode",
";",
"$",
"encode",
"->",
"from",
"(",
"$",
"this",
"->",
"defaultCharset",
")",
";",
"$",
"encode",
"->",
"to",
"(",
"$",
"this",
"->",
"defaultCharset",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"options",
"->",
"enforceEncoding",
")",
")",
"{",
"// they want to enforce the given encoding",
"$",
"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",
")",
")",
"{",
"// could not find meta tag",
"$",
"this",
"->",
"root",
"->",
"propagateEncoding",
"(",
"$",
"encode",
")",
";",
"return",
"false",
";",
"}",
"$",
"content",
"=",
"$",
"meta",
"->",
"content",
";",
"if",
"(",
"empty",
"(",
"$",
"content",
")",
")",
"{",
"// could not find 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",
";",
"}",
"// no charset found",
"$",
"this",
"->",
"root",
"->",
"propagateEncoding",
"(",
"$",
"encode",
")",
";",
"return",
"false",
";",
"}"
] | Attempts to detect the charset that the html was sent in.
@return bool | [
"Attempts",
"to",
"detect",
"the",
"charset",
"that",
"the",
"html",
"was",
"sent",
"in",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom.php#L740-L781 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Selector/Selector.php | Selector.find | 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);
// clear the options
$options = [];
}
// this is the final set of nodes
foreach ($nodes as $result) {
$results[] = $result;
}
}
return $results;
} | php | 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);
// clear the options
$options = [];
}
// this is the final set of nodes
foreach ($nodes as $result) {
$results[] = $result;
}
}
return $results;
} | [
"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",
")",
";",
"// clear the options",
"$",
"options",
"=",
"[",
"]",
";",
"}",
"// this is the final set of nodes",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"result",
")",
"{",
"$",
"results",
"[",
"]",
"=",
"$",
"result",
";",
"}",
"}",
"return",
"$",
"results",
";",
"}"
] | Attempts to find the selectors starting from the given
node object.
@param AbstractNode $node
@return Collection | [
"Attempts",
"to",
"find",
"the",
"selectors",
"starting",
"from",
"the",
"given",
"node",
"object",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Selector/Selector.php#L50-L77 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Selector/Selector.php | Selector.flattenOptions | protected function flattenOptions(array $optionsArray)
{
$options = [];
foreach ($optionsArray as $optionArray) {
foreach ($optionArray as $key => $option) {
$options[$key] = $option;
}
}
return $options;
} | php | protected function flattenOptions(array $optionsArray)
{
$options = [];
foreach ($optionsArray as $optionArray) {
foreach ($optionArray as $key => $option) {
$options[$key] = $option;
}
}
return $options;
} | [
"protected",
"function",
"flattenOptions",
"(",
"array",
"$",
"optionsArray",
")",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"optionsArray",
"as",
"$",
"optionArray",
")",
"{",
"foreach",
"(",
"$",
"optionArray",
"as",
"$",
"key",
"=>",
"$",
"option",
")",
"{",
"$",
"options",
"[",
"$",
"key",
"]",
"=",
"$",
"option",
";",
"}",
"}",
"return",
"$",
"options",
";",
"}"
] | Flattens the option array.
@param array $optionsArray
@return array | [
"Flattens",
"the",
"option",
"array",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Selector/Selector.php#L232-L242 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Selector/Selector.php | Selector.getNextChild | protected function getNextChild(AbstractNode $node, AbstractNode $currentChild)
{
try {
// get next child
$child = $node->nextChild($currentChild->id());
} catch (ChildNotFoundException $e) {
// no more children
$child = null;
}
return $child;
} | php | protected function getNextChild(AbstractNode $node, AbstractNode $currentChild)
{
try {
// get next child
$child = $node->nextChild($currentChild->id());
} catch (ChildNotFoundException $e) {
// no more children
$child = null;
}
return $child;
} | [
"protected",
"function",
"getNextChild",
"(",
"AbstractNode",
"$",
"node",
",",
"AbstractNode",
"$",
"currentChild",
")",
"{",
"try",
"{",
"// get next child",
"$",
"child",
"=",
"$",
"node",
"->",
"nextChild",
"(",
"$",
"currentChild",
"->",
"id",
"(",
")",
")",
";",
"}",
"catch",
"(",
"ChildNotFoundException",
"$",
"e",
")",
"{",
"// no more children",
"$",
"child",
"=",
"null",
";",
"}",
"return",
"$",
"child",
";",
"}"
] | Returns the next child or null if no more children.
@param AbstractNode $node
@param AbstractNode $currentChild
@return AbstractNode|null | [
"Returns",
"the",
"next",
"child",
"or",
"null",
"if",
"no",
"more",
"children",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Selector/Selector.php#L251-L262 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Selector/Selector.php | Selector.checkTag | protected function checkTag(array $rule, AbstractNode $node): bool
{
if ( ! empty($rule['tag']) && $rule['tag'] != $node->getTag()->name() &&
$rule['tag'] != '*'
) {
return false;
}
return true;
} | php | protected function checkTag(array $rule, AbstractNode $node): bool
{
if ( ! empty($rule['tag']) && $rule['tag'] != $node->getTag()->name() &&
$rule['tag'] != '*'
) {
return false;
}
return true;
} | [
"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.
@param array $rule
@param AbstractNode $node
@return bool | [
"Checks",
"tag",
"condition",
"from",
"rules",
"against",
"node",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Selector/Selector.php#L271-L280 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Selector/Selector.php | Selector.checkKey | 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;
} | php | 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;
} | [
"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.
@param array $rule
@param AbstractNode $node
@return bool | [
"Checks",
"key",
"condition",
"from",
"rules",
"against",
"node",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Selector/Selector.php#L289-L302 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Selector/Selector.php | Selector.checkComparison | public function checkComparison(array $rule, AbstractNode $node): bool
{
if ($rule['key'] == 'plaintext') {
// plaintext search
$nodeValue = $node->text();
} else {
// normal search
$nodeValue = $node->getAttribute($rule['key']);
}
$check = $this->match($rule['operator'], $rule['value'], $nodeValue);
// handle multiple classes
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;
} | php | public function checkComparison(array $rule, AbstractNode $node): bool
{
if ($rule['key'] == 'plaintext') {
// plaintext search
$nodeValue = $node->text();
} else {
// normal search
$nodeValue = $node->getAttribute($rule['key']);
}
$check = $this->match($rule['operator'], $rule['value'], $nodeValue);
// handle multiple classes
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;
} | [
"public",
"function",
"checkComparison",
"(",
"array",
"$",
"rule",
",",
"AbstractNode",
"$",
"node",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"rule",
"[",
"'key'",
"]",
"==",
"'plaintext'",
")",
"{",
"// plaintext search",
"$",
"nodeValue",
"=",
"$",
"node",
"->",
"text",
"(",
")",
";",
"}",
"else",
"{",
"// normal search",
"$",
"nodeValue",
"=",
"$",
"node",
"->",
"getAttribute",
"(",
"$",
"rule",
"[",
"'key'",
"]",
")",
";",
"}",
"$",
"check",
"=",
"$",
"this",
"->",
"match",
"(",
"$",
"rule",
"[",
"'operator'",
"]",
",",
"$",
"rule",
"[",
"'value'",
"]",
",",
"$",
"nodeValue",
")",
";",
"// handle multiple classes",
"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.
@param array $rule
@param AbstractNode $node
@return bool | [
"Checks",
"comparison",
"condition",
"from",
"rules",
"against",
"node",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Selector/Selector.php#L311-L337 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Options.php | Options.setOptions | public function setOptions(array $options): Options
{
foreach ($options as $key => $option) {
$this->options[$key] = $option;
}
return $this;
} | php | public function setOptions(array $options): Options
{
foreach ($options as $key => $option) {
$this->options[$key] = $option;
}
return $this;
} | [
"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.
@param array $options
@return Options
@chainable | [
"Sets",
"a",
"new",
"options",
"param",
"to",
"override",
"the",
"current",
"option",
"array",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Options.php#L70-L77 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom/Collection.php | Collection.offsetGet | public function offsetGet($offset)
{
return isset($this->collection[$offset]) ? $this->collection[$offset] : null;
} | php | public function offsetGet($offset)
{
return isset($this->collection[$offset]) ? $this->collection[$offset] : null;
} | [
"public",
"function",
"offsetGet",
"(",
"$",
"offset",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"collection",
"[",
"$",
"offset",
"]",
")",
"?",
"$",
"this",
"->",
"collection",
"[",
"$",
"offset",
"]",
":",
"null",
";",
"}"
] | Gets a node at the given offset, or null
@param mixed $offset
@return mixed | [
"Gets",
"a",
"node",
"at",
"the",
"given",
"offset",
"or",
"null"
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom/Collection.php#L141-L144 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom/Collection.php | Collection.each | public function each(callable $callback)
{
foreach ($this->collection as $key => $value) {
$callback($value, $key);
}
} | php | public function each(callable $callback)
{
foreach ($this->collection as $key => $value) {
$callback($value, $key);
}
} | [
"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.
@param callable $callback | [
"Similar",
"to",
"jQuery",
"each",
"method",
".",
"Calls",
"the",
"callback",
"with",
"each",
"Node",
"in",
"this",
"collection",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom/Collection.php#L162-L167 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Selector/Parser.php | Parser.parseSelectorString | public function parseSelectorString(string $selector): array
{
$selectors = [];
$matches = [];
preg_match_all($this->pattern, trim($selector).' ', $matches, PREG_SET_ORDER);
// skip tbody
$result = [];
foreach ($matches as $match) {
// default values
$tag = strtolower(trim($match[1]));
$operator = '=';
$key = null;
$value = null;
$noKey = false;
$alterNext = false;
// check for elements that alter the behavior of the next element
if ($tag == '>') {
$alterNext = true;
}
// check for id selector
if ( ! empty($match[2])) {
$key = 'id';
$value = $match[2];
}
// check for class selector
if ( ! empty($match[3])) {
$key = 'class';
$value = $match[3];
}
// and final attribute selector
if ( ! empty($match[4])) {
$key = strtolower($match[4]);
}
if ( ! empty($match[5])) {
$operator = $match[5];
}
if ( ! empty($match[6])) {
$value = $match[6];
}
// check for elements that do not have a specified attribute
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 = [];
}
}
// save last results
if (count($result) > 0) {
$selectors[] = $result;
}
return $selectors;
} | php | public function parseSelectorString(string $selector): array
{
$selectors = [];
$matches = [];
preg_match_all($this->pattern, trim($selector).' ', $matches, PREG_SET_ORDER);
// skip tbody
$result = [];
foreach ($matches as $match) {
// default values
$tag = strtolower(trim($match[1]));
$operator = '=';
$key = null;
$value = null;
$noKey = false;
$alterNext = false;
// check for elements that alter the behavior of the next element
if ($tag == '>') {
$alterNext = true;
}
// check for id selector
if ( ! empty($match[2])) {
$key = 'id';
$value = $match[2];
}
// check for class selector
if ( ! empty($match[3])) {
$key = 'class';
$value = $match[3];
}
// and final attribute selector
if ( ! empty($match[4])) {
$key = strtolower($match[4]);
}
if ( ! empty($match[5])) {
$operator = $match[5];
}
if ( ! empty($match[6])) {
$value = $match[6];
}
// check for elements that do not have a specified attribute
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 = [];
}
}
// save last results
if (count($result) > 0) {
$selectors[] = $result;
}
return $selectors;
} | [
"public",
"function",
"parseSelectorString",
"(",
"string",
"$",
"selector",
")",
":",
"array",
"{",
"$",
"selectors",
"=",
"[",
"]",
";",
"$",
"matches",
"=",
"[",
"]",
";",
"preg_match_all",
"(",
"$",
"this",
"->",
"pattern",
",",
"trim",
"(",
"$",
"selector",
")",
".",
"' '",
",",
"$",
"matches",
",",
"PREG_SET_ORDER",
")",
";",
"// skip tbody",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"match",
")",
"{",
"// default values",
"$",
"tag",
"=",
"strtolower",
"(",
"trim",
"(",
"$",
"match",
"[",
"1",
"]",
")",
")",
";",
"$",
"operator",
"=",
"'='",
";",
"$",
"key",
"=",
"null",
";",
"$",
"value",
"=",
"null",
";",
"$",
"noKey",
"=",
"false",
";",
"$",
"alterNext",
"=",
"false",
";",
"// check for elements that alter the behavior of the next element",
"if",
"(",
"$",
"tag",
"==",
"'>'",
")",
"{",
"$",
"alterNext",
"=",
"true",
";",
"}",
"// check for id selector",
"if",
"(",
"!",
"empty",
"(",
"$",
"match",
"[",
"2",
"]",
")",
")",
"{",
"$",
"key",
"=",
"'id'",
";",
"$",
"value",
"=",
"$",
"match",
"[",
"2",
"]",
";",
"}",
"// check for class selector",
"if",
"(",
"!",
"empty",
"(",
"$",
"match",
"[",
"3",
"]",
")",
")",
"{",
"$",
"key",
"=",
"'class'",
";",
"$",
"value",
"=",
"$",
"match",
"[",
"3",
"]",
";",
"}",
"// and final attribute selector",
"if",
"(",
"!",
"empty",
"(",
"$",
"match",
"[",
"4",
"]",
")",
")",
"{",
"$",
"key",
"=",
"strtolower",
"(",
"$",
"match",
"[",
"4",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"match",
"[",
"5",
"]",
")",
")",
"{",
"$",
"operator",
"=",
"$",
"match",
"[",
"5",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"match",
"[",
"6",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"match",
"[",
"6",
"]",
";",
"}",
"// check for elements that do not have a specified attribute",
"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",
"=",
"[",
"]",
";",
"}",
"}",
"// save last results",
"if",
"(",
"count",
"(",
"$",
"result",
")",
">",
"0",
")",
"{",
"$",
"selectors",
"[",
"]",
"=",
"$",
"result",
";",
"}",
"return",
"$",
"selectors",
";",
"}"
] | Parses the selector string
@param string $selector | [
"Parses",
"the",
"selector",
"string"
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Selector/Parser.php#L24-L96 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom/AbstractNode.php | AbstractNode.propagateEncoding | public function propagateEncoding(Encode $encode)
{
$this->encode = $encode;
$this->tag->setEncoding($encode);
} | php | public function propagateEncoding(Encode $encode)
{
$this->encode = $encode;
$this->tag->setEncoding($encode);
} | [
"public",
"function",
"propagateEncoding",
"(",
"Encode",
"$",
"encode",
")",
"{",
"$",
"this",
"->",
"encode",
"=",
"$",
"encode",
";",
"$",
"this",
"->",
"tag",
"->",
"setEncoding",
"(",
"$",
"encode",
")",
";",
"}"
] | Sets the encoding class to this node.
@param Encode $encode
@return void | [
"Sets",
"the",
"encoding",
"class",
"to",
"this",
"node",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom/AbstractNode.php#L205-L209 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom/AbstractNode.php | AbstractNode.isAncestor | public function isAncestor(int $id): Bool
{
if ( ! is_null($this->getAncestor($id))) {
return true;
}
return false;
} | php | public function isAncestor(int $id): Bool
{
if ( ! is_null($this->getAncestor($id))) {
return true;
}
return false;
} | [
"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.
@param int $id
@return bool | [
"Checks",
"if",
"the",
"given",
"node",
"id",
"is",
"an",
"ancestor",
"of",
"the",
"current",
"node",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom/AbstractNode.php#L218-L225 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom/AbstractNode.php | AbstractNode.hasNextSibling | public function hasNextSibling(): bool
{
try
{
$this->nextSibling();
// sibling found, return true;
return true;
}
catch (ParentNotFoundException $e)
{
// no parent, no next sibling
return false;
}
catch (ChildNotFoundException $e)
{
// no sibling found
return false;
}
} | php | public function hasNextSibling(): bool
{
try
{
$this->nextSibling();
// sibling found, return true;
return true;
}
catch (ParentNotFoundException $e)
{
// no parent, no next sibling
return false;
}
catch (ChildNotFoundException $e)
{
// no sibling found
return false;
}
} | [
"public",
"function",
"hasNextSibling",
"(",
")",
":",
"bool",
"{",
"try",
"{",
"$",
"this",
"->",
"nextSibling",
"(",
")",
";",
"// sibling found, return true;",
"return",
"true",
";",
"}",
"catch",
"(",
"ParentNotFoundException",
"$",
"e",
")",
"{",
"// no parent, no next sibling",
"return",
"false",
";",
"}",
"catch",
"(",
"ChildNotFoundException",
"$",
"e",
")",
"{",
"// no sibling found",
"return",
"false",
";",
"}",
"}"
] | Checks if the current node has a next sibling.
@return bool | [
"Checks",
"if",
"the",
"current",
"node",
"has",
"a",
"next",
"sibling",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom/AbstractNode.php#L251-L270 | train |
paquettg/php-html-parser | src/PHPHtmlParser/Dom/AbstractNode.php | AbstractNode.setAttribute | public function setAttribute(string $key, $value): AbstractNode
{
$this->tag->setAttribute($key, $value);
//clear any cache
$this->clear();
return $this;
} | php | public function setAttribute(string $key, $value): AbstractNode
{
$this->tag->setAttribute($key, $value);
//clear any cache
$this->clear();
return $this;
} | [
"public",
"function",
"setAttribute",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
":",
"AbstractNode",
"{",
"$",
"this",
"->",
"tag",
"->",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"//clear any cache",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | A wrapper method that simply calls the setAttribute method
on the tag of this node.
@param string $key
@param string|null $value
@return AbstractNode
@chainable | [
"A",
"wrapper",
"method",
"that",
"simply",
"calls",
"the",
"setAttribute",
"method",
"on",
"the",
"tag",
"of",
"this",
"node",
"."
] | 77e4a44b0916690b4300fe9abf98fd05bbba48f0 | https://github.com/paquettg/php-html-parser/blob/77e4a44b0916690b4300fe9abf98fd05bbba48f0/src/PHPHtmlParser/Dom/AbstractNode.php#L366-L374 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.