public static function wpcf_create_new_cap() { if (!current_user_can('manage_options')) { _e('There are security problems. You do not have permissions.', 'wpcf-access'); die; } if (!isset($_POST['wpnonce']) || !wp_verify_nonce($_POST['wpnonce'], 'wpcf-access-error-pages')) { die('verification failed'); } $custom_caps = get_option('wpcf_access_custom_caps'); if (!is_array($custom_caps)) { $custom_caps = array(); } $output = ''; $model = TAccess_Loader::get('MODEL/Access'); $default_caps = getDefaultCaps(); $default_wordpress_caps = getDefaultWordpressCaps(); $wocommerce_caps = get_woocommerce_caps(); $wpml_caps_list = get_wpml_caps(); $cap = sanitize_text_field($_POST['cap_name']); $description = sanitize_text_field($_POST['cap_description']); if (isset($custom_caps[$cap]) || isset($default_wordpress_caps[$cap]) || isset($wocommerce_caps[$cap]) || isset($wpml_caps_list[$cap])) { $output = array('error', __('This capability already exists in your site', 'wpcf-access')); } else { $custom_caps[$cap] = $description; update_option('wpcf_access_custom_caps', $custom_caps); $input = '<p id="wpcf-custom-cap-' . $cap . '"><label for="cap_' . $cap . '"><input type="checkbox" name="current_role_caps[]" value="cap_' . $cap . '" id="cap_' . $cap . '" checked="checked"> ' . $cap . '<br><small>' . $description . '</small></label>' . '<span class="js-wpcf-remove-custom-cap js-wpcf-remove-custom-cap_' . $cap . '">' . '<a href="" data-object="wpcf-custom-cap-' . $cap . '" data-remove="0" data-cap="' . $cap . '">Delete</a><span class="ajax-loading spinner"></span>' . '</span>' . '</p>'; $output = array(1, $input); } echo json_encode($output); die; }
function wpcf_access_general_capabilities($data) { $wp_roles['label'] = __('General capabilities', 'wpcf-access'); $wp_roles['capabilities'] = getDefaultWordpressCaps(); $data[] = $wp_roles; return $data; }