/** * Renders meta boxes. * * @param type $post * @param type $args */ public static function wpcf_access_post_meta_box($post, $args) { $model = TAccess_Loader::get('MODEL/Access'); $meta = $model->getAccessMeta($post->ID); //get_post_meta($post->ID, '_types_access', true); $area = $args['args'][0]; $roles = $args['args'][1]; //wpcf_get_editable_roles(); $output = ''; $groups = array(); $groups = apply_filters('types-access-show-ui-group', $groups, $area['id']); foreach ($groups as $group) { $output .= '<div class="wpcf-access-type-item">'; $output .= '<div class="wpcf-access-mode">'; $caps = array(); $caps = apply_filters('types-access-show-ui-cap', $caps, $area['id'], $group['id']); $saved_data = array(); foreach ($caps as $cap_slug => $cap) { if (isset($cap['default_role'])) { $caps[$cap_slug]['role'] = $cap['role'] = $cap['default_role']; } $saved_data[$cap['cap_id']] = is_array($meta) && isset($meta[$area['id']][$group['id']]['permissions'][$cap['cap_id']]) ? $meta[$area['id']][$group['id']]['permissions'][$cap['cap_id']] : array('role' => $cap['role']); } if (isset($cap['style']) && $cap['style'] == 'dropdown') { } else { $output .= Access_Admin_Edit::wpcf_access_permissions_table($roles, $saved_data, $caps, $area['id'], $group['id']); } $output .= '</div>'; $output .= '</div>'; } echo $output; }
public static function wpcf_process_new_access_group_ajax() { 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'); } $nice = sanitize_title('wpcf-custom-group-' . $_POST['title']); $posts = array(); if (isset($_POST['posts'])) { $posts = array_map('intval', $_POST['posts']); } $model = TAccess_Loader::get('MODEL/Access'); $settings_access = $model->getAccessTypes(); $groups[$nice] = array('title' => sanitize_text_field($_POST['title']), 'mode' => 'permissions', '__permissions' => array('read' => array('role' => 'guest')), 'permissions' => array('read' => array('role' => 'guest'))); $process = true; if (!empty($settings_access)) { foreach ($settings_access as $permission_slug => $data) { if ($permission_slug == $nice) { $process = false; } } } if (!$process) { echo 'error'; die; } for ($i = 0, $limit = count($posts); $i < $limit; $i++) { update_post_meta($posts[$i], '_wpcf_access_group', $nice); } TAccess_Loader::load('CLASS/Admin_Edit'); $roles = Access_Helper::wpcf_get_editable_roles(); $settings_access = array_merge($settings_access, $groups); $model->updateAccessTypes($settings_access); $enabled = true; $group['id'] = $nice; $group['name'] = sanitize_text_field($_POST['title']); $group_divid = str_replace('%', '', $nice); $output = '<a name="' . $group['id'] . '"></a>'; $output .= '<div class="wpcf-access-type-item is-enabled" id="js-box-' . $group_divid . '">'; $output .= '<h4>' . $group['name'] . '</h4>'; $output .= '<div class="wpcf-access-mode">'; $caps = array(); $saved_data = array(); $saved_data['read'] = array('role' => 'guest'); $group_data = $groups[$nice]; $def = array('read' => array('title' => __('Read', 'wpcf-access'), 'role' => 'guest', 'predefined' => 'read', 'cap_id' => 'group')); $output .= Access_Admin_Edit::wpcf_access_permissions_table($roles, $saved_data, $def, 'types', $group['id'], $enabled, 'permissions', $group_data); $output .= '<p class="wpcf-access-buttons-wrap">'; $output .= '<span class="ajax-loading spinner"></span>'; $output .= '<input data-group="' . $nice . '" data-groupdiv="' . esc_attr($group_divid) . '" type="button" value="' . esc_attr(__('Modify Group', 'wpcf-access')) . '" class="js-wpcf-modify-group button-secondary" /> '; $output .= '<input data-group="' . $nice . '" data-groupdiv="' . esc_attr($group_divid) . '" type="button" value="' . esc_attr(__('Remove Group', 'wpcf-access')) . '" class="button-secondary js-wpcf-remove-group" /> '; $output .= Access_Admin_Edit::wpcf_access_submit_button($enabled, true, $group['name']); $output .= '</p>'; $output .= '<input type="hidden" name="groupvalue-' . $nice . '" value="' . esc_attr($_POST['title']) . '">'; $output .= '</div> <!-- .wpcf-access-mode -->'; // $output .= '<p class="wpcf-access-top-anchor"><a href="#wpcf-access-top-anchor">'. __('Back to Top', 'wpcf-access') .'</a></p>'; $output .= '</div> <!-- .wpcf-access-type-item -->'; echo $output; die; }
/** * Menu page render hook. */ public static function wpcf_access_admin_menu_page() { TAccess_Loader::load('CLASS/Admin_Edit'); echo "\r\n" . '<div class="wrap"> <div id="icon-wpcf-access" class="icon32"><br /></div> <h2>' . __('Access', 'wpcf-access') . '</h2>' . "\r\n"; Access_Admin_Edit::wpcf_access_admin_edit_access(); echo "\r\n" . '</div>' . "\r\n"; }