コード例 #1
0
 /**
  * Manage user account actions.
  *
  * @since  1.0.0
  * @internal
  */
 public function user_account_manager()
 {
     $action = $this->get_action();
     $member = MS_Model_Member::get_current_member();
     /**
      * These actions are always executed when any user account page loads.
      *
      * @since  1.0.1.0
      */
     do_action('ms_frontend_user_account_manager-' . $action, $this);
     do_action('ms_frontend_user_account_manager', $action, $this);
     if ($this->verify_nonce()) {
         /**
          * The following two actions are only executed when a form was
          * submitted on a user account page.
          *
          * @since  1.0.1.0
          */
         do_action('ms_frontend_user_account_manager_submit-' . $action, $this);
         do_action('ms_frontend_user_account_manager_submit', $action, $this);
     }
     switch ($action) {
         case self::ACTION_EDIT_PROFILE:
             $data = array();
             if ($this->verify_nonce()) {
                 if (is_array($_POST)) {
                     foreach ($_POST as $field => $value) {
                         $member->{$field} = $value;
                     }
                 }
                 try {
                     $member->validate_member_info();
                     $member->save();
                     wp_safe_redirect(esc_url_raw(remove_query_arg('action')));
                     exit;
                 } catch (Exception $e) {
                     $data['errors'] = $e->getMessage();
                 }
             }
             $view = MS_Factory::create('MS_View_Frontend_Profile');
             $data['member'] = $member;
             $data['action'] = $action;
             $view->data = apply_filters('ms_view_frontend_profile_data', $data, $this);
             $view->add_filter('the_content', 'to_html', 1);
             break;
         case self::ACTION_VIEW_INVOICES:
             $data['invoices'] = MS_Model_Invoice::get_public_invoices($member->id);
             $view = MS_Factory::create('MS_View_Frontend_Invoices');
             $view->data = apply_filters('ms_view_frontend_frontend_invoices', $data, $this);
             $view->add_filter('the_content', 'to_html', 1);
             break;
         case self::ACTION_VIEW_ACTIVITIES:
             $data['events'] = MS_Model_Event::get_events(array('author' => $member->id, 'posts_per_page' => -1));
             $view = MS_Factory::create('MS_View_Frontend_Activities');
             $view->data = apply_filters('ms_view_frontend_frontend_activities', $data, $this);
             $view->add_filter('the_content', 'to_html', 1);
             break;
         case self::ACTION_VIEW_RESETPASS:
             /**
              * Reset password action.
              * This action is accessed via the password-reset email
              * @see  class-ms-controller-dialog.php
              *
              * The action is targeted to the Account-page but actually calls
              * the Login-Shortcode.
              */
             $view = MS_Factory::create('MS_View_Shortcode_Login');
             $view->data = array('action' => 'resetpass');
             $view->add_filter('the_content', 'to_html', 1);
             break;
         default:
             // Do nothing...
             break;
     }
 }
コード例 #2
0
 /**
  * Membership account page shortcode callback function.
  *
  * @since  1.0.0
  *
  * @param mixed[] $atts Shortcode attributes.
  */
 public function membership_account($atts)
 {
     MS_Helper_Shortcode::did_shortcode(MS_Helper_Shortcode::SCODE_MS_ACCOUNT);
     $data = apply_filters('ms_controller_shortcode_membership_account_atts', shortcode_atts(array('show_membership' => true, 'show_membership_change' => true, 'membership_title' => __('Your Membership', 'membership2'), 'membership_change_label' => __('Change', 'membership2'), 'show_profile' => true, 'show_profile_change' => true, 'profile_title' => __('Personal details', 'membership2'), 'profile_change_label' => __('Edit', 'membership2'), 'show_invoices' => true, 'limit_invoices' => 10, 'show_all_invoices' => true, 'invoices_title' => __('Invoices', 'membership2'), 'invoices_details_label' => __('View all', 'membership2'), 'show_activity' => true, 'limit_activities' => 10, 'show_all_activities' => true, 'activity_title' => __('Activities', 'membership2'), 'activity_details_label' => __('View all', 'membership2')), $atts));
     $data['show_membership'] = lib3()->is_true($data['show_membership']);
     $data['show_membership_change'] = lib3()->is_true($data['show_membership_change']);
     $data['show_profile'] = lib3()->is_true($data['show_profile']);
     $data['show_profile_change'] = lib3()->is_true($data['show_profile_change']);
     $data['show_invoices'] = lib3()->is_true($data['show_invoices']);
     $data['show_all_invoices'] = lib3()->is_true($data['show_all_invoices']);
     $data['show_activity'] = lib3()->is_true($data['show_activity']);
     $data['show_all_activities'] = lib3()->is_true($data['show_all_activities']);
     $data['limit_invoices'] = absint($data['limit_invoices']);
     $data['limit_activities'] = absint($data['limit_activities']);
     $data['member'] = MS_Model_Member::get_current_member();
     $data['membership'] = array();
     $subscriptions = MS_Model_Relationship::get_subscriptions(array('user_id' => $data['member']->id, 'status' => 'all'));
     if (is_array($subscriptions)) {
         foreach ($subscriptions as $subscription) {
             // Do not display system-memberships in Account
             if ($subscription->is_system()) {
                 continue;
             }
             // Do not display deactivated memberships in Account
             if ($subscription->get_status() == MS_Model_Relationship::STATUS_DEACTIVATED) {
                 continue;
             }
             $data['subscription'][] = $subscription;
         }
     }
     $data['invoices'] = MS_Model_Invoice::get_public_invoices($data['member']->id, $data['limit_invoices']);
     $data['events'] = MS_Model_Event::get_events(array('author' => $data['member']->id, 'posts_per_page' => $data['limit_activities']));
     $view = MS_Factory::create('MS_View_Shortcode_Account');
     $view->data = apply_filters('ms_view_shortcode_account_data', $data, $this);
     return $view->to_html();
 }