本文整理汇总了PHP中wpcf_getarr函数的典型用法代码示例。如果您正苦于以下问题:PHP wpcf_getarr函数的具体用法?PHP wpcf_getarr怎么用?PHP wpcf_getarr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wpcf_getarr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hack_around_legacy_import_routine
private function hack_around_legacy_import_routine($import_data, $import_args = null)
{
add_filter('wpcf_admin_message_store', '__return_false');
$_POST['overwrite-settings'] = isset($import_args['overwrite-settings']) ? (bool) $import_args['overwrite-settings'] : false;
$_POST['overwrite-groups'] = isset($import_args['overwrite-groups']) && 1 == $import_args['overwrite-groups'] ? 1 : 0;
$_POST['overwrite-fields'] = isset($import_args['overwrite-fields']) && 1 == $import_args['overwrite-fields'] ? 1 : 0;
$_POST['overwrite-types'] = isset($import_args['overwrite-types']) && 1 == $import_args['overwrite-types'] ? 1 : 0;
$_POST['overwrite-tax'] = isset($import_args['overwrite-tax']) && 1 == $import_args['overwrite-tax'] ? 1 : 0;
$_POST['post_relationship'] = isset($import_args['post_relationship']) ? (bool) $import_args['post_relationship'] : false;
$_POST['delete-groups'] = isset($import_args['delete-groups']) ? (bool) $import_args['delete-groups'] : false;
$_POST['delete-fields'] = isset($import_args['delete-fields']) ? (bool) $import_args['delete-fields'] : false;
$_POST['delete-types'] = isset($import_args['delete-types']) ? (bool) $import_args['delete-types'] : false;
$_POST['delete-tax'] = isset($import_args['delete-tax']) ? (bool) $import_args['delete-tax'] : false;
/**
* This can be emtpy string '' or 'wpvdemo', but this second option has a serious bug with xml parsing/looping
*/
$context = isset($import_args['context']) ? $import_args['context'] : '';
// Not sure if this is needed
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
require_once WPCF_EMBEDDED_INC_ABSPATH . '/import-export.php';
// Prepare legacy arguments for Types_Data_Installer
$legacy_args = array();
if (isset($import_args['overwrite'])) {
$legacy_args['force_import_post_name'] = wpcf_getarr($import_args, 'overwrite', array());
}
if (isset($import_args['skip'])) {
$legacy_args['force_skip_post_name'] = wpcf_getarr($import_args, 'skip', array());
}
if (isset($import_args['duplicate'])) {
$legacy_args['force_duplicate_post_name'] = wpcf_getarr($import_args, 'duplicate', array());
}
$result = wpcf_admin_import_data($import_data, false, $context, $legacy_args);
return true;
}
示例2: render_single
/**
* @param mixed $value Single field value in the intermediate format (see data mappers for details)
*
* @return string Rendered HTML
*/
protected function render_single($value)
{
// Simply get the Skype name.
$skype_name = wpcf_getarr($value, 'skypename');
$skype_name = is_string($skype_name) ? $skype_name : '';
return sanitize_text_field($skype_name);
}
示例3: 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;
}
示例4: get_link_label
/**
* @param string[] $url_components Result of parse_url().
* @return string Label of the resulting link.
* @since 1.9.1
*/
protected function get_link_label($url_components)
{
// Build link label only from host, path and query.
$url_query = wpcf_getarr($url_components, 'query');
$url_query = empty($url_query) ? '' : '?' . $url_query;
$url_path = wpcf_getarr($url_components, 'path');
if (empty($url_query)) {
// Omit last slash when it would be the last label character
$url_path = substr($url_path, 0, strlen($url_path) - 1);
}
$label = sprintf('%s%s%s', wpcf_getarr($url_components, 'host'), $url_path, $url_query);
return $label;
}
示例5: __construct
/**
* WPCF_Field_Type_Definition constructor.
*
* @param string $field_type_slug Field type slug.
* @param array $args Additional array of arguments which should contain at least 'display_name' (or 'title')
* and 'description' elements, but omitting them is not critical.
*/
public function __construct($field_type_slug, $args)
{
if (sanitize_title($field_type_slug) != $field_type_slug) {
throw new InvalidArgumentException('Invalid field type slug.');
}
if (!is_array($args)) {
throw new InvalidArgumentException('Wrong arguments provided.');
}
$this->field_type_slug = $field_type_slug;
// Try to fall back to legacy "title", and if even that fails, use id instead.
$this->display_name = sanitize_text_field(wpcf_getarr($args, 'display_name', wpcf_getarr($args, 'title', $field_type_slug)));
$this->description = wpcf_getarr($args, 'description', '');
$this->args = $args;
}
示例6: get_display_value
/**
* Determine value to be displayed for this option.
*
* @param bool $is_checked For which value should the output be rendered.
* @return string Display value depending on option definition and field display mode
* @since 1.9.1
*/
public function get_display_value($is_checked = true)
{
$field_definition_array = $this->field_definition->get_definition_array();
$display_mode = wpcf_getnest($field_definition_array, array('data', 'display'), 'db');
$display_mode = 'value' == $display_mode ? 'value' : 'db';
if ('db' == $display_mode) {
return $is_checked ? $this->get_value_to_store() : '';
} else {
if ($is_checked) {
return wpcf_getarr($this->config, 'display_value');
} else {
return '';
}
}
}
示例7: sanitize_field_definition_array_type_specific
/**
* @inheritdoc
*
* @param array $definition_array
* @return array
* @since 2.1
*/
protected function sanitize_field_definition_array_type_specific($definition_array)
{
$definition_array['type'] = Types_Field_Type_Definition_Factory::SELECT;
$options = wpcf_ensarr(wpcf_getnest($definition_array, array('data', 'options')));
foreach ($options as $key => $option) {
if ('default' == $key) {
continue;
}
$options[$key] = $this->sanitize_single_option($option);
}
$default_option = wpcf_getarr($options, 'default');
if (!is_string($default_option) || !array_key_exists($default_option, $options)) {
$default_option = 'no-default';
}
$options['default'] = $default_option;
$definition_array['data']['options'] = $options;
return $definition_array;
}
示例8: 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);
}
示例9: load_field_type_definition
/**
* Load a field type definition.
*
* @param string $field_type_slug Slug of the field type. If the function fails to find the field type and the slug
* starts with a "wpcf-" prefix, it attempts to remove it and search again. This way, passing a field type ID,
* which usually has this form, is also supported.
* @return null|WPCF_Field_Type_Definition Field type definition or null if it can't be loaded.
*/
public function load_field_type_definition($field_type_slug)
{
if (!is_string($field_type_slug)) {
return null;
}
// Check if we can use cached version.
if (!in_array($field_type_slug, $this->field_type_definitions)) {
// now it gets hacky
$field_types = $this->get_legacy_field_types();
if (!in_array($field_type_slug, array_keys($field_types))) {
// Field slug not recognized. Maybe we got a field identifier instead. Check if we can remove
// the wpcf- prefix and try again.
$prefix = 'wpcf-';
if (substr($field_type_slug, 0, strlen($prefix)) == $prefix) {
$field_type_slug = substr($field_type_slug, strlen($prefix));
if (!in_array($field_type_slug, $field_types)) {
// Removing prefix didn't help
return null;
}
} else {
// There was no prefix to remove.
return null;
}
}
// Not using getFieldTypeData() directly to avoid unnecessary getFieldsTypes() and filter applying.
$field_type_configuration_path = $field_types[$field_type_slug];
$field_type_configuration = WPCF_Fields::getFieldTypeConfig($field_type_configuration_path);
$field_type_id = wpcf_getarr($field_type_configuration, 'id', null);
if (null == $field_type_id) {
return null;
}
try {
$field_type_definition = new WPCF_Field_Type_Definition($field_type_slug, $field_type_configuration);
} catch (Exception $e) {
return null;
}
// Save new instance to cache.
$this->field_type_definitions[$field_type_slug] = $field_type_definition;
}
// Use cache.
return $this->field_type_definitions[$field_type_slug];
}
示例10: process_call
/**
* @param array $arguments Original action/filter arguments.
*
* @return mixed
*/
function process_call($arguments)
{
$query = wpcf_getarr($arguments, 1, array());
$domain = wpcf_getarr($query, 'domain', 'all');
unset($query['domain']);
// Sanitize input
if (!is_string($domain) || !is_array($query)) {
return null;
}
if ('all' == $domain) {
// Separate query for each available domain.
$groups_by_domain = array();
$domains = Types_Field_Utils::get_domains();
foreach ($domains as $field_domain) {
$groups_by_domain[$field_domain] = $this->query_specific_domain($field_domain, $query);
}
return $groups_by_domain;
} else {
return $this->query_specific_domain($domain, $query);
}
}
示例11: query_groups
/**
* Get field groups based on query arguments.
*
* @param array $query_args Optional. Arguments for the WP_Query that will be applied on the underlying posts.
* Post type query is added automatically.
* Additional arguments are allowed:
* - 'types_search': String for extended search. See WPCF_Field_Group::is_match() for details.
* - 'is_active' bool: If defined, only active/inactive field groups will be returned.
*
* @return Types_Field_Group[]
* @since 1.9
*/
public function query_groups($query_args = array())
{
// Read specific arguments
$search_string = wpcf_getarr($query_args, 'types_search');
$is_active = wpcf_getarr($query_args, 'is_active', null);
// Query posts
$query_args = array_merge($query_args, array('post_type' => $this->get_post_type(), 'posts_per_page' => -1));
// Group's "activeness" is defined by the post status.
if (null !== $is_active) {
unset($query_args['is_active']);
$query_args['post_status'] = $is_active ? 'publish' : 'draft';
}
$query = new WP_Query($query_args);
$posts = $query->get_posts();
// Transform posts into Types_Field_Group
$all_groups = array();
foreach ($posts as $post) {
$field_group = $this->load_field_group($post);
if (null != $field_group) {
$all_groups[] = $field_group;
}
}
// Filter groups by the search string.
$selected_groups = array();
if (empty($search_string)) {
$selected_groups = $all_groups;
} else {
/** @var Types_Field_Group $group */
foreach ($all_groups as $group) {
if ($group->is_match($search_string)) {
$selected_groups[] = $group;
}
}
}
return $selected_groups;
}
示例12: wpcf_getnest
/**
* Get a value from nested associative array.
*
* This function will try to traverse a nested associative array by the set of keys provided.
*
* E.g. if you have $source = array( 'a' => array( 'b' => array( 'c' => 'my_value' ) ) ) and want to reach 'my_value',
* you need to write: $my_value = wpcf_getnest( $source, array( 'a', 'b', 'c' ) );
*
* @param mixed|array $source The source array.
* @param string[] $keys Keys which will be used to access the final value.
* @param null|mixed $default Default value to return when the keys cannot be followed.
*
* @return mixed|null Value in the nested structure defined by keys or default value.
*/
function wpcf_getnest(&$source, $keys = array(), $default = null)
{
$current_value = $source;
while (!empty($keys)) {
$current_key = array_shift($keys);
$is_last_key = empty($keys);
$current_value = wpcf_getarr($current_value, $current_key, null);
if ($is_last_key) {
return $current_value;
} elseif (!is_array($current_value)) {
return $default;
}
}
return $default;
}
示例13: get_ellipsis
/**
* @return string Ellipsis to be added when some field values are omitted.
* @since 1.9.1
*/
protected function get_ellipsis()
{
return wpcf_getarr($this->args, 'ellipsis', $this->get_value_separator() . '...');
}
示例14: get_groups_by_taxonomy
/**
* Get array of groups that are associated with given taxonomy.
*
* @param string $taxonomy_slug Slug of the taxonomy
* @return WPCF_Field_Group_Term[] Associated term field groups.
*/
public function get_groups_by_taxonomy($taxonomy_slug)
{
$groups_by_taxonomies = $this->get_groups_by_taxonomies();
return wpcf_ensarr(wpcf_getarr($groups_by_taxonomies, $taxonomy_slug));
}
示例15: change_field_cardinality
/**
* Change cardinality of given field, if it is permitted by its type.
*
* @param string $field_slug Field definition slug.
* @param string $domain Field domain.
* @param string[] $arguments Needs to contain the 'target_cardinality' key with 'single'|'repetitive' value.
* @return bool|WP_Error|WPCF_Field_Definition The updated definition on succes, error/false otherwise.
* @since 2.0
*/
public static function change_field_cardinality($field_slug, $domain, $arguments)
{
$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)));
} else {
if (!$definition->is_managed_by_types()) {
return new WP_Error(42, sprintf(__('Field "%s" will not be converted because it is not managed by Types.', 'wpcf'), sanitize_text_field($field_slug)));
}
}
$target_cardinality = wpcf_getarr($arguments, 'target_cardinality', null, array('single', 'repetitive'));
if (null == $target_cardinality) {
return false;
}
$set_as_repetitive = 'repetitive' == $target_cardinality;
$result = $definition->set_is_repetitive($set_as_repetitive);
if ($result) {
return $definition;
} else {
return false;
}
}