本文整理汇总了PHP中wpcf_ensarr函数的典型用法代码示例。如果您正苦于以下问题:PHP wpcf_ensarr函数的具体用法?PHP wpcf_ensarr怎么用?PHP wpcf_ensarr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wpcf_ensarr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sanitize_single_option
/**
* Sanitize single checkboxes option definition.
*
* @param array $option
* @return array Sanitized option.
* @since 2.1
*/
private function sanitize_single_option($option)
{
$option = $this->sanitize_element_isset(wpcf_ensarr($option), 'value');
$option = $this->sanitize_element_isset($option, 'title', $option['value']);
$option = $this->sanitize_element_isset($option, 'display_value', $option['value']);
return $option;
}
示例2: sanitize_single_option
/**
* Sanitize single checkboxes option definition.
*
* @param array $option
* @return array Sanitized option.
* @since 2.1
*/
private function sanitize_single_option($option)
{
$option = $this->sanitize_element_isset(wpcf_ensarr($option), 'set_value');
$option = $this->sanitize_element_isset($option, 'title', $option['set_value']);
$option = $this->sanitize_element_isset($option, 'display', 'db', array('db', 'value'));
$option = $this->sanitize_element_isset($option, 'display_value_selected');
$option = $this->sanitize_element_isset($option, 'display_value_not_selected');
return $option;
}
示例3: get_associated_taxonomies
/**
* Get taxonomies that are associated with this field group.
*
* @return string[] Taxonomy slugs. Empty array means that this group should be displayed with all taxonomies.
*/
public function get_associated_taxonomies()
{
$postmeta = get_post_meta($this->get_id(), self::POSTMETA_ASSOCIATED_TAXONOMY, false);
$postmeta = array_filter($postmeta, function ($value) {
$value = trim($value);
return !empty($value);
});
return wpcf_ensarr($postmeta);
}
示例4: sanitize_numeric_validation
/**
* Add the 'number' validation if it was not already there, and activate it.
*
* @param array $definition_array
* @return array
* @since 2.0
*/
protected function sanitize_numeric_validation($definition_array)
{
// Get the original setting or a default one.
$validation_setting = wpcf_ensarr(wpcf_getnest($definition_array, array('data', 'validate', 'number')), array('active' => true, 'message' => __('Please enter numeric data', 'wpcf')));
// Force the activation of this validation.
$validation_setting['active'] = true;
// Store the setting.
$definition_array['data']['validate']['number'] = $validation_setting;
return $definition_array;
}
示例5: get_possible_conversions
/**
* @param Types_Field_Type_Definition $type
* @return Types_Field_Type_Definition[]
*/
public function get_possible_conversions($type)
{
if (!$type instanceof Types_Field_Type_Definition) {
throw new InvalidArgumentException('Not a field type definition');
}
$matrix = $this->get_conversion_matrix();
$allowed_slugs = wpcf_ensarr(wpcf_getarr($matrix, $type->get_slug()));
$allowed_types = Types_Field_Type_Definition_Factory::get_instance()->load_multiple_definitions($allowed_slugs);
return $allowed_types;
}
示例6: get_associated_taxonomies
/**
* Get taxonomies that are associated with this field group.
*
* @return string[] Taxonomy slugs. Empty array means that this group should be displayed with all taxonomies.
*/
public function get_associated_taxonomies()
{
$postmeta = get_post_meta($this->get_id(), self::POSTMETA_ASSOCIATED_TAXONOMY, false);
// Survive empty or whitespace taxonomy slugs (skip them). They are invalid values but
// if we have only them, we need to return an empty array to keep the group displayed everywhere.
foreach ($postmeta as $index => $taxonomy_slug) {
$taxonomy_slug = trim($taxonomy_slug);
if (empty($taxonomy_slug)) {
unset($postmeta[$index]);
}
}
return wpcf_ensarr($postmeta);
}
示例7: read_field_values
/**
* Read the field values from $_POST.
*
* @return array Values in the "intermediate" format (see WPCF_Field_DataMapper_Abstract). For non-repetitive values,
* it will be an array with a single item.
*/
private function read_field_values()
{
if (null == $this->field_values) {
$definition = $this->field->get_definition();
$form_data = wpcf_ensarr(wpcf_getpost('wpcf'));
$values = wpcf_getarr($form_data, $definition->get_slug());
// Handle single fields.
if (!$definition->get_is_repetitive()) {
$values = array($values);
}
// Map POST values to intermediate format.
$this->field_values = array();
$data_mapper = $definition->get_data_mapper();
foreach ($values as $value) {
$this->field_values[] = $data_mapper->post_to_intermediate($value, $form_data);
}
}
return wpcf_ensarr($this->field_values);
}
示例8: get_field_options
/**
* Retrieve an array of option definitions.
*
* Allowed only for the checkboxes, radio and select field types.
*
* @throws RuntimeException when the field type is invalid
* @throws InvalidArgumentException when option definitions are corrupted
* @return WPCF_Field_Option_Checkboxes[] An option_id => option_data array.
* @since 1.9
*/
public function get_field_options()
{
$this->check_allowed_types(array(Types_Field_Type_Definition_Factory::CHECKBOXES, Types_Field_Type_Definition_Factory::RADIO, Types_Field_Type_Definition_Factory::SELECT));
$options_definition = wpcf_ensarr(wpcf_getnest($this->definition_array, array('data', 'options')));
$results = array();
// The 'default' key can be present, we have to remove it so it's not handled as another option.
$has_default = array_key_exists('default', $options_definition);
$default = wpcf_getarr($options_definition, 'default', 'no-default');
if ($has_default) {
unset($options_definition['default']);
}
foreach ($options_definition as $option_id => $option_config) {
try {
switch ($this->get_type()->get_slug()) {
case Types_Field_Type_Definition_Factory::RADIO:
$option = new WPCF_Field_Option_Radio($option_id, $option_config, $default, $this);
break;
case Types_Field_Type_Definition_Factory::SELECT:
$option = new WPCF_Field_Option_Select($option_id, $option_config, $default, $this);
break;
case Types_Field_Type_Definition_Factory::CHECKBOXES:
$option = new WPCF_Field_Option_Checkboxes($option_id, $option_config, $default);
break;
default:
throw new InvalidArgumentException('Invalid field type');
}
$results[$option_id] = $option;
} catch (Exception $e) {
// Corrupted data, can't do anything but skip the option.
}
}
return $results;
}
示例9: wpcf_fix_exported_taxonomy_assignment_to_cpt
/**
* Filter the data to be exported for custom taxonomies.
*
* Ensure the settings of post types associated with the taxonomy is exported correctly, even with support of legacy
* settings.
*
* @param array $taxonomy_data
* @return array Modified taxonomy data.
* @since unknown
*/
function wpcf_fix_exported_taxonomy_assignment_to_cpt($taxonomy_data = array())
{
$setting_name_prefix = '__types_cpt_supports_';
$post_type_support_settings = array();
// Associated CPTs slugs are stored as XML keys, so they can not start with a number.
// We force a prefix on all of them on export, and restore them on import.
$supported_post_types = wpcf_ensarr(wpcf_getarr($taxonomy_data, 'supports'));
foreach ($supported_post_types as $post_type_slug => $is_supported) {
$setting_name = $setting_name_prefix . $post_type_slug;
$post_type_support_settings[$setting_name] = $is_supported ? 1 : 0;
}
// Here, we will also process the legacy "object_type" setting, containing supported post type slugs as array items,
// in the samve way.
$legacy_supported_post_type_array = wpcf_ensarr(wpcf_getarr($taxonomy_data, 'object_type'));
foreach ($legacy_supported_post_type_array as $post_type_slug) {
$setting_name = $setting_name_prefix . $post_type_slug;
$post_type_support_settings[$setting_name] = 1;
}
// Now we need to remove this legacy setting to prevent producing invalid XML.
unset($taxonomy_data['object_type']);
$taxonomy_data['supports'] = $post_type_support_settings;
return $taxonomy_data;
}
示例10: change_assignment_to_groups
/**
* Change which groups is a field definition associated with.
*
* AJAX callback helper only, do not use elsewhere.
*
* @param string $field_slug Field definition slug.
* @param string $domain Field domain
* @param string[][] $groups Action-specific data passed through AJAX. Array containing a single key 'group_slugs',
* containing an array of field group slugs.
*
* @return WP_Error|WPCF_Field_Definition The updated field definition on success or an error object.
* @since 2.0
*/
public static function change_assignment_to_groups($field_slug, $domain, $groups)
{
$factory = Types_Field_Utils::get_definition_factory_by_domain($domain);
$definition = $factory->load_field_definition($field_slug);
if (null == $definition) {
return new WP_Error(42, sprintf(__('Field definition for field "%s" not found in options.', 'wpcf'), sanitize_text_field($field_slug)));
}
$new_groups = wpcf_ensarr(wpcf_getarr($groups, 'group_slugs'));
$associated_groups = $definition->get_associated_groups();
$is_success = true;
foreach ($associated_groups as $group) {
if (!in_array($group->get_slug(), $new_groups)) {
$is_success = $is_success && $group->remove_field_definition($definition);
}
}
$group_factory = $factory->get_group_factory();
foreach ($new_groups as $new_group_slug) {
$new_group = $group_factory->load_field_group($new_group_slug);
if (null != $new_group) {
$is_success = $is_success && $new_group->add_field_definition($definition);
} else {
$is_success = false;
}
}
if ($is_success) {
return $definition;
} else {
return new WP_Error();
}
}
示例11: load_multiple_definitions
/**
* Get field type definitions from an array of slugs.
*
* If a definition cannot be loaded for a given slug, the slug is skipped without reporting an error in any other way.
*
* @param string[] $field_type_slugs
* @return Types_Field_Type_Definition[]
* @since 2.0
*/
public function load_multiple_definitions($field_type_slugs)
{
$results = array();
$field_type_slugs = wpcf_ensarr($field_type_slugs);
foreach ($field_type_slugs as $field_type_slug) {
$type_definition = $this->load_field_type_definition($field_type_slug);
if (null != $type_definition) {
$results[$field_type_slug] = $type_definition;
}
}
return $results;
}
示例12: get_associated_taxonomies
/**
* Get taxonomies that are associated with this field group.
*
* @return string[] Taxonomy slugs. Empty array means that this group should be displayed with all taxonomies.
*/
public function get_associated_taxonomies()
{
$postmeta = get_post_meta($this->get_id(), self::POSTMETA_ASSOCIATED_TAXONOMY, false);
return wpcf_ensarr($postmeta);
}
示例13: sanitize_field_definition_array
/**
* Make sure that the field definition array contains all necessary information.
*
* Note: This is a WIP, currently it sanitizes only very specific cases. It should be extended in the future.
*
* @link https://git.onthegosystems.com/toolset/types/wikis/database-layer/field-definition-arrays
* @param array $definition_array Field definition array
* @return array Field definition array that is safe to be used even with legacy code.
* @since 2.0
*/
public final function sanitize_field_definition_array($definition_array)
{
/**
* types_pre_sanitize_field_definition_array
*
* Allow for additional field definition array sanitization before the standard one runs.
*
* @param mixed $definition_array
* @return array
* @since 2.1
*/
$definition_array = wpcf_ensarr(apply_filters('types_pre_sanitize_field_definition_array', $definition_array));
$definition_array = $this->sanitize_field_definition_array_generic($definition_array);
$definition_array = $this->sanitize_numeric_validation($definition_array);
$definition_array = $this->sanitize_field_definition_array_type_specific($definition_array);
/**
* types_post_sanitize_field_definition_array
*
* Allow for additional field definition array sanitization after the standard one runs.
*
* @param array $definition_array
* @return array
* @since 2.1
*/
$definition_array = wpcf_ensarr(apply_filters('types_post_sanitize_field_definition_array', $definition_array));
return $definition_array;
}
示例14: sanitize_field_definition_array
/**
* Make sure that the field definition array contains all necessary information.
*
* Note: This is a WIP, currently it sanitizes only very specific cases. It should be extended in the future.
*
* Expected definition array structure common to all fields:
*
* - slug: string
* - data: array
* - validate: array
*
* @param array $definition_array Field definition array
* @return array Field definition array that is safe to be used even with legacy code.
* @since 2.0
*/
public function sanitize_field_definition_array($definition_array)
{
$definition_array['data'] = wpcf_ensarr(wpcf_getarr($definition_array, 'data'));
$definition_array['data']['validate'] = wpcf_ensarr(wpcf_getarr($definition_array['data'], 'validate'));
$definition_array = $this->sanitize_numeric_validation($definition_array);
return $definition_array;
}
示例15: get_field_options
/**
* @return array An option_id => option_data array.
*/
public function get_field_options()
{
return wpcf_ensarr(wpcf_getnest($this->definition_array, array('data', 'options')));
}