Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/paid-memberships-pro/adminpages/member-edit.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + /**
4 + * Get the panels to display on the member edit page.
5 + *
6 + * @since 3.0
7 + *
8 + * @return array
9 + */
10 + function pmpro_member_edit_get_panels() {
11 + // Add default panels.
12 + $panels = array();
13 + $panels[] = new PMPro_Member_Edit_Panel_User_Info();
14 + $panels[] = new PMPro_Member_Edit_Panel_Memberships();
15 + $panels[] = new PMPro_Member_Edit_Panel_Subscriptions();
16 + $panels[] = new PMPro_Member_Edit_Panel_Orders();
17 + $panels[] = new PMPro_Member_Edit_Panel_TOS();
18 +
19 + // Add user fields panels.
20 + $user_id = PMPro_Member_Edit_Panel::get_user()->ID;
21 + if ( $user_id ) {
22 + foreach( PMPro_Field_Group::get_all() as $group ) {
23 + $fields_to_display = $group->get_fields_to_display(
24 + array(
25 + 'scope' => 'profile',
26 + 'user_id' => $user_id,
27 + )
28 + );
29 +
30 + if ( empty( $fields_to_display ) ) {
31 + continue;
32 + }
33 +
34 + $panels[] = new PMPro_Member_Edit_Panel_User_Fields( $group->name );
35 + }
36 + }
37 +
38 + /**
39 + * Filter to add/edit panels on the member edit page.
40 + *
41 + * @since 3.0
42 + *
43 + * @param array $panels The panels to display on the member edit page.
44 + */
45 + $panels = apply_filters( 'pmpro_member_edit_panels', $panels );
46 +
47 + // Build array to return with slug as key.
48 + $panels_return = array();
49 + foreach ( $panels as $panel ) {
50 + $panels_return[ $panel->get_slug() ] = $panel;
51 + }
52 +
53 + // Return panels.
54 + return $panels_return;
55 + }
56 +
57 + /**
58 + * Display the member edit page.
59 + *
60 + * @since 3.0
61 + */
62 + function pmpro_member_edit_display() {
63 + global $current_user;
64 +
65 + // Get the user that we are editing.
66 + $user = PMPro_Member_Edit_Panel::get_user();
67 +
68 + // Define a constant if user is editing their own membership.
69 + if ( ! defined( 'IS_PROFILE_PAGE' ) ) {
70 + define( 'IS_PROFILE_PAGE', ( $user->ID === $current_user->ID ) );
71 + }
72 +
73 + $panels = pmpro_member_edit_get_panels();
74 +
75 + // Get the panel to default to.
76 + $default_panel_slug = 'user-info';
77 + if ( ! empty( $user->ID ) && ! empty( $_REQUEST['pmpro_member_edit_panel'] ) && ! empty( $panels[ $_REQUEST['pmpro_member_edit_panel'] ] ) ) {
78 + $default_panel_slug = sanitize_text_field( $_REQUEST['pmpro_member_edit_panel'] );
79 + }
80 +
81 + /**
82 + * Load the Paid Memberships Pro dashboard-area header
83 + */
84 + require_once( PMPRO_DIR . '/adminpages/admin_header.php' ); ?>
85 +
86 + <hr class="wp-header-end">
87 + <h1 class="wp-heading-inline">
88 + <?php
89 + if ( ! empty( $user->ID ) ) {
90 + echo get_avatar( $user->ID, 96 );
91 + echo wp_kses_post( sprintf( esc_html__( 'Edit Member: %s', 'paid-memberships-pro' ), '<strong>' . $user->display_name . '</strong>' ) );
92 + } else {
93 + echo esc_html_e( 'Add Member', 'paid-memberships-pro' );
94 + }
95 + ?>
96 + </h1>
97 +
98 + <?php pmpro_showMessage(); ?>
99 +
100 + <div id="pmpro-edit-user-div">
101 + <nav id="pmpro-edit-user-nav" role="tablist" aria-labelledby="pmpro-edit-user-menu">
102 + <h2 id="pmpro-edit-user-menu" class="screen-reader-text"><?php esc_html_e( 'Edit Member Area Menu', 'paid-memberships-pro' ); ?></h2>
103 + <?php
104 + $count = 0;
105 + foreach ( $panels as $panel_slug => $panel ) {
106 + /**
107 + * Filter to limit the number of tabs that are visible on the member edit page.
108 + *
109 + * @since 3.0
110 + * @param int $num_visible_tabs The default number of tabs that are visible on the member edit page.
111 + * @return int
112 + */
113 + $num_visible_tabs = apply_filters( 'pmpro_member_edit_num_visible_tabs', 6 );
114 + $tab_visibility = $count < (int) $num_visible_tabs ? true : false;
115 +
116 + // Show the tab.
117 + $panel->display_tab( $panel_slug === $default_panel_slug, $tab_visibility );
118 +
119 + // Increment the count.
120 + $count++;
121 + }
122 +
123 + // Show a "More" tab if there are more than 4 panels.
124 + if ( $count > (int) $num_visible_tabs ) {
125 + ?>
126 + <div class="pmpro_relative">
127 + <div class="pmpro_divider"></div>
128 + <button role="showmore" class="pmpro-member-edit-show-more-tab">
129 + <?php esc_html_e( 'Show More', 'paid-memberships-pro' ); ?>
130 + <span class="dashicons dashicons-arrow-down-alt2"></span>
131 + </button>
132 + </div>
133 + <?php
134 + }
135 + ?>
136 + </nav>
137 + <div class="pmpro_section">
138 + <?php
139 + foreach ( $panels as $panel_slug => $panel ) {
140 + // When creating a new user, we only want to show the user-info panel.
141 + if ( empty( $user->ID ) && $panel_slug !== 'user-info' ) {
142 + continue;
143 + }
144 +
145 + // If we are showing the orders panel, there is additional code that we need to run to allow emailing orders.
146 + // Ideally this would be in the "orders" panel class, but this code needs to be its own separate <form>.
147 + // Hopefully we will have a solution for this down the road, but for now, adding this code here.
148 + if ( $panel_slug === 'orders' && function_exists( 'pmpro_add_email_order_modal' ) ) {
149 + // Load the email order modal.
150 + pmpro_add_email_order_modal();
151 + }
152 +
153 + // Display the panel.
154 + $panel->display_panel( $panel_slug === $default_panel_slug );
155 +
156 + // Increment the count.
157 + $count++;
158 + }
159 + ?>
160 + </div>
161 + </div>
162 +
163 + <?php
164 + require_once( PMPRO_DIR . '/adminpages/admin_footer.php' );
165 + }
166 +
167 + /**
168 + * Save the member edit page.
169 + *
170 + * @since 3.0
171 + */
172 + function pmpro_member_edit_save() {
173 + global $current_user;
174 +
175 + // Check if we are on the pmpro-member page.
176 + if ( empty( $_REQUEST['page'] ) || 'pmpro-member' !== $_REQUEST['page'] ) {
177 + return;
178 + }
179 +
180 + // Check that data was posted.
181 + if ( empty( $_POST ) ) {
182 + return;
183 + }
184 +
185 + // Make sure the current user can edit this user.
186 + // Alterred from wp-admin/user-edit.php.
187 + $user = PMPro_Member_Edit_Panel::get_user();
188 + if ( ! current_user_can( pmpro_get_edit_member_capability() ) ) {
189 + wp_die( esc_html__( 'Sorry, you are not allowed to edit this user.', 'paid-memberships-pro' ) );
190 + }
191 +
192 + // Get the panel slug that was submitted.
193 + $panel_slug = empty( $_REQUEST['pmpro_member_edit_panel'] ) ? '' : sanitize_text_field( $_REQUEST['pmpro_member_edit_panel'] );
194 + if ( empty( $panel_slug ) ) {
195 + return;
196 + }
197 +
198 + // Check the nonce.
199 + if ( empty( $_REQUEST['pmpro_member_edit_saved_panel_nonce'] ) || ! wp_verify_nonce( $_REQUEST['pmpro_member_edit_saved_panel_nonce'], 'pmpro_member_edit_saved_panel_' . $panel_slug ) ) {
200 + return;
201 + }
202 +
203 + // Define a constant if user is editing their own membership.
204 + if ( ! defined( 'IS_PROFILE_PAGE' ) ) {
205 + define( 'IS_PROFILE_PAGE', ( $user->ID === $current_user->ID ) );
206 + }
207 +
208 + // Save the panel.
209 + $panels = pmpro_member_edit_get_panels();
210 + if ( ! empty( $panels[ $panel_slug ] ) ) {
211 + $panels[ $panel_slug ]->save();
212 + }
213 + }
214 + add_action( 'admin_init', 'pmpro_member_edit_save' );
215 +
216 + /**
217 + * We always want to show the time of expiration on the edit member page of the dashboard.
218 + * Fires on priority 5 so sites filtering run later by default.
219 + * @param bool $show Whether to show the time of expiration
220 + * @since 3.0
221 + */
222 + function pmpro_member_edit_show_time_on_expiration( $show ) {
223 + // Ignore on frontend.
224 + if ( ! is_admin() ) {
225 + return $show;
226 + }
227 +
228 + // Make sure we are on the edit member page.
229 + if ( empty( $_REQUEST['page'] ) || $_REQUEST['page'] !== 'pmpro-member' ) {
230 + return $show;
231 + }
232 +
233 + return true;
234 + }
235 + add_filter( 'pmpro_show_time_on_expiration_date', 'pmpro_member_edit_show_time_on_expiration', 5 );