本文整理汇总了PHP中wpcf_admin_fields_get_groups函数的典型用法代码示例。如果您正苦于以下问题:PHP wpcf_admin_fields_get_groups函数的具体用法?PHP wpcf_admin_fields_get_groups怎么用?PHP wpcf_admin_fields_get_groups使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wpcf_admin_fields_get_groups函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wpcf_cred_post_groups_filter
/**
* Filters groups on post edit page.
*
* @param type $groups
* @param type $post
* @return type
*/
function wpcf_cred_post_groups_filter($groups, $post)
{
if (isset($post->post_type) && $post->post_type == 'cred-form') {
return wpcf_admin_fields_get_groups(TYPES_CUSTOM_FIELD_GROUP_CPT_NAME, 'group_active', 'fields_active');
return wpcf_admin_fields_get_groups();
}
return $groups;
}
示例2: wpcf_cred_post_groups_filter
/**
* Filters groups on post edit page.
*
* @param type $groups
* @param type $post
* @return type
*/
function wpcf_cred_post_groups_filter($groups, $post)
{
if (isset($post->post_type) && $post->post_type == 'cred-form') {
return wpcf_admin_fields_get_groups('wp-types-group', 'group_active', 'fields_active');
return wpcf_admin_fields_get_groups();
}
return $groups;
}
示例3: wpcf_admin_fields_list
/**
* Renders 'widefat' table.
*/
function wpcf_admin_fields_list()
{
$groups = wpcf_admin_fields_get_groups();
if (empty($groups)) {
echo '<p>' . __("To use custom fields, please create a group to hold them.", 'wpcf') . '</p>';
echo '<br /><a class="button-primary" href="' . admin_url('admin.php?page=wpcf-edit') . '">' . __('Add a custom fields group', 'wpcf') . '</a><br /><br />';
} else {
echo '<br /><a class="button-secondary" href="' . admin_url('admin.php?page=wpcf-edit') . '">' . __('Add a custom fields group', 'wpcf') . '</a><br /><br />';
$rows = array();
$header = array('group_name' => __('Group name', 'wpcf'), 'group_description' => __('Description', 'wpcf'), 'group_active' => __('Active', 'wpcf'), 'group_post_types' => __('Post types', 'wpcf'), 'group_taxonomies' => __('Taxonomies', 'wpcf'));
foreach ($groups as $group) {
// Set 'name' column
$name = '';
$name .= '<a href="' . admin_url('admin.php?page=wpcf-edit&group_id=' . $group['id']) . '">' . $group['name'] . '</a>';
$name .= '<br />';
$name .= '<a href="' . admin_url('admin.php?page=wpcf-edit&group_id=' . $group['id']) . '">' . __('Edit', 'wpcf') . '</a> | ';
$name .= $group['is_active'] ? wpcf_admin_fields_get_ajax_deactivation_link($group['id']) . ' | ' : wpcf_admin_fields_get_ajax_activation_link($group['id']) . ' | ';
$name .= '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&' . 'wpcf_action=delete_group&group_id=' . $group['id'] . '&wpcf_ajax_update=wpcf_list_ajax_response_' . $group['id']) . '&_wpnonce=' . wp_create_nonce('delete_group') . '&wpcf_warning=' . __('Are you sure?', 'wpcf') . '" class="wpcf-ajax-link" ' . 'id="wpcf-list-delete-' . $group['id'] . '">' . __('Delete Permanently', 'wpcf') . '</a>';
$name .= '<div id="wpcf_list_ajax_response_' . $group['id'] . '"></div>';
$rows[$group['id']]['name'] = $name;
$rows[$group['id']]['raw_name'] = $group['name'];
$rows[$group['id']]['description'] = $group['description'];
$rows[$group['id']]['active-' . $group['id']] = $group['is_active'] ? __('Yes', 'wpcf') : __('No', 'wpcf');
$rows[$group['id']]['status'] = $group['is_active'] ? 'active' : 'inactive';
// Set 'post_tpes' column
$post_types = wpcf_admin_get_post_types_by_group($group['id']);
$rows[$group['id']]['post_types'] = empty($post_types) ? __('All post types', 'wpcf') : implode(', ', $post_types);
// Set 'taxonomies' column
$taxonomies = wpcf_admin_get_taxonomies_by_group($group['id']);
$output = '';
if (empty($taxonomies)) {
$output = __('None', 'wpcf');
} else {
foreach ($taxonomies as $taxonomy => $terms) {
$output .= '<em>' . $taxonomy . '</em>: ';
$terms_output = array();
foreach ($terms as $term_id => $term) {
$terms_output[] = $term['name'];
}
$output .= implode(', ', $terms_output) . '<br />';
}
}
$rows[$group['id']]['tax'] = $output;
}
uasort($rows, 'wpcf_admin_fields_list_sort');
// Render table
wpcf_admin_widefat_table('wpcf_groups_list', $header, $rows);
}
do_action('wpcf_groups_list_table_after');
}
示例4: wpcf_admin_fields_list
/**
* Renders 'widefat' table.
*/
function wpcf_admin_fields_list()
{
$groups = wpcf_admin_fields_get_groups();
if (empty($groups)) {
echo '<p>' . __("Custom Fields (also known as post-meta) are information attached to WordPress posts. This data can then be queried and filtered in your database. With Types you can create Custom Field Groups which are then attached to any post type (including Posts, Pages and Custom Post Types) or taxonomy.", 'wpcf') . '<br /><br />' . __('You can read more about Custom Fields in this tutorial: <a href="http://wp-types.com/user-guides/using-custom-fields/" target="_blank">http://wp-types.com/user-guides/using-custom-fields/ »</a>.', 'wpcf') . '</p>';
}
echo '<br /><a class="button-secondary" href="' . admin_url('admin.php?page=wpcf-edit') . '">' . __('Add a custom fields group', 'wpcf') . '</a><br /><br />';
if (!empty($groups)) {
$rows = array();
$header = array('group_name' => __('Group name', 'wpcf'), 'group_description' => __('Description', 'wpcf'), 'group_active' => __('Active', 'wpcf'), 'group_post_types' => __('Post types', 'wpcf'), 'group_taxonomies' => __('Taxonomies', 'wpcf'));
foreach ($groups as $group) {
// Set 'name' column
$name = '';
$name .= '<a href="' . admin_url('admin.php?page=wpcf-edit&group_id=' . $group['id']) . '">' . $group['name'] . '</a>';
$name .= '<br />';
$name .= '<a href="' . admin_url('admin.php?page=wpcf-edit&group_id=' . $group['id']) . '">' . __('Edit', 'wpcf') . '</a> | ';
$name .= $group['is_active'] ? wpcf_admin_fields_get_ajax_deactivation_link($group['id']) . ' | ' : wpcf_admin_fields_get_ajax_activation_link($group['id']) . ' | ';
$name .= '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&' . 'wpcf_action=delete_group&group_id=' . $group['id'] . '&wpcf_ajax_update=wpcf_list_ajax_response_' . $group['id']) . '&_wpnonce=' . wp_create_nonce('delete_group') . '&wpcf_warning=' . __('Are you sure?', 'wpcf') . '" class="wpcf-ajax-link" ' . 'id="wpcf-list-delete-' . $group['id'] . '">' . __('Delete Permanently', 'wpcf') . '</a>';
$name .= '<div id="wpcf_list_ajax_response_' . $group['id'] . '"></div>';
$rows[$group['id']]['name'] = $name;
$rows[$group['id']]['description'] = $group['description'];
$rows[$group['id']]['active-' . $group['id']] = $group['is_active'] ? __('Yes', 'wpcf') : __('No', 'wpcf');
// Set 'post_tpes' column
$post_types = wpcf_admin_get_post_types_by_group($group['id']);
$rows[$group['id']]['post_types'] = empty($post_types) ? __('None', 'wpcf') : implode(', ', $post_types);
// Set 'taxonomies' column
$taxonomies = wpcf_admin_get_taxonomies_by_group($group['id']);
$output = '';
if (empty($taxonomies)) {
$output = __('None', 'wpcf');
} else {
foreach ($taxonomies as $taxonomy => $terms) {
$output .= '<em>' . $taxonomy . '</em>: ';
$terms_output = array();
foreach ($terms as $term_id => $term) {
$terms_output[] = $term['name'];
}
$output .= implode(', ', $terms_output) . '<br />';
}
}
$rows[$group['id']]['tax'] = $output;
}
// Render table
wpcf_admin_widefat_table('wpcf_groups_list', $header, $rows);
}
do_action('wpcf_groups_list_table_after');
}
示例5: wpv_filters_add_filter_usermeta_field
static function wpv_filters_add_filter_usermeta_field($filters)
{
$basic = array(array(__('First Name', 'wpv-views'), 'first_name', 'Basic', ''), array(__('Last Name', 'wpv-views'), 'last_name', 'Basic', ''), array(__('Nickname', 'wpv-views'), 'nickname', 'Basic', ''), array(__('Description', 'wpv-views'), 'description', 'Basic', ''), array(__('Yahoo IM', 'wpv-views'), 'yim', 'Basic', ''), array(__('Jabber', 'wpv-views'), 'jabber', 'Basic', ''), array(__('AIM', 'wpv-views'), 'aim', 'Basic', ''));
foreach ($basic as $b_filter) {
$filters['usermeta-field-basic-' . str_replace(' ', '_', $b_filter[1])] = array('name' => sprintf(__('User field - %s', 'wpv-views'), $b_filter[0]), 'present' => 'usermeta-field-' . $b_filter[1] . '_compare', 'callback' => array('WPV_Usermeta_Field_Filter', 'wpv_add_new_filter_usermeta_field_list_item'), 'args' => array('name' => 'usermeta-field-' . $b_filter[1]), 'group' => __('User data', 'wpv-views'));
}
// @todo review this for gods sake!!!!!!!!!!!!!!!!!!!!!!!!
if (function_exists('wpcf_admin_fields_get_groups')) {
$groups = wpcf_admin_fields_get_groups('wp-types-user-group');
$user_id = wpcf_usermeta_get_user();
$add = array();
if (!empty($groups)) {
foreach ($groups as $group_id => $group) {
if (empty($group['is_active'])) {
continue;
}
$fields = wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', true, false, true, 'wp-types-user-group', 'wpcf-usermeta');
if (!empty($fields)) {
foreach ($fields as $field_id => $field) {
$add[] = $field['meta_key'];
$filters['usermeta-field-' . str_replace(' ', '_', $field['meta_key'])] = array('name' => sprintf(__('User field - %s', 'wpv-views'), $field['name']), 'present' => 'usermeta-field-' . $field['meta_key'] . '_compare', 'callback' => array('WPV_Usermeta_Field_Filter', 'wpv_add_new_filter_usermeta_field_list_item'), 'args' => array('name' => 'usermeta-field-' . $field['meta_key']));
}
}
}
}
$cf_types = wpcf_admin_fields_get_fields(true, true, false, 'wpcf-usermeta');
foreach ($cf_types as $cf_id => $cf) {
if (!in_array($cf['meta_key'], $add)) {
$filters['usermeta-field-' . str_replace(' ', '_', $cf['meta_key'])] = array('name' => sprintf(__('User field - %s', 'wpv-views'), $cf['name']), 'present' => 'usermeta-field-' . $cf['meta_key'] . '_compare', 'callback' => array('WPV_Usermeta_Field_Filter', 'wpv_add_new_filter_usermeta_field_list_item'), 'args' => array('name' => 'usermeta-field-' . $cf['meta_key']));
}
}
}
$meta_keys = get_user_meta_keys();
foreach ($meta_keys as $key) {
$key_nicename = '';
if (stripos($key, 'wpcf-') === 0) {
if (function_exists('wpcf_admin_fields_get_groups')) {
continue;
}
} else {
$key_nicename = $key;
}
$filters['usermeta-field-' . str_replace(' ', '_', $key)] = array('name' => sprintf(__('User field - %s', 'wpv-views'), $key_nicename), 'present' => 'usermeta-field-' . $key . '_compare', 'callback' => array('WPV_Usermeta_Field_Filter', 'wpv_add_new_filter_usermeta_field_list_item'), 'args' => array('name' => 'usermeta-field-' . $key));
}
return $filters;
}
示例6: wpcf_admin_usermeta_list
/**
* Renders 'widefat' table.
*/
function wpcf_admin_usermeta_list()
{
$post_type = 'wp-types-user-group';
$groups = wpcf_admin_fields_get_groups('wp-types-user-group');
if (empty($groups)) {
echo '<p>' . __("User Fields, also known as user-meta, are additional fields that belong to user profiles.", 'wpcf') . '</p>';
}
echo '<br /><a class="button-secondary" href="' . admin_url('admin.php?page=wpcf-edit-usermeta') . '">' . __('Add a user meta group', 'wpcf') . '</a><br /><br />';
if (!empty($groups)) {
$rows = array();
$header = array('group_name' => __('Group name', 'wpcf'), 'group_description' => __('Description', 'wpcf'), 'group_active' => __('Active', 'wpcf'), 'group_post_types' => __('Available for', 'wpcf'));
foreach ($groups as $group) {
// Set 'name' column
$name = '';
$name .= '<a href="' . admin_url('admin.php?page=wpcf-edit-usermeta&group_id=' . $group['id']) . '">' . $group['name'] . '</a>';
$name .= '<br />';
$name .= '<a href="' . admin_url('admin.php?page=wpcf-edit-usermeta&group_id=' . $group['id']) . '">' . __('Edit', 'wpcf') . '</a> | ';
$name .= $group['is_active'] ? wpcf_admin_usermeta_get_ajax_deactivation_link($group['id']) . ' | ' : wpcf_admin_usermeta_get_ajax_activation_link($group['id']) . ' | ';
$name .= '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&' . 'wpcf_action=delete_usermeta_group&group_id=' . $group['id'] . '&wpcf_ajax_update=wpcf_list_ajax_response_' . $group['id']) . '&_wpnonce=' . wp_create_nonce('delete_usermeta_group') . '&wpcf_warning=' . __('Are you sure?', 'wpcf') . '" class="wpcf-ajax-link" ' . 'id="wpcf-list-delete-' . $group['id'] . '">' . __('Delete Permanently', 'wpcf') . '</a>';
$name .= '<div id="wpcf_list_ajax_response_' . $group['id'] . '"></div>';
$rows[$group['id']]['name'] = $name;
$rows[$group['id']]['description'] = $group['description'];
$rows[$group['id']]['active-' . $group['id']] = $group['is_active'] ? __('Yes', 'wpcf') : __('No', 'wpcf');
$show_for = wpcf_admin_get_groups_showfor_by_group($group['id']);
if (function_exists('wpcf_access_register_caps')) {
$show_for = __('This groups visibility is also controlled by the Access plugin.', 'wpcf');
} else {
$show_for = count($show_for) == 0 ? __('Displayed for all users roles', 'wpcf') : ucwords(implode($show_for, ', '));
}
$rows[$group['id']]['group_post_types'] = $show_for;
}
// Render table
wpcf_admin_widefat_table('wpcf_groups_list', $header, $rows);
}
do_action('wpcf_groups_list_table_after');
}
示例7: wpcf_admin_fields_get_groups_by_field
/**
* Gets all groups that contain specified field.
*
* @static $cache
* @param type $field_id
*/
function wpcf_admin_fields_get_groups_by_field($field_id, $post_type = 'wp-types-group')
{
static $cache = array();
$groups = wpcf_admin_fields_get_groups($post_type);
$meta_name = $post_type == 'wp-types-group' ? 'wpcf-fields' : 'wpcf-usermeta';
$return = array();
foreach ($groups as $group_id => $group) {
if (isset($cache['groups'][$group_id])) {
$fields = $cache['groups'][$group_id];
} else {
$fields = wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', false, false, false, $post_type, $meta_name);
}
if (array_key_exists($field_id, $fields)) {
$return[$group['id']] = $group;
}
$cache['groups'][$group_id] = $fields;
}
return $return;
}
示例8: editorDropdownFilter
/**
* Adds items to view dropdown.
*
* @param type $items
* @return type
*/
public static function editorDropdownFilter($items)
{
$post = wpcf_admin_get_edited_post();
if (empty($post)) {
$post = (object) array('ID' => -1);
}
$groups = wpcf_admin_fields_get_groups('wp-types-group', 'group_active');
$all_post_types = implode(' ', get_post_types(array('public' => true)));
$add = array();
if (!empty($groups)) {
// $group_id is blank therefore not equal to $group['id']
// use array for item key and CSS class
$item_styles = array();
foreach ($groups as $group) {
$fields = wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', true, false, true);
if (!empty($fields)) {
// code from Types used here without breaking the flow
// get post types list for every group or apply all
$post_types = get_post_meta($group['id'], '_wp_types_group_post_types', true);
if ($post_types == 'all') {
$post_types = $all_post_types;
}
$post_types = trim(str_replace(',', ' ', $post_types));
$item_styles[$group['name']] = $post_types;
foreach ($fields as $field) {
$callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'postmeta\', ' . $post->ID . ')';
$add[$group['name']][stripslashes($field['name'])] = array(stripslashes($field['name']), trim(wpcf_fields_get_shortcode($field), '[]'), $group['name'], $callback);
// TODO Remove - it's not post edit screen (meta box JS and CSS)
WPCF_Fields::enqueueScript($field['type']);
WPCF_Fields::enqueueStyle($field['type']);
}
}
}
}
$search_key = '';
// Iterate all items to be displayed in the "V" menu
foreach ($items as $key => $item) {
if ($key == __('Basic', 'wpv-views')) {
$search_key = 'found';
continue;
}
if ($search_key == 'found') {
$search_key = $key;
}
if ($key == __('Field', 'wpv-views') && isset($item[trim(wpcf_types_get_meta_prefix(), '-')])) {
unset($items[$key][trim(wpcf_types_get_meta_prefix(), '-')]);
}
}
if (empty($search_key) || $search_key == 'found') {
$search_key = count($items);
}
$insert_position = array_search($search_key, array_keys($items));
$part_one = array_slice($items, 0, $insert_position);
$part_two = array_slice($items, $insert_position);
$items = $part_one + $add + $part_two;
// apply CSS styles to each item based on post types
foreach ($items as $key => $value) {
if (isset($item_styles[$key])) {
$items[$key]['css'] = $item_styles[$key];
} else {
$items[$key]['css'] = $all_post_types;
}
}
return $items;
}
示例9: wpcf_register_modules_items_groups
function wpcf_register_modules_items_groups($items)
{
$groups = wpcf_admin_fields_get_groups();
foreach ($groups as $group) {
$_details = sprintf(__('Fields group: %s', 'wpcf'), $group['name']);
$details = !empty($group['description']) ? $group['description'] : $_details;
$items[] = array('id' => '12' . _GROUPS_MODULE_MANAGER_KEY_ . '21' . $group['id'], 'title' => $group['name'], 'details' => '<p style="padding:5px;">' . $details . '</p>', '__types_id' => $group['slug'], '__types_title' => $group['name']);
}
return $items;
}
示例10: wpcf_admin_bulk_string_translation
/**
* Bulk translation.
*/
function wpcf_admin_bulk_string_translation()
{
if (!function_exists('icl_register_string')) {
return false;
}
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
require_once WPCF_EMBEDDED_INC_ABSPATH . '/custom-types.php';
require_once WPCF_INC_ABSPATH . '/custom-types-form.php';
require_once WPCF_EMBEDDED_INC_ABSPATH . '/custom-taxonomies.php';
require_once WPCF_INC_ABSPATH . '/custom-taxonomies-form.php';
// Register groups
$groups = wpcf_admin_fields_get_groups();
foreach ($groups as $group_id => $group) {
wpcf_translate_register_string('plugin Types', 'group ' . $group_id . ' name', $group['name']);
if (isset($group['description'])) {
wpcf_translate_register_string('plugin Types', 'group ' . $group_id . ' description', $group['description']);
}
}
// Register fields
$fields = wpcf_admin_fields_get_fields();
foreach ($fields as $field_id => $field) {
wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' name', $field['name']);
if (isset($field['description'])) {
wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' description', $field['description']);
}
// For radios or select
if (!empty($field['data']['options'])) {
foreach ($field['data']['options'] as $name => $option) {
if ($name == 'default') {
continue;
}
if (isset($option['title'])) {
wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' title', $option['title']);
}
if (isset($option['value'])) {
wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' value', $option['value']);
}
if (isset($option['display_value'])) {
wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' display value', $option['display_value']);
}
}
}
if ($field['type'] == 'checkbox' && (isset($field['set_value']) && $field['set_value'] != '1')) {
// we need to translate the check box value to store
wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' checkbox value', $field['set_value']);
}
if ($field['type'] == 'checkbox' && !empty($field['display_value_selected'])) {
// we need to translate the check box value to store
wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' checkbox value selected', $field['display_value_selected']);
}
if ($field['type'] == 'checkbox' && !empty($field['display_value_not_selected'])) {
// we need to translate the check box value to store
wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' checkbox value not selected', $field['display_value_not_selected']);
}
// Validation message
if (!empty($field['data']['validate'])) {
foreach ($field['data']['validate'] as $method => $validation) {
if (!empty($validation['message'])) {
// Skip if it's same as default
$default_message = wpcf_admin_validation_messages($method);
if ($validation['message'] != $default_message) {
wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' validation message ' . $method, $validation['message']);
}
}
}
}
}
// Register types
$custom_types = get_option('wpcf-custom-types', array());
foreach ($custom_types as $post_type => $data) {
wpcf_custom_types_register_translation($post_type, $data);
}
// Register taxonomies
$custom_taxonomies = get_option('wpcf-custom-taxonomies', array());
foreach ($custom_taxonomies as $taxonomy => $data) {
wpcf_custom_taxonimies_register_translation($taxonomy, $data);
}
}
示例11: __construct
public function __construct()
{
//Get list of groups
self::$fields_groups = wpcf_admin_fields_get_groups();
// setup custom capabilities
//If access plugin installed
if (function_exists('wpcf_access_register_caps')) {
// integrate with Types Access
if (!empty(self::$fields_groups)) {
//Add Fields area
add_filter('types-access-area', array('Post_Fields_Access', 'register_access_fields_area'), 10, 2);
//Add Fields groups
add_filter('types-access-group', array('Post_Fields_Access', 'register_access_fields_groups'), 10, 2);
//Add Fields caps to groups
add_filter('types-access-cap', array('Post_Fields_Access', 'register_access_fields_caps'), 10, 3);
//}
}
}
}
示例12: prepare_items
/** ************************************************************************
* REQUIRED! This is where you prepare your data for display. This method will
* usually be used to query the database, sort and filter the data, and generally
* get it ready to be displayed. At a minimum, we should set $this->items and
* $this->set_pagination_args(), although the following properties and methods
* are frequently interacted with here...
*
* @uses $this->_column_headers
* @uses $this->items
* @uses $this->get_columns()
* @uses $this->get_sortable_columns()
* @uses $this->get_pagenum()
* @uses $this->set_pagination_args()
**************************************************************************/
function prepare_items()
{
/**
* First, lets decide how many records per page to show
*/
$per_page = $this->get_items_per_page('wpcf_uf_per_page', 10);
/**
* REQUIRED. Now we need to define our column headers. This includes a complete
* array of columns to be displayed (slugs & titles), a list of columns
* to keep hidden, and a list of columns that are sortable. Each of these
* can be defined in another method (as we've done here) before being
* used to build the value for our _column_headers property.
*/
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
/**
* REQUIRED. Finally, we build an array to be used by the class for column
* headers. The $this->_column_headers property takes an array which contains
* 3 other arrays. One for all columns, one for hidden columns, and one
* for sortable columns.
*/
$this->_column_headers = array($columns, $hidden, $sortable);
/**
* Optional. You can handle your bulk actions however you see fit. In this
* case, we'll handle them within our package just to keep things clean.
*/
$this->process_bulk_action();
/**
* Instead of querying a database, we're going to fetch the example data
* property we created for use in this plugin. This makes this example
* package slightly different than one you might build on your own. In
* this example, we'll be using array manipulation to sort and paginate
* our data. In a real-world implementation, you will probably want to
* use sort and pagination data to build a custom query instead, as you'll
* be able to use your precisely-queried data immediately.
*/
$s = isset($_POST['s']) ? mb_strtolower(trim($_POST['s'])) : false;
$data = array();
$groups = wpcf_admin_fields_get_groups(TYPES_USER_META_FIELD_GROUP_CPT_NAME);
if (!empty($groups)) {
foreach (array_values($groups) as $group) {
$one = array('description' => $group['description'], 'id' => $group['id'], 'slug' => $group['slug'], 'status' => isset($group['is_active']) && $group['is_active'] ? 'active' : 'inactive', 'supports' => isset($group['supports']) ? $group['supports'] : array(), 'title' => wp_kses_post($group['name']), WPCF_AUTHOR => isset($group[WPCF_AUTHOR]) ? $group[WPCF_AUTHOR] : 0);
$add_one = true;
if ($s) {
$add_one = false;
foreach (array('description', 'id', 'slug', 'title') as $key) {
if ($add_one || empty($one[$key])) {
continue;
}
if (is_numeric(strpos(mb_strtolower($one[$key]), $s))) {
$add_one = true;
}
}
}
if ($add_one) {
$data[] = $one;
}
}
}
/**
* This checks for sorting input and sorts the data in our array accordingly.
*/
usort($data, 'wpcf_usort_reorder');
/**
* REQUIRED for pagination. Let's figure out what page the user is currently
* looking at. We'll need this later, so you should always include it in
* your own package classes.
*/
$current_page = $this->get_pagenum();
/**
* REQUIRED for pagination. Let's check how many items are in our data array.
* In real-world use, this would be the total number of items in your database,
* without filtering. We'll need this later, so you should always include it
* in your own package classes.
*/
$total_items = count($data);
/**
* The WP_List_Table class does not handle pagination for us, so we need
* to ensure that the data is trimmed to only the current page. We can use
* array_slice() to
*/
$data = array_slice($data, ($current_page - 1) * $per_page, $per_page);
/**
* REQUIRED. Now we can add our *sorted* data to the items property, where
* it can be used by the rest of the class.
//.........这里部分代码省略.........
示例13: wpcf_admin_get_allowed_fields_by_post_type
/**
* Get active fields by post type
*
* Get active fields by post type chosing it from active groups and this
* groups which are connected to certain post type.
*
* @since: 1.7
*
* @param string $post_type post type
*
* @return array allowed meta keys
*/
function wpcf_admin_get_allowed_fields_by_post_type($post_type)
{
$allowed_fields = $active_groups = array();
$all_groups = wpcf_admin_get_groups_by_post_type($post_type);
foreach ($all_groups as $group_id => $group_data) {
$active_groups[] = $group_data['slug'];
}
$all_groups = wpcf_admin_fields_get_groups(TYPES_CUSTOM_FIELD_GROUP_CPT_NAME, true, true);
foreach ($all_groups as $group) {
if (!in_array($group['slug'], $active_groups)) {
continue;
}
foreach ($group['fields'] as $field_key => $field_data) {
$allowed_fields[] = $field_data['meta_key'];
}
}
return $allowed_fields;
}
示例14: prepare_items
/**
* @global object $wpdb
*/
function prepare_items()
{
global $wpdb;
$per_page = $this->get_items_per_page('wpcf_ufc_per_page', 10);
// Get ours and enabled
$cf_types = wpcf_admin_fields_get_fields(true, true, false, 'wpcf-usermeta');
$__groups = wpcf_admin_fields_get_groups(TYPES_USER_META_FIELD_GROUP_CPT_NAME);
foreach ($__groups as $__group_id => $__group) {
$__groups[$__group_id]['fields'] = wpcf_admin_fields_get_fields_by_group($__group['id'], 'slug', false, true, false, TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta');
}
foreach ($cf_types as $cf_id => $cf) {
foreach ($__groups as $__group) {
if (isset($__group['fields'][$cf_id])) {
$cf_types[$cf_id]['groups'][$__group['id']] = $__group['name'];
}
}
$cf_types[$cf_id]['groups_txt'] = empty($cf_types[$cf_id]['groups']) ? __('None', 'wpcf') : implode(', ', $cf_types[$cf_id]['groups']);
}
$meta_key_not_like = array('\\_%', 'closedpostboxes%', 'meta-box-order%', 'metaboxhidden%');
$having = '';
foreach ($meta_key_not_like as $one) {
if ($having) {
$having .= ' AND ';
}
$having .= sprintf('meta_key NOT LIKE \'%s\'', $one);
}
if ($having) {
$having = ' HAVING ' . $having;
}
$query = sprintf('SELECT umeta_id, meta_key FROM %s GROUP BY meta_key %s ORDER BY meta_key', $wpdb->usermeta, $having);
// Get others (cache this result?)
$cf_other = $wpdb->get_results($query);
$output = '';
// Clean from ours
foreach ($cf_other as $type_id => $type_data) {
if (strpos($type_data->meta_key, WPCF_META_PREFIX) !== false) {
$field_temp = wpcf_admin_fields_get_field(str_replace(WPCF_META_PREFIX, '', $type_data->meta_key), false, false, 'wpcf-usermeta');
if (!empty($field_temp)) {
if (!empty($field_temp['data']['disabled'])) {
$cf_types[$field_temp['id']] = array('id' => $field_temp['id'], 'slug' => $type_data->meta_key, 'name' => $type_data->meta_key, 'type' => 0, 'groups_txt' => __('None', 'wpcf'));
} else {
unset($cf_other[$type_id]);
}
} else {
if (wpcf_types_cf_under_control('check_exists', $type_data->meta_key, TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta')) {
unset($cf_other[$type_id]);
} else {
$cf_types[$type_data->meta_key] = array('id' => $type_data->meta_key, 'slug' => $type_data->meta_key, 'name' => $type_data->meta_key, 'type' => 0, 'groups_txt' => __('None', 'wpcf'));
}
}
} else {
if (wpcf_types_cf_under_control('check_exists', $type_data->meta_key, TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta')) {
unset($cf_other[$type_id]);
} else {
$cf_types[$type_data->meta_key] = array('id' => $type_data->meta_key, 'slug' => $type_data->meta_key, 'name' => $type_data->meta_key, 'type' => 0, 'groups_txt' => __('None', 'wpcf'));
}
}
}
// Set some values
foreach ($cf_types as $cf_id_temp => $cf_temp) {
if (empty($cf_temp['type']) || !empty($cf_temp['data']['controlled'])) {
$cf_types[$cf_id_temp]['slug'] = $cf_temp['name'];
} else {
$cf_types[$cf_id_temp]['slug'] = wpcf_types_get_meta_prefix($cf_temp) . $cf_temp['slug'];
}
}
// Order
$orderby = isset($_REQUEST['orderby']) && !empty($_REQUEST['orderby']) ? sanitize_text_field($_REQUEST['orderby']) : 'c';
$order = isset($_REQUEST['order']) && !empty($_REQUEST['order']) ? sanitize_text_field($_REQUEST['order']) : 'asc';
$sort_matches = array('c' => 'name', 'g' => 'groups_txt', 't' => 'slug', 'f' => 'type');
$sorted_keys = array();
$new_array = array();
foreach ($cf_types as $cf_id_temp => $cf_temp) {
if (isset($sort_matches[$orderby])) {
$sorted_keys[$cf_temp['id']] = strtolower($cf_temp[$sort_matches[$orderby]]);
} else {
$sorted_keys[$cf_temp['id']] = strtolower($cf_temp[$sort_matches['c']]);
}
}
asort($sorted_keys, SORT_STRING);
if ('desc' == $order) {
$sorted_keys = array_reverse($sorted_keys, true);
}
foreach ($sorted_keys as $cf_id_temp => $groups_txt) {
$new_array[$cf_id_temp] = $cf_types[$cf_id_temp];
}
$cf_types = $new_array;
// Search
if (!empty($_REQUEST['s'])) {
$search_results = array();
foreach ($cf_types as $search_id => $search_field) {
if (strpos(strval($search_field['name']), strval(trim(stripslashes($_REQUEST['s'])))) !== false) {
$search_results[$search_id] = $cf_types[$search_id];
}
}
$cf_types = $search_results;
}
//.........这里部分代码省略.........
示例15: ajax_metabox_custom_fields_get_content
/**
* Summary.
*
* Description.
*
* @since x.x.x
* @access (for functions: only use if private)
*
* @see Function/method/class relied on
* @link URL
* @global type $varname Description.
* @global type $varname Description.
*
* @param type $var Description.
* @param type $var Optional. Description.
* @return type Description.
*/
public function ajax_metabox_custom_fields_get_content()
{
// check nonce
if (!isset($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'], $this->get_nonce('custom-fields-box', $_REQUEST['type'], $_REQUEST['id']))) {
$this->verification_failed_and_die();
}
// we need an array of all possible fields to check agains what is stored in the database,
// otherwise stored db fields will always be shown until next cpt save
$possible_fields = array();
// current selected groups
$current_selected_groups = isset($_REQUEST['current_groups']) && !empty($_REQUEST['current_groups']) ? $_REQUEST['current_groups'] : array();
// current selected fields
$current_selected_fields = isset($_REQUEST['current_fields']) && !empty($_REQUEST['current_fields']) ? $_REQUEST['current_fields'] : array();
// get post type slug
$post_type_slug = $this->get_type_from_request('id');
// not saved yet
if (empty($post_type_slug)) {
$this->print_notice_and_die(__('Please save first, before you can edit the custom fields.', 'wpcf'));
}
// current post type
require_once WPCF_INC_ABSPATH . '/classes/class.types.admin.post-type.php';
$wpcf_post_type = new Types_Admin_Post_Type();
$post_type = $wpcf_post_type->get_post_type($post_type_slug);
// no groups selected
if (empty($current_selected_groups)) {
$this->print_notice_and_die(sprintf(__('You can include Post Fields in the <b>listing page for %s</b>. Add Post Fields to this Post Type and you will be able to select which ones will display in the listing page.', 'wpcf'), $post_type['labels']['name']));
}
// all custom field groups
$custom_field_groups = wpcf_admin_fields_get_groups(TYPES_CUSTOM_FIELD_GROUP_CPT_NAME, true, true);
if (empty($custom_field_groups)) {
echo wpautop(__('To use custom fields, please create a group to hold them.', 'wpcf'));
die;
}
// form
$form = $field_checkboxes = array();
// add description to form
$form['description'] = array('#type' => 'markup', '#markup' => sprintf('<p class="description">%s</p>', __('Check which fields should be shown on this Post Type list as a columns.', 'wpcf')));
$form_add = array();
// for all custom field groups
foreach ($custom_field_groups as $custom_field_group) {
// skip group if not selected
if (!in_array($custom_field_group['id'], $current_selected_groups)) {
continue;
}
$id = 'group-' . $custom_field_group['id'] . '-';
// add fields to possible fields
if (isset($custom_field_group['fields'])) {
$possible_fields = array_merge($possible_fields, $custom_field_group['fields']);
} else {
$custom_field_group['fields'] = array();
}
// get field checkboxes
$field_checkboxes = $this->build_options($post_type, $custom_field_group['fields'], 'custom-field-%s');
// no fields
if (empty($field_checkboxes)) {
$form_add[$id] = array('#type' => 'markup', '#title' => $custom_field_group['name'], '#markup' => __('There are no available fields in this group.', 'wpcf'), '#inline' => true, '_builtin' => true, '#pattern' => '<div class="js-wpcf-custom-field-group wpcf-custom-field-group"><h4><TITLE></h4><ul><ELEMENT></ul></div>');
continue;
}
// if not first time loading fields use the selected fields and not the database stored
if ($_REQUEST['init'] == 0) {
foreach ($field_checkboxes as $field_key => $field_values) {
// check if field is selected
$field_values['#default_value'] = in_array('wpcf-' . $field_key, $current_selected_fields) || in_array($field_key, $current_selected_fields) ? 1 : 0;
$field_checkboxes[$field_key] = $field_values;
}
}
// add checkboxes to form
$form_add[$id] = array('#type' => 'checkboxes', '#title' => $custom_field_group['name'], '#options' => $field_checkboxes, '#name' => 'wpcf[group][supports]', '#inline' => true, '_builtin' => true, '#pattern' => '<div class="js-wpcf-custom-field-group wpcf-custom-field-group"><h4><TITLE></h4><ul><ELEMENT></ul></div>');
}
// if form is still empty here the user didn't create any group
if (empty($form_add)) {
$form['no-fields'] = array('#type' => 'markup', '#markup' => sprintf('<p class="description">%s</p>', __('No custom field groups found.', 'wpcf')));
$form = wpcf_form(__FUNCTION__, $form);
echo $form->renderForm();
die;
}
$form['groups-open'] = array('#type' => 'markup', '#markup' => '<div class="clearfix wpcf-custom-field-group-container js-wpcf-custom-field-group-container">');
$form += $form_add;
$form['groups-close'] = array('#type' => 'markup', '#markup' => '</div>');
/**
* Sortable Area
*/
// on first load use db stored fields
//.........这里部分代码省略.........