Plugin Directory

Changeset 2681090


Ignore:
Timestamp:
02/17/2022 11:02:24 PM (4 years ago)
Author:
mintunmedia
Message:

v2.1.2 - updates to shortcodes

Location:
groups-for-membermouse
Files:
50 added
3 edited

Legend:

Unmodified
Added
Removed
  • groups-for-membermouse/trunk/groups-for-membermouse.php

    r2648097 r2681090  
    11<?php
    22
    3 /****************************************************************************************************************************
     3/**
    44 * Plugin Name: Groups for MemberMouse
    55 * Description: Adds group support to MemberMouse. You can define different types of groups allowing a single customer to pay for multiple seats and members to join existing groups for free or for a price based on how you configure the group type. <strong>Requires MemberMouse to activate and use.</strong>
    6  * Version: 2.1.1
     6 * Version: 2.1.2
    77 * Author: Mintun Media
    88 * Plugin URI:  https://www.mintunmedia.com
     
    1111 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1212 *
    13  ****************************************************************************************************************************/
     13 */
    1414
    1515if (!defined('ABSPATH')) exit; // Exit if accessed directly
     
    947947
    948948        /**
     949         * Get Group ID with a Members User ID
     950         * @return object | bool - If Group is found, returns row from database. If not, returns false
     951         */
     952        public function get_group_from_member_id($memberId) {
     953            write_groups_log(__METHOD__);
     954            global $wpdb;
     955            $sql = "SELECT * FROM " . $wpdb->prefix . "group_sets_members WHERE member_id='" . $memberId . "' ORDER BY member_status DESC, createdDate DESC";
     956            $result = $wpdb->get_row($sql);
     957            return $result;
     958        }
     959
     960        /**
     961         * Get List of Members in a Group
     962         * @param string $group_id is the group ID you want to get the list of members from
     963         * @return object | bool - If Group is found, returns row of members from database. If not, returns false
     964         */
     965        public function get_members_in_group($group_id) {
     966            write_groups_log(__METHOD__);
     967            global $wpdb;
     968            $sql = "SELECT * FROM " . $wpdb->prefix . "group_sets_members WHERE group_id = '" . $group_id . "' AND member_status=1 ORDER BY member_status DESC, createdDate DESC";
     969            $result = $wpdb->get_results($sql);
     970            return $result;
     971        }
     972
     973        /**
    949974         * Get Group Template from Group Template ID
    950975         * @param int $group_template_id
  • groups-for-membermouse/trunk/includes/class.shortcodes.php

    r2642052 r2681090  
    7070  public function load_shortcodes() {
    7171    add_shortcode('MM_Group_Leader_Dashboard', array($this, 'generate_group_leader_dashboard'));
     72    add_shortcode('MM_Group_Member_List', array($this, 'generate_group_member_list'));
    7273  }
    7374
     
    7879   * @return void
    7980   */
    80   public function generate_group_leader_dashboard() {
     81  public function generate_group_leader_dashboard($atts) {
    8182    global $wpdb, $current_user;
     83
     84    $controls = array(
     85      'signup-link' => 'show',
     86      'add-member' => 'show',
     87      'action-column' => 'show',
     88    );
     89
     90    $atts = shortcode_atts($controls, $atts, 'MM_Group_Leader_Dashboard');
     91
     92    $signup_link_content = '<button class="btn primary-btn" title="Signup Link" id="signup-link">Signup Link</button>';
     93    $add_member_content = '<button class="btn primary-btn" title="Add a Member" id="add-member">Add Member</button>';
     94    $action_header_content = '<th>Actions</th>';
     95
     96    $signup_link_control = $atts['signup-link'];
     97    $add_member_control = $atts['add-member'];
     98    $action_control = $atts['action-column'];
    8299
    83100    $groups = new MemberMouseGroupAddon();
     
    120137    <div class="groups-button-container">
    121138      <button class="btn primary-btn" title="Edit Group Name" id="edit-group-name">Edit Group Name</button>
    122       <button class="btn primary-btn" title="Signup Link" id="signup-link">Signup Link</button>
    123       <button class="btn primary-btn" title="Add a Member" id="add-member">Add Member</button>
     139      <?php if ($signup_link_control != 'hide') {
     140        echo $signup_link_content;
     141      }
     142      if ($add_member_control != 'hide') {
     143        echo $add_member_content;
     144      } ?>
    124145    </div>
    125146
     
    139160            <th>Registered</th>
    140161            <th>Status</th>
    141             <th>Actions</th>
     162            <?php if ($action_control != 'hide') {
     163              echo $action_header_content;
     164            } ?>
    142165          </tr>
    143166        </thead>
     
    190213              <td><?php echo date('F d, Y h:m a', strtotime($registered)); ?></td>
    191214              <td><?= $status; ?></td>
    192               <td>
    193                 <?php
    194                 if ($has_subscriptions) {
    195                   // Member has active subscriptions. Show error
    196                   echo $cancellationHtml;
    197                   echo MM_Utils::getDeleteIcon("This member has an active paid membership which must be canceled before they can be removed from the group. Please contact support.", 'margin-left:5px;', '', true);
    198                 } else if ($statusId === 1) {
    199                   $deleteActionUrl = 'href="#" class="delete-member" data-member-id="' .  $gMemRes->member_id . '" data-name="' . $firstName . ' ' . $lastName . '"';
    200                   echo MM_Utils::getDeleteIcon("Remove the member from this group", 'margin-left:5px;', $deleteActionUrl);
    201                 }
    202                 ?>
    203               </td>
     215              <?php if ($action_control != 'hide') { ?>
     216                <td>
     217                  <?php
     218                  if ($has_subscriptions) {
     219                    // Member has active subscriptions. Show error
     220                    echo $cancellationHtml;
     221                    echo MM_Utils::getDeleteIcon("This member has an active paid membership which must be canceled before they can be removed from the group. Please contact support.", 'margin-left:5px;', '', true);
     222                  } else if ($statusId === 1) {
     223                    $deleteActionUrl = 'href="#" class="delete-member" data-member-id="' .  $gMemRes->member_id . '" data-name="' . $firstName . ' ' . $lastName . '"';
     224                    echo MM_Utils::getDeleteIcon("Remove the member from this group", 'margin-left:5px;', $deleteActionUrl);
     225                  }
     226                  ?>
     227                </td>
     228              <?php } ?>
    204229            </tr>
    205230          <?php endforeach; ?>
     
    248273        </table>
    249274      </div>
    250 <?php
     275    <?php
    251276    endif;
     277
     278    return ob_get_clean();
     279  }
     280
     281
     282  /**
     283   * SHORTCODE - Group Member List [MM_Group_Member_List]
     284   * Outputs the Group Member List on front end as a table
     285   *
     286   * @return void
     287   */
     288  public function generate_group_member_list() {
     289
     290    // Do nothing if visitor is not logged in
     291    if (!is_user_logged_in()) {
     292      return 'You must be logged in to view this.';
     293    }
     294
     295    global $wpdb, $current_user;
     296
     297    $groups = new MemberMouseGroupAddon();
     298    $group_row = $groups->get_group_from_member_id($current_user->ID);
     299
     300    // Check if current user is a group leader
     301    if (!$group_row) {
     302      return 'You must be a group member to view this.';
     303    }
     304
     305    $gid = $group_row->group_id;
     306
     307    // Check if current group is active
     308    if ($group_row && !$groups->is_group_active($gid)) {
     309      return 'Your group is no longer active.';
     310    }
     311
     312    wp_enqueue_style('groups-leader-dashboard');
     313    wp_enqueue_script('groups-leader-dashboard');
     314    wp_enqueue_script('sweetalert');
     315
     316    $gMemResults = $groups->get_members_in_group($gid);
     317
     318    ob_start();
     319
     320    if (!$gMemResults) { ?>
     321      <p><em>No members found.</em></p>
     322    <?php } else { ?>
     323      <table class="widefat" id="mm-data-grid" style="width:96%">
     324        <thead>
     325          <tr>
     326            <th>Name</th>
     327            <th>Email</th>
     328            <th>Phone</th>
     329            <th>Registered</th>
     330            <th>Status</th>
     331          </tr>
     332        </thead>
     333        <tbody>
     334          <?php foreach ($gMemResults as $gMemRes) :
     335            $userSql      = "SELECT * FROM " . $wpdb->prefix . "users WHERE ID = '" . $gMemRes->member_id . "'";
     336            $userResult    = $wpdb->get_row($userSql);
     337            $registered    = $userResult->user_registered;
     338            $memSql        = "SELECT * FROM mm_user_data WHERE wp_user_id = '" . $gMemRes->member_id . "'";
     339            $memResult    = $wpdb->get_row($memSql);
     340            $firstName     = $memResult->first_name;
     341            $lastName     = $memResult->last_name;
     342            $email         = $userResult->user_email;
     343            $phone         = empty($memResult->phone) ? "&mdash;" : $memResult->phone;
     344            $statusId = (int) $gMemRes->member_status;
     345
     346            switch ($statusId) {
     347              case 1:
     348                $status = "Active";
     349                break;
     350              case 0:
     351                $status = "Deactivated";
     352                break;
     353            }
     354
     355          ?>
     356            <tr class="<?= strtolower($status) ?>">
     357              <td><?php echo $firstName . '&nbsp;' . $lastName; ?></td>
     358              <td><?php echo $email; ?></td>
     359              <td><?php echo $phone; ?></td>
     360              <td><?php echo date('F d, Y h:m a', strtotime($registered)); ?></td>
     361              <td><?= $status; ?></td>
     362            </tr>
     363          <?php endforeach; ?>
     364        </tbody>
     365      </table>
     366<?php }
    252367
    253368    return ob_get_clean();
  • groups-for-membermouse/trunk/readme.txt

    r2648097 r2681090  
    4949
    5050__Group Leader Management Page__
    51 `[MM_Group_Leader_Dashboard]`
     51`[MM_Group_Leader_Dashboard signup-link='hide' add-member='show' action-column='hide']`
    5252You can add the front-end Group Leader Dashboard to any page with this shortcode! This dashboard allows your Group Leaders to add members, delete members, grab their group sign up link and see all the members in their group.
     53
     54Shortcode Attributes aren't required. They default to "show". If you want to hide them, you can set them to "hide"
     55
     56__Group Member View Only Listing__
     57`[MM_Group_Member_List]`
     58Displays a member list (like the Group Leader Dashboard but without admin features) for members of the group to view other members.
    5359
    5460== Installation ==
     
    6369
    6470== Changelog ==
     71* 2.1.2
     72- ENHANCEMENT: Updated group leader dashboard shortcode to allow showing/hiding elements. Updated
     73- ENHANCEMENT: Added a View Only member dashboard shortcode visible by members
     74
    65752.1.1 Added filter to change group leader role and group leader name: `add_filter('groupsmm_group_leader_role_slug')`, `add_filter('groupsmm_group_leader_role_name')`
    6676
Note: See TracChangeset for help on using the changeset viewer.