/** * Loads scripts. */ public static function admin_print_scripts() { global $groups_version; // this one's currently empty //wp_enqueue_script( 'groups_admin', GROUPS_PLUGIN_URL . 'js/groups_admin.js', array( ), $groups_version ); Groups_UIE::enqueue('select'); }
/** * Enqueues the select script. */ public static function admin_enqueue_scripts() { global $pagenow; if ($pagenow == 'edit.php') { $post_type = isset($_GET['post_type']) ? $_GET['post_type'] : 'post'; $post_types_option = Groups_Options::get_option(Groups_Post_Access::POST_TYPES, array()); if (!isset($post_types_option[$post_type]['add_meta_box']) || $post_types_option[$post_type]['add_meta_box']) { Groups_UIE::enqueue('select'); } } }
/** * Enqueues the select script on the product screen. * Groups' Access Restrictions meta box already does that as well but for * the sake of consistency and in case it were not loaded by that ... */ public static function admin_enqueue_scripts() { $screen = get_current_screen(); if (isset($screen->id)) { switch ($screen->id) { case 'product': require_once GROUPS_VIEWS_LIB . '/class-groups-uie.php'; Groups_UIE::enqueue('select'); break; } } }
/** * Enqueue scripts the group-actions. */ public static function admin_enqueue_scripts() { global $pagenow; if ($pagenow == 'users.php' && empty($_GET['page'])) { Groups_UIE::enqueue('select'); } }
/** * Render capabilities box for attachment post type (Media). * @param array $form_fields * @param object $post * @return array */ public static function attachment_fields_to_edit($form_fields, $post) { Groups_UIE::enqueue('select'); $post_types_option = Groups_Options::get_option(Groups_Post_Access::POST_TYPES, array()); if (!isset($post_types_option['attachment']['add_meta_box']) || $post_types_option['attachment']['add_meta_box']) { if (self::user_can_restrict()) { $user = new Groups_User(get_current_user_id()); $output = ""; $post_singular_name = __('Media', GROUPS_PLUGIN_DOMAIN); $output .= __("Enforce read access", GROUPS_PLUGIN_DOMAIN); $read_caps = get_post_meta($post->ID, Groups_Post_Access::POSTMETA_PREFIX . Groups_Post_Access::READ_POST_CAPABILITY); $valid_read_caps = self::get_valid_read_caps_for_user(); // On attachments edited within the 'Insert Media' popup, the update is triggered too soon and we end up with only the last capability selected. // This occurs when using normal checkboxes as well as the select below (Chosen and Selectize tested). // With checkboxes it's even more confusing, it's actually better to have it using a select as below, // because the visual feedback corresponds with what is assigned. // See http://wordpress.org/support/topic/multiple-access-restrictions-for-media-items-are-not-saved-in-grid-view // and https://core.trac.wordpress.org/ticket/28053 - this is an issue with multiple value fields and should // be fixed within WordPress. // $output .= '<div style="padding:0 1em;margin:1em 0;border:1px solid #ccc;border-radius:4px;">'; // $output .= '<ul>'; // foreach( $valid_read_caps as $valid_read_cap ) { // if ( $capability = Groups_Capability::read_by_capability( $valid_read_cap ) ) { // $checked = in_array( $capability->capability, $read_caps ) ? ' checked="checked" ' : ''; // $output .= '<li>'; // $output .= '<label>'; // $output .= '<input name="attachments[' . $post->ID . '][' . self::CAPABILITY . '][]" ' . $checked . ' type="checkbox" value="' . esc_attr( $capability->capability_id ) . '" />'; // $output .= wp_filter_nohtml_kses( $capability->capability ); // $output .= '</label>'; // $output .= '</li>'; // } // } // $output .= '</ul>'; // $output .= '</div>'; $show_groups = Groups_Options::get_user_option(self::SHOW_GROUPS, true); $output .= '<div class="select-capability-container">'; $select_id = 'attachments-' . $post->ID . '-' . self::CAPABILITY; $output .= sprintf('<select id="%s" class="select capability" name="%s" multiple="multiple" data-placeholder="%s" title="%s">', $select_id, 'attachments[' . $post->ID . '][' . self::CAPABILITY . '][]', __('Type and choose …', GROUPS_PLUGIN_DOMAIN), __('Choose one or more capabilities to restrict access. Groups that grant access through the capabilities are shown in parenthesis. If no capabilities are available yet, you can use the quick-create box to create a group and capability enabled for access restriction on the fly.', GROUPS_PLUGIN_DOMAIN)); $output .= '<option value=""></option>'; foreach ($valid_read_caps as $valid_read_cap) { if ($capability = Groups_Capability::read_by_capability($valid_read_cap)) { if ($user->can($capability->capability)) { $c = new Groups_Capability($capability->capability_id); $groups = $c->groups; $group_names = array(); if (!empty($groups)) { foreach ($groups as $group) { $group_names[] = $group->name; } } if (count($group_names) > 0) { $label_title = sprintf(_n('Members of the %1$s group can access this %2$s through this capability.', 'Members of the %1$s groups can access this %2$s through this capability.', count($group_names), GROUPS_PLUGIN_DOMAIN), wp_filter_nohtml_kses(implode(',', $group_names)), $post_singular_name); } else { $label_title = __('No groups grant access through this capability. To grant access to group members using this capability, you should assign it to a group and enable the capability for access restriction.', GROUPS_PLUGIN_DOMAIN); } $output .= sprintf('<option value="%s" %s>', esc_attr($capability->capability_id), in_array($capability->capability, $read_caps) ? ' selected="selected" ' : ''); $output .= wp_filter_nohtml_kses($capability->capability); if ($show_groups) { if (count($group_names) > 0) { $output .= ' '; $output .= '(' . wp_filter_nohtml_kses(implode(', ', $group_names)) . ')'; } } $output .= '</option>'; } } } $output .= '</select>'; $output .= Groups_UIE::render_select('#' . $select_id); $output .= '</div>'; $output .= '<p class="description">'; $output .= sprintf(__("Only groups or users that have one of the selected capabilities are allowed to read this %s.", GROUPS_PLUGIN_DOMAIN), $post_singular_name); $output .= '</p>'; $form_fields['groups_access'] = array('label' => __('Access restrictions', GROUPS_PLUGIN_DOMAIN), 'input' => 'html', 'html' => $output); } } return $form_fields; }