/** * Return an array of registered user roles for use in a Visual Composer param. * * @since 1.0.0 * * @param string $context The context to pass to our filter. * * @return array The array of user roles. */ function mm_get_user_roles_for_vc($context = '') { return array_flip(mm_get_user_roles($context)); }
/** * Register UI for Shortcake. * * @since 1.0.0 */ function mm_components_mm_users_shortcode_ui() { if (!function_exists('shortcode_ui_register_for_shortcode')) { return; } $roles = mm_get_user_roles('mm-users'); $templates = mm_get_mm_users_templates('mm-users'); $wrap_elements = mm_get_wrap_elements('mm-users'); shortcode_ui_register_for_shortcode('mm_users', array('label' => esc_html__('Mm Users', 'mm-components'), 'listItemImage' => MM_COMPONENTS_ASSETS_URL . 'component-icon.png', 'attrs' => array(array('label' => esc_html__('User Role', 'mm-components'), 'description' => esc_html__('Select a specific user role to only include users with that role', 'mm-components'), 'attr' => 'role', 'type' => 'select', 'options' => $roles), array('label' => esc_html('Users Per Page', 'mm-components'), 'description' => esc_html__('Specify the maximum number of users to show at once.', 'mm-components'), 'attr' => 'number', 'value' => 10, 'type' => 'text'), array('label' => esc_html__('Pagination', 'mm-components'), 'attr' => 'pagination', 'type' => 'select', 'options' => array('' => esc_html__('None', 'mm-components'), 'next-prev' => esc_html__('Next/Prev', 'mm-components'), 'page-numbers' => esc_html__('Page Numbers', 'mm-components'))), array('label' => esc_html__('Template', 'mm-components'), 'description' => esc_html__('Select a template', 'mm-components'), 'attr' => 'template', 'type' => 'select', 'options' => $templates), array('label' => esc_html__('Wrap Element', 'mm-components'), 'description' => esc_html__('Select a wrap element', 'mm-components'), 'attr' => 'wrap_element', 'type' => 'select', 'options' => $wrap_elements), array('label' => esc_html('User ID', 'mm-components'), 'description' => esc_html__('Enter a user ID to display a single user', 'mm-components'), 'attr' => 'user_id', 'type' => 'text')))); }
/** * Output the Widget settings form. * * @since 1.0.0 * * @param array $instance The options for the widget instance. */ public function form($instance) { $defaults = array('title' => '', 'specific_roles' => '', 'roles' => '', 'restricted_content' => '', 'other_content' => '', 'mm_custom_class' => ''); // Use our instance args if they are there, otherwise use the defaults. $instance = wp_parse_args($instance, $defaults); $title = $instance['title']; $specific_roles = $instance['specific_roles']; $roles = $instance['roles']; $restricted_content = $instance['restricted_content']; $other_content = $instance['other_content']; $mm_custom_class = $instance['mm_custom_class']; $classname = $this->options['classname']; // Title. $this->field_text(__('Title:', 'mm-components'), '', $classname . '-title widefat', 'title', $title); // Specific Roles. $this->field_checkbox(__('Restrict to specific user roles?', 'mm-components'), __('By default only logged in users will see the restricted content. Check this to further restrict to specific user roles.', 'mm-components'), $classname . '-specific-roles widefat', 'specific_roles', $specific_roles, array('Yes')); // User roles. $this->field_multi_checkbox(__('Allowed user roles.', 'mm-components'), __('Select the user role(s) that should be allowed to view the restricted content.', 'mm-components'), $classname . '-roles widefat', 'roles', $roles, mm_get_user_roles('mm-restricted-content')); // Restricted content. $this->field_textarea(__('Restricted content for users with the selected role(s):', 'mm-components'), '', $classname . '-restricted-content widefat', 'restricted_content', $restricted_content); // Other content. $this->field_textarea(__('Optional content for all other users:', 'mm-components'), __('The content entered here will be shown to users who do not meet the criteria set above. HTML and shortcodes are allowed.', 'mm-components'), $classname . '-other-content widefat', 'other_content', $other_content); // Custom class. $this->field_text(__('Custom class:', 'mm-components'), '', $classname . '-mm-custom-class widefat', 'mm_custom_class', $mm_custom_class); }