本文整理汇总了PHP中wpcf_admin_get_groups_showfor_by_group函数的典型用法代码示例。如果您正苦于以下问题:PHP wpcf_admin_get_groups_showfor_by_group函数的具体用法?PHP wpcf_admin_get_groups_showfor_by_group怎么用?PHP wpcf_admin_get_groups_showfor_by_group使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wpcf_admin_get_groups_showfor_by_group函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: column_default
/** ************************************************************************
* Recommended. This method is called when the parent class can't find a method
* specifically build for a given column. Generally, it's recommended to include
* one method for each column you want to render, keeping your package class
* neat and organized. For example, if the class needs to process a column
* named 'title', it would first see if a method named $this->column_title()
* exists - if it does, that method will be used. If it doesn't, this one will
* be used. Generally, you should try to use custom column methods as much as
* possible.
*
* Since we have defined a column_title() method later on, this method doesn't
* need to concern itself with any column with a name of 'title'. Instead, it
* needs to handle everything else.
*
* For more detailed insight into how columns are handled, take a look at
* WP_List_Table::single_row_columns()
*
* @param array $item A singular item (one full row's worth of data)
* @param array $column_name The name/slug of the column to be processed
* @return string Text or HTML to be placed inside the column <td>
**************************************************************************/
function column_default($item, $column_name)
{
switch ($column_name) {
case 'title':
case 'description':
return stripslashes($item[$column_name]);
case 'show_for':
$show_for = wpcf_admin_get_groups_showfor_by_group($item['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, ', '));
}
return $show_for;
case 'status':
return 'active' == $item[$column_name] ? __('Yes', 'wpcf') : __('No', 'wpcf');
default:
return print_r($item, true);
//Show the whole array for troubleshooting purposes
}
}
示例2: 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');
}
示例3: wpcf_admin_userprofile_init
/**
* Init functions for User profile edit pages.
*/
function wpcf_admin_userprofile_init($user_id)
{
global $wpcf;
if (!is_object($user_id)) {
$user_id = new stdClass();
$user_id->ID = 0;
}
$user_role = isset($user_id->roles) ? array_shift($user_id->roles) : 'subscriber';
$groups = wpcf_admin_usermeta_get_groups_fields();
$wpcf_active = false;
$profile_only_preview = '';
foreach ($groups as $group) {
if (!empty($group['fields'])) {
$wpcf_active = true;
$for_users = wpcf_admin_get_groups_showfor_by_group($group['id']);
$profile_only_preview = '';
if (count($for_users) != 0) {
if (!in_array($user_role, $for_users)) {
continue;
} else {
//If Access plugin activated
if (function_exists('wpcf_access_register_caps')) {
//If user can't view own profile fields
if (!current_user_can('view_own_in_profile_' . $group['slug'])) {
continue;
}
//If user can modify current group in own profile
if (!current_user_can('modify_own_' . $group['slug'])) {
$profile_only_preview = 1;
}
}
}
} else {
if (function_exists('wpcf_access_register_caps')) {
if (!current_user_can('view_own_in_profile_' . $group['slug'])) {
continue;
}
if (!current_user_can('modify_own_' . $group['slug'])) {
$profile_only_preview = 1;
}
}
}
// Process fields
if (empty($profile_only_preview)) {
if (defined('WPTOOLSET_FORMS_VERSION')) {
$errors = get_user_meta($user_id->ID, '__wpcf-invalid-fields', true);
// OLD
delete_post_meta($user_id->ID, 'wpcf-invalid-fields');
delete_post_meta($user_id->ID, '__wpcf-invalid-fields');
if (empty($group['fields'])) {
continue;
}
$output = '<div class="wpcf-group-area wpcf-group-area_' . $group['slug'] . '">' . "\n\n" . '<h3>' . wpcf_translate('group ' . $group['id'] . ' name', $group['name']) . '</h3>' . "\n\n";
if (!empty($group['description'])) {
$output .= '<span>' . wpautop(wpcf_translate('group ' . $group['id'] . ' description', $group['description'])) . '</span>' . "\n\n";
}
$output .= '<div class="wpcf-profile-field-line">' . "\n\n";
foreach ($group['fields'] as $field) {
$config = wptoolset_form_filter_types_field($field, $user_id->ID);
$config = array_map('fix_fields_config_output_for_display', $config);
$meta = get_user_meta($user_id->ID, $field['meta_key']);
if ($errors) {
$config['validate'] = true;
}
if (isset($config['validation']['required'])) {
$config['title'] .= '*';
}
$config['_title'] = $config['title'];
$output .= '
<div class="wpcf-profile-field-line">
<div class="wpcf-profile-line-left">
' . $config['title'] . '
</div>
<div class="wpcf-profile-line-right">
';
$description = false;
if (!empty($config['description'])) {
$description = sprintf('<span class="description">%s</span>', $config['description']);
}
$config['title'] = $config['description'] = '';
$form_name = $user_id->ID ? 'your-profile' : 'createuser';
$output .= wptoolset_form_field($form_name, $config, $meta);
if ($description) {
$output .= $description;
}
$output .= '
</div>
</div>';
}
$output .= '</div></div>';
echo $output;
} else {
$group['fields'] = wpcf_admin_usermeta_process_fields($user_id, $group['fields'], true);
wpcf_admin_render_fields($group, $user_id);
}
} else {
// Render profile fields (text only)
//.........这里部分代码省略.........
示例4: wpcf_admin_usermeta_form
/**
* Generates form data.
*/
function wpcf_admin_usermeta_form()
{
global $wpcf;
wpcf_admin_add_js_settings('wpcf_nonce_toggle_group', '\'' . wp_create_nonce('group_form_collapsed') . '\'');
wpcf_admin_add_js_settings('wpcf_nonce_toggle_fieldset', '\'' . wp_create_nonce('form_fieldset_toggle') . '\'');
$default = array();
global $wpcf_button_style;
global $wpcf_button_style30;
// If it's update, get data
$update = false;
if (isset($_REQUEST['group_id'])) {
$update = wpcf_admin_fields_get_group(intval($_REQUEST['group_id']), 'wp-types-user-group');
if (empty($update)) {
$update = false;
wpcf_admin_message(sprintf(__("Group with ID %d do not exist", 'wpcf'), intval($_REQUEST['group_id'])));
} else {
$update['fields'] = wpcf_admin_fields_get_fields_by_group($_REQUEST['group_id'], 'slug', false, true, false, 'wp-types-user-group', 'wpcf-usermeta');
$update['show_for'] = wpcf_admin_get_groups_showfor_by_group($_REQUEST['group_id']);
$update['admin_styles'] = wpcf_admin_get_groups_admin_styles_by_group($_REQUEST['group_id']);
}
}
$form = array();
$form['#form']['callback'] = array('wpcf_admin_save_usermeta_groups_submit');
// Form sidebars
$form['open-sidebar'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-form-fields-align-right">');
// Set help icon
$form['help-icon'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-admin-fields-help"><img src="' . WPCF_EMBEDDED_RELPATH . '/common/res/images/question.png" style="position:relative;top:2px;" /> <a href="http://wp-types.com/documentation/user-guides/using-custom-fields/" target="_blank">' . __('Usermeta help', 'wpcf') . '</a></div>');
$form['submit2'] = array('#type' => 'submit', '#name' => 'save', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary wpcf-disabled-on-submit'));
$form['fields'] = array('#type' => 'fieldset', '#title' => __('Available fields', 'wpcf'));
// Get field types
$fields_registered = wpcf_admin_fields_get_available_types();
foreach ($fields_registered as $filename => $data) {
$form['fields'][basename($filename, '.php')] = array('#type' => 'markup', '#markup' => '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax&wpcf_action=fields_insert' . '&field=' . basename($filename, '.php') . '&page=wpcf-edit-usermeta') . '&_wpnonce=' . wp_create_nonce('fields_insert') . '" ' . 'class="wpcf-fields-add-ajax-link button-secondary">' . $data['title'] . '</a> ');
// Process JS
if (!empty($data['group_form_js'])) {
foreach ($data['group_form_js'] as $handle => $script) {
if (isset($script['inline'])) {
add_action('admin_footer', $script['inline']);
continue;
}
$deps = !empty($script['deps']) ? $script['deps'] : array();
$in_footer = !empty($script['in_footer']) ? $script['in_footer'] : false;
wp_register_script($handle, $script['src'], $deps, WPCF_VERSION, $in_footer);
wp_enqueue_script($handle);
}
}
// Process CSS
if (!empty($data['group_form_css'])) {
foreach ($data['group_form_css'] as $handle => $script) {
if (isset($script['src'])) {
$deps = !empty($script['deps']) ? $script['deps'] : array();
wp_enqueue_style($handle, $script['src'], $deps, WPCF_VERSION);
} else {
if (isset($script['inline'])) {
add_action('admin_head', $script['inline']);
}
}
}
}
}
// Get fields created by user
$fields = wpcf_admin_fields_get_fields(true, true, false, 'wpcf-usermeta');
if (!empty($fields)) {
$form['fields-existing'] = array('#type' => 'fieldset', '#title' => __('User created fields', 'wpcf'), '#id' => 'wpcf-form-groups-user-fields');
foreach ($fields as $key => $field) {
if (isset($update['fields']) && array_key_exists($key, $update['fields'])) {
continue;
}
if (!empty($field['data']['removed_from_history'])) {
continue;
}
$form['fields-existing'][$key] = array('#type' => 'markup', '#markup' => '<div id="wpcf-user-created-fields-wrapper-' . $field['id'] . '" style="float:left; margin-right: 10px;"><a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax' . '&page=wpcf-edit' . '&wpcf_action=usermeta_insert_existing' . '&field=' . $field['id']) . '&_wpnonce=' . wp_create_nonce('usermeta_insert_existing') . '" ' . 'class="wpcf-fields-add-ajax-link button-secondary" onclick="jQuery(this).parent().fadeOut();" ' . 'data-slug="' . $field['id'] . '">' . htmlspecialchars(stripslashes($field['name'])) . '</a>' . '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax' . '&wpcf_action=remove_from_history2' . '&field_id=' . $field['id']) . '&_wpnonce=' . wp_create_nonce('remove_from_history2') . '&wpcf_warning=' . sprintf(__('Are you sure that you want to remove field %s from history?', 'wpcf'), htmlspecialchars(stripslashes($field['name']))) . '&wpcf_ajax_update=wpcf-user-created-fields-wrapper-' . $field['id'] . '" title="' . sprintf(__('Remove field %s', 'wpcf'), htmlspecialchars(stripslashes($field['name']))) . '" class="wpcf-ajax-link"><img src="' . WPCF_RES_RELPATH . '/images/delete-2.png" style="postion:absolute;margin-top:5px;margin-left:-4px;" /></a></div>');
}
}
$form['close-sidebar'] = array('#type' => 'markup', '#markup' => '</div>');
// Group data
$form['open-main'] = array('#type' => 'markup', '#markup' => '<div id="wpcf-form-fields-main">');
$form['title'] = array('#type' => 'textfield', '#name' => 'wpcf[group][name]', '#id' => 'wpcf-group-name', '#value' => $update ? $update['name'] : __('Enter group title', 'wpcf'), '#inline' => true, '#attributes' => array('style' => 'width:100%;margin-bottom:10px;'), '#validate' => array('required' => array('value' => true)));
if (!$update) {
$form['title']['#attributes']['data-label'] = addcslashes(__('Enter group title', 'wpcf'), '"');
$form['title']['#attributes']['onfocus'] = 'if (jQuery(this).val() == jQuery(this).data(\'label\')) { jQuery(this).val(\'\'); }';
$form['title']['#attributes']['onblur'] = 'if (jQuery(this).val() == \'\') { jQuery(this).val(jQuery(this).data(\'label\')) }';
}
$form['description'] = array('#type' => 'textarea', '#id' => 'wpcf-group-description', '#name' => 'wpcf[group][description]', '#value' => $update ? $update['description'] : __('Enter a description for this group', 'wpcf'));
if (!$update) {
$form['description']['#attributes']['data-label'] = addcslashes(__('Enter a description for this group', 'wpcf'), '"');
$form['description']['#attributes']['onfocus'] = 'if (jQuery(this).val() == jQuery(this).data(\'label\')) { jQuery(this).val(\'\'); }';
$form['description']['#attributes']['onblur'] = 'if (jQuery(this).val() == \'\') { jQuery(this).val(jQuery(this).data(\'label\')) }';
}
// Show Fields for
global $wp_roles;
$options = array();
$users_currently_supported = array();
$form_types = array();
foreach ($wp_roles->role_names as $role => $name) {
$options[$role]['#name'] = 'wpcf[group][supports][' . $role . ']';
$options[$role]['#title'] = ucwords($role);
//.........这里部分代码省略.........
示例5: wpcf_admin_fields_usermeta_styles
function wpcf_admin_fields_usermeta_styles()
{
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php';
require_once WPCF_EMBEDDED_INC_ABSPATH . '/usermeta-post.php';
$groups = wpcf_admin_fields_get_groups(TYPES_USER_META_FIELD_GROUP_CPT_NAME);
$content = '';
if (!empty($groups)) {
global $user_id;
$user_role = false;
if (!empty($user_id)) {
$user_info = get_userdata($user_id);
$user_role = isset($user_info->roles) ? array_shift($user_info->roles) : 'subscriber';
unset($user_info);
}
foreach ($groups as $group) {
if (!empty($user_id)) {
$for_users = wpcf_admin_get_groups_showfor_by_group($group['id']);
if (!empty($for_users) && !in_array($user_role, $for_users)) {
continue;
}
}
if (empty($group['is_active'])) {
continue;
}
$content .= str_replace("}", '}' . PHP_EOL, wpcf_admin_get_groups_admin_styles_by_group($group['id']));
$content .= PHP_EOL;
}
}
if ($content) {
printf('<style type="text/css">%s</style>%s', $content, PHP_EOL);
}
}
示例6: form
/**
* 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 form()
{
$this->save();
global $wpcf;
$this->current_user_can_edit = WPCF_Roles::user_can_create('user-meta-field');
// If it's update, get data
$this->update = false;
if (isset($_REQUEST[$this->get_id])) {
$this->update = wpcf_admin_fields_get_group(intval($_REQUEST[$this->get_id]), TYPES_USER_META_FIELD_GROUP_CPT_NAME);
$this->current_user_can_edit = WPCF_Roles::user_can_edit('user-meta-field', $this->update);
if (empty($this->update)) {
$this->update = false;
wpcf_admin_message(sprintf(__("Group with ID %d do not exist", 'wpcf'), intval($_REQUEST[$this->get_id])));
} else {
$this->update['fields'] = wpcf_admin_fields_get_fields_by_group(sanitize_text_field($_REQUEST[$this->get_id]), 'slug', false, true, false, TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta');
$this->update['show_for'] = wpcf_admin_get_groups_showfor_by_group(sanitize_text_field($_REQUEST[$this->get_id]));
if (defined('TYPES_USE_STYLING_EDITOR') && TYPES_USE_STYLING_EDITOR) {
$this->update['admin_styles'] = wpcf_admin_get_groups_admin_styles_by_group(sanitize_text_field($_REQUEST[$this->get_id]));
}
}
}
/**
* sanitize id
*/
if (!isset($this->update['id'])) {
$this->update['id'] = 0;
}
/**
* setup meta type
*/
$this->update['meta_type'] = 'custom_fields_group';
/**
* copy update to ct
*/
$this->ct = $this->update;
$form = $this->prepare_screen();
$form['_wpnonce_wpcf'] = array('#type' => 'markup', '#markup' => wp_nonce_field('wpcf_form_fields', '_wpnonce_wpcf', true, false));
/**
* nonce depend on group id
*/
$form['_wpnonce_' . $this->post_type] = array('#type' => 'markup', '#markup' => wp_nonce_field($this->get_nonce_action($this->update['id']), 'wpcf_save_group_nonce', true, false));
$form['form-open'] = array('#type' => 'markup', '#markup' => sprintf('<div id="post-body-content" class="%s">', $this->current_user_can_edit ? '' : 'wpcf-types-read-only'));
$form[$this->get_id] = array('#type' => 'hidden', '#name' => 'wpcf[group][id]', '#value' => $this->update['id']);
$form['table-1-open'] = array('#type' => 'markup', '#markup' => '<table id="wpcf-types-form-name-table" class="wpcf-types-form-table widefat js-wpcf-slugize-container"><thead><tr><th colspan="2">' . __('Field Group name and description', 'wpcf') . '</th></tr></thead><tbody>');
$table_row = '<tr><td><LABEL></td><td><ERROR><BEFORE><ELEMENT><AFTER></td></tr>';
$form['title'] = array('#title' => sprintf('%s <b>(%s)</b>', __('Field Group name', 'wpcf'), __('required', 'wpcf')), '#type' => 'textfield', '#name' => 'wpcf[group][name]', '#id' => 'wpcf-group-name', '#value' => $this->update['id'] ? $this->update['name'] : '', '#inline' => true, '#attributes' => array('class' => 'large-text', 'placeholder' => __('Enter group title', 'wpcf')), '#validate' => array('required' => array('value' => true)), '#pattern' => $table_row);
$form['description'] = array('#title' => __('Description', 'wpcf'), '#type' => 'textarea', '#id' => 'wpcf-group-description', '#name' => 'wpcf[group][description]', '#value' => $this->update['id'] ? $this->update['description'] : '', '#attributes' => array('placeholder' => __('Enter a description for this group', 'wpcf'), 'class' => 'hidden js-wpcf-description'), '#pattern' => $table_row, '#after' => sprintf('<a class="js-wpcf-toggle-description hidden" href="#">%s</a>', __('Add description', 'wpcf')), '#inline' => true);
$form['table-1-close'] = array('#type' => 'markup', '#markup' => '</tbody></table>');
/**
* fields
*/
$form += $this->fields();
$form['form-close'] = array('#type' => 'markup', '#markup' => '</div>', '_builtin' => true);
/**
* setup common setting for forms
*/
$form = $this->common_form_setup($form);
/**
* return form if current_user_can edit
*/
if ($this->current_user_can_edit) {
return $form;
}
return wpcf_admin_common_only_show($form);
}