WP-Members Membership Plugin - Version 3.3.3

Version Description

  • If WooCommerce is active, any standard WC user meta fields are removed from the WP-Members additional fields in the User Profile Edit (since they already display in the WC field blocks).
  • When setting hidden posts, don't include posts from post types not set as handled by WP-Members. This prevents previously hidden posts from being included if the post type is no longer included for WP-Members.
  • Set a default product for publishing posts/pages.
  • Updated activation/deactivation processing so that a (admin) user cannot activate or deactivate themselves. Also, if a user has "edit_users" capability, they can log in without being activated.
  • Load email "from" address with main settings rather than when email is sent. This corrects issues with Advanced Options extension, and also keeps the value loaded for use outside of WP-Members email function.
  • WP 5.4 adds the wp_nav_menu_item_custom_fields action, so now WP-Members only loads its custom walker if WP is 5.3 or lower.
  • Image file field type now shows an immediate preview when the "choose file" button is clicked and an image selected (both profile update and new registration).
  • wpmem_login_failed_args updated to pass $args (similar to other _args filters in the plugin, now parses defaults).
Download this release

Release Info

Developer cbutlerjr
Plugin Icon 128x128 WP-Members Membership Plugin
Version 3.3.3
Comparing to
See all releases

Code changes from version 3.3.2 to 3.3.3

includes/admin/class-wp-members-admin-users.php CHANGED
@@ -50,7 +50,7 @@ class WP_Members_Admin_Users {
50
  */
51
  static function insert_activate_link( $actions, $user_object ) {
52
  global $wpmem;
53
- if ( 1 == $wpmem->mod_reg ) {
54
 
55
  $var = get_user_meta( $user_object->ID, 'active', true );
56
 
@@ -112,14 +112,16 @@ class WP_Members_Admin_Users {
112
  $x = 0;
113
  foreach ( $users as $user ) {
114
  $user = filter_var( $user, FILTER_VALIDATE_INT );
115
- // Check to see if the user is already activated, if not, activate.
116
- if ( 'activate' == $action && 1 != get_user_meta( $user, 'active', true ) ) {
117
- wpmem_activate_user( $user );
118
- } elseif( 'deactivate' == $action ) {
119
- wpmem_deactivate_user( $user );
 
 
 
 
120
  }
121
-
122
- $x++;
123
  }
124
  $msg = ( 'activate' == $action ) ? urlencode( sprintf( __( '%s users activated', 'wp-members' ), $x ) ) : urlencode( sprintf( __( '%s users deactivated', 'wp-members' ), $x ) );
125
 
@@ -141,15 +143,18 @@ class WP_Members_Admin_Users {
141
  $users = filter_var( $_REQUEST['user'], FILTER_VALIDATE_INT );
142
 
143
  // Check to see if the user is already activated, if not, activate.
144
- if ( 'activate-single' == $action && 1 != get_user_meta( $users, 'active', true ) ) {
 
 
 
145
  wpmem_activate_user( $users );
146
  $user_info = get_userdata( $users );
147
- $msg = urlencode( sprintf( __( "%s activated", 'wp-members' ), $user_info->user_login ) );
148
 
149
  } elseif ( 'deactivate-single' == $action ) {
150
  wpmem_deactivate_user( $users );
151
  $user_info = get_userdata( $users );
152
- $msg = urlencode( sprintf( __( "%s deactivated", 'wp-members' ), $user_info->user_login ) );
153
 
154
  } else {
155
  // Set the return message.
50
  */
51
  static function insert_activate_link( $actions, $user_object ) {
52
  global $wpmem;
53
+ if ( 1 == $wpmem->mod_reg && $user_object->ID != get_current_user_id() ) {
54
 
55
  $var = get_user_meta( $user_object->ID, 'active', true );
56
 
112
  $x = 0;
113
  foreach ( $users as $user ) {
114
  $user = filter_var( $user, FILTER_VALIDATE_INT );
115
+ // Current user cannot activate or deactivate themselves.
116
+ if ( $user != get_current_user_id() ) {
117
+ // Check to see if the user is already activated, if not, activate.
118
+ if ( 'activate' == $action && 1 != get_user_meta( $user, 'active', true ) ) {
119
+ wpmem_activate_user( $user );
120
+ } elseif( 'deactivate' == $action ) {
121
+ wpmem_deactivate_user( $user );
122
+ }
123
+ $x++;
124
  }
 
 
125
  }
126
  $msg = ( 'activate' == $action ) ? urlencode( sprintf( __( '%s users activated', 'wp-members' ), $x ) ) : urlencode( sprintf( __( '%s users deactivated', 'wp-members' ), $x ) );
127
 
143
  $users = filter_var( $_REQUEST['user'], FILTER_VALIDATE_INT );
144
 
145
  // Check to see if the user is already activated, if not, activate.
146
+ if ( $users == get_current_user_id() ) {
147
+ $msg = urlencode( sprintf( esc_html__( 'You cannot activate or deactivate yourself', 'wp-members' ) ) );
148
+
149
+ } elseif ( 'activate-single' == $action && 1 != get_user_meta( $users, 'active', true ) ) {
150
  wpmem_activate_user( $users );
151
  $user_info = get_userdata( $users );
152
+ $msg = urlencode( sprintf( esc_html__( "%s activated", 'wp-members' ), $user_info->user_login ) );
153
 
154
  } elseif ( 'deactivate-single' == $action ) {
155
  wpmem_deactivate_user( $users );
156
  $user_info = get_userdata( $users );
157
+ $msg = urlencode( sprintf( esc_html__( "%s deactivated", 'wp-members' ), $user_info->user_login ) );
158
 
159
  } else {
160
  // Set the return message.
includes/admin/class-wp-members-products-admin.php CHANGED
@@ -144,6 +144,28 @@ class WP_Members_Products_Admin {
144
  );
145
  }
146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  /**
148
  * Outputs HTML for CPT editor.
149
  *
@@ -165,11 +187,26 @@ class WP_Members_Products_Admin {
165
  $show_exp_detail = ( false !== $product_expires ) ? 'show' : 'hide'; ?>
166
 
167
  <?php wp_nonce_field( '_wpmem_product_nonce', 'wpmem_product_nonce' ); ?>
168
- <p><?php _e( 'Name (slug)', 'wp-members' ); ?>: <?php echo esc_attr( $post->post_name ); ?></p>
 
 
169
  <p>
170
- <input type="checkbox" name="wpmem_product_default" id="wpmem_product_default" value="1" <?php echo ( 1 == $product_default ) ? 'checked' : ''; ?> />
171
  <label for="wpmem_product_default"><?php _e( 'Assign as default at registration? (optional)', 'wp-members' ); ?></label>
172
  </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  <p>
174
  <input type="checkbox" name="wpmem_product_role_required" id="wpmem_product_role_required" value="role-required" <?php echo ( false !== $product_role ) ? 'checked' : ''; ?> />
175
  <label for="wpmem_product_role_required"><?php _e( 'Role Required? (optional)', 'wp-members' ); ?></label>
@@ -185,7 +222,7 @@ class WP_Members_Products_Admin {
185
  <span id="wpmem_product_expires_wrap">
186
  <label for="wpmem_product_number_of_periods" style="display:none;"><?php _e( 'Number', 'wp-members' ); ?></label>
187
  <?php $period = explode( '|', $product_expires ); ?>
188
- <input type="text" name="wpmem_product_number_of_periods" id="wpmem_product_number_of_periods" value="<?php echo esc_attr( $period[0] ); ?>" class="small-text" placeholder="<?php _e( 'Number', 'membership_product' ); ?>" style="width:66px;height:28px;vertical-align:middle;">
189
  <label for="wpmem_product_time_period" style="display:none;"><?php _e( 'Period', 'wp-members' ); ?></label>
190
  <?php echo wpmem_form_field( array( 'name'=>'wpmem_product_time_period', 'type'=>'select', 'value'=>$periods, 'compare'=>( ( isset( $period[1] ) ) ? $period[1] : '' ) ) ); ?>
191
  <label><?php esc_html_e( 'Use "no gap" renewal', 'wp-members' ); ?></label>
@@ -262,25 +299,47 @@ class WP_Members_Products_Admin {
262
  delete_post_meta( $post_id, 'wpmem_product_no_gap' );
263
  }
264
  }
 
 
 
 
 
 
 
265
  }
266
 
267
  /**
268
  * Add dropdown to post and page meta box for marking access by product..
269
  *
270
  * @since 3.2.0
 
271
  *
 
272
  * @global object $wpmem
273
  * @param object $post
274
  * @param string $block
275
  */
276
  function add_product_to_post( $post, $block ) {
277
- global $wpmem;
 
 
 
 
278
  $product = $wpmem->membership->get_post_products( $post->ID ); //get_post_meta( $post->ID, $wpmem->membership->post_meta, true );
279
  $product = ( $product ) ? $product : array();
280
  $values[] = __( 'None', 'wp-members' ) . '|';
 
281
  foreach ( $wpmem->membership->products as $key => $value ) {
 
 
 
 
 
 
 
282
  $values[] = $value['title'] . '|' . $key;
283
  }
 
284
  echo wpmem_form_label( array(
285
  'meta_key'=>$wpmem->membership->post_meta,
286
  'label'=>__( 'Limit access to:', 'wp-members' ),
144
  );
145
  }
146
 
147
+ /**
148
+ * Gets an array of post types.
149
+ *
150
+ * @since 3.3.3
151
+ *
152
+ * @return array $post_types
153
+ */
154
+ function get_post_types() {
155
+ global $wpmem;
156
+ // @todo This comes from option tab. Should consider it being an api function.
157
+ $post_arr = array(
158
+ 'post' => __( 'Posts' ),
159
+ 'page' => __( 'Pages' ),
160
+ );
161
+ if ( ! empty( $wpmem->post_types ) ) {
162
+ foreach ( $wpmem->post_types as $key => $post_type ) {
163
+ $post_arr[ $key ] = $post_type;
164
+ }
165
+ }
166
+ return $post_arr;
167
+ }
168
+
169
  /**
170
  * Outputs HTML for CPT editor.
171
  *
187
  $show_exp_detail = ( false !== $product_expires ) ? 'show' : 'hide'; ?>
188
 
189
  <?php wp_nonce_field( '_wpmem_product_nonce', 'wpmem_product_nonce' ); ?>
190
+ <h3><?php _e( 'Name (slug)', 'wp-members' ); ?></h3>
191
+ <p><strong><?php echo esc_attr( $post->post_name ); ?></strong></p>
192
+ <h3><?php esc_html_e( 'Optional Defaults', 'wp-members' ); ?></h3>
193
  <p>
194
+ <input type="checkbox" name="wpmem_product_default" id="wpmem_product_default" value="1" <?php echo ( 1 == $product_default ) ? 'checked' : ''; ?> />
195
  <label for="wpmem_product_default"><?php _e( 'Assign as default at registration? (optional)', 'wp-members' ); ?></label>
196
  </p>
197
+ <p>
198
+ <?php
199
+
200
+ foreach( $this->get_post_types() as $key => $post_type ) {
201
+ echo '<div>';
202
+ echo '<input type="checkbox" name="wpmem_product_set_default_' . $key . '" id="wpmem_product_set_default_' . $key . '" value ="1" '; echo ( 1 == $this->get_meta( "wpmem_product_set_default_" . $key ) ) ? 'checked' : ''; echo ' />';
203
+ echo '<label for="wpmem_product_set_default_' . $key . '">' . sprintf( esc_html__( 'Pre-selected by default for new %s', 'wp-members' ), $post_type ) . '</label>';
204
+ echo '</div>';
205
+ }
206
+
207
+ ?>
208
+ </p>
209
+ <h3><?php esc_html_e( 'Optional Properties', 'wp-members' ); ?></h3>
210
  <p>
211
  <input type="checkbox" name="wpmem_product_role_required" id="wpmem_product_role_required" value="role-required" <?php echo ( false !== $product_role ) ? 'checked' : ''; ?> />
212
  <label for="wpmem_product_role_required"><?php _e( 'Role Required? (optional)', 'wp-members' ); ?></label>
222
  <span id="wpmem_product_expires_wrap">
223
  <label for="wpmem_product_number_of_periods" style="display:none;"><?php _e( 'Number', 'wp-members' ); ?></label>
224
  <?php $period = explode( '|', $product_expires ); ?>
225
+ <input type="text" name="wpmem_product_number_of_periods" id="wpmem_product_number_of_periods" value="<?php echo esc_attr( $period[0] ); ?>" class="small-text" placeholder="<?php _e( 'Number', 'wp-members' ); ?>" style="width:66px;height:28px;vertical-align:middle;">
226
  <label for="wpmem_product_time_period" style="display:none;"><?php _e( 'Period', 'wp-members' ); ?></label>
227
  <?php echo wpmem_form_field( array( 'name'=>'wpmem_product_time_period', 'type'=>'select', 'value'=>$periods, 'compare'=>( ( isset( $period[1] ) ) ? $period[1] : '' ) ) ); ?>
228
  <label><?php esc_html_e( 'Use "no gap" renewal', 'wp-members' ); ?></label>
299
  delete_post_meta( $post_id, 'wpmem_product_no_gap' );
300
  }
301
  }
302
+ foreach( $this->get_post_types() as $key => $post_type ) {
303
+ if ( false !== wpmem_get( 'wpmem_product_set_default_' . $key, false ) ) {
304
+ update_post_meta( $post_id, 'wpmem_product_set_default_' . $key, 1 );
305
+ } else {
306
+ delete_post_meta( $post_id, 'wpmem_product_set_default_' . $key );
307
+ }
308
+ }
309
  }
310
 
311
  /**
312
  * Add dropdown to post and page meta box for marking access by product..
313
  *
314
  * @since 3.2.0
315
+ * @since 3.3.3 Added defaults.
316
  *
317
+ * @global object $pagenow
318
  * @global object $wpmem
319
  * @param object $post
320
  * @param string $block
321
  */
322
  function add_product_to_post( $post, $block ) {
323
+ global $pagenow, $wpmem;
324
+
325
+ // For checking default memberships.
326
+ $is_new = ( 'post-new.php' == $pagenow ) ? true : false;
327
+
328
  $product = $wpmem->membership->get_post_products( $post->ID ); //get_post_meta( $post->ID, $wpmem->membership->post_meta, true );
329
  $product = ( $product ) ? $product : array();
330
  $values[] = __( 'None', 'wp-members' ) . '|';
331
+
332
  foreach ( $wpmem->membership->products as $key => $value ) {
333
+
334
+ if ( $is_new ) {
335
+ if ( isset( $value[ 'set_default_' . $post->post_type ] ) && 1 == $value[ 'set_default_' . $post->post_type ] ) {
336
+ $product[] = $key;
337
+ }
338
+ }
339
+
340
  $values[] = $value['title'] . '|' . $key;
341
  }
342
+
343
  echo wpmem_form_label( array(
344
  'meta_key'=>$wpmem->membership->post_meta,
345
  'label'=>__( 'Limit access to:', 'wp-members' ),
includes/class-wp-members-forms.php CHANGED
@@ -129,7 +129,7 @@ class WP_Members_Forms {
129
  $accept = '';
130
  }
131
  $class = ( 'textbox' == $class ) ? "file" : $this->sanitize_class( $class );
132
- $str = "<input name=\"$name\" type=\"file\" id=\"$id\" value=\"" . esc_attr( $value ) . "\" class=\"$class\"$accept" . ( ( $required ) ? " required " : "" ) . " />";
133
  break;
134
 
135
  case "checkbox":
@@ -803,6 +803,7 @@ class WP_Members_Forms {
803
  * @since 3.1.7 Moved to forms object class as register_form().
804
  * @since 3.2.5 use_nonce now obsolete (nonce is added automatically).
805
  * @since 3.3.0 $heading argument obsolete.
 
806
  *
807
  * @global object $wpmem The WP_Members object.
808
  * @global string $wpmem_regchk Used to determine if the form is in an error state.
@@ -921,6 +922,7 @@ class WP_Members_Forms {
921
  $wpmem_fields = apply_filters( 'wpmem_register_fields_arr', $wpmem_fields, $tag );
922
 
923
  $hidden_rows = array();
 
924
 
925
  // Loop through the remaining fields.
926
  foreach ( $wpmem_fields as $meta_key => $field ) {
@@ -1081,16 +1083,24 @@ class WP_Members_Forms {
1081
  $valtochk = '';
1082
  }
1083
 
1084
- if ( 'edit' == $tag && ( 'file' == $field['type'] || 'image' == $field['type'] ) ) {
1085
-
 
 
1086
  $attachment_url = wp_get_attachment_url( $val );
1087
  $empty_file = '<span class="description">' . __( 'None' ) . '</span>';
1088
- if ( 'file' == $field['type'] ) {
1089
- $input = ( $attachment_url ) ? '<a href="' . esc_url( $attachment_url ) . '">' . get_the_title( $val ) . '</a>' : $empty_file;
 
 
 
 
 
1090
  } else {
1091
- $input = ( $attachment_url ) ? '<img src="' . esc_url( $attachment_url ) . '">' : $empty_file;
 
 
1092
  }
1093
- $input.= '<br />' . $wpmem->get_text( 'profile_upload' ) . '<br />';
1094
  $input.= wpmem_form_field( array(
1095
  'name' => $meta_key,
1096
  'type' => $field['type'],
@@ -1396,6 +1406,20 @@ class WP_Members_Forms {
1396
  // Remove line breaks if enabled for easier filtering later.
1397
  $form = ( $args['strip_breaks'] ) ? $this->strip_breaks( $form, $rows ) : $form; //str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $form ) : $form;
1398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1399
  /**
1400
  * Filter the generated HTML of the entire form.
1401
  *
@@ -1940,7 +1964,7 @@ class WP_Members_Forms {
1940
  'name' => $wpmem->get_text( 'pwdreset_email' ),
1941
  'type' => 'text',
1942
  'tag' => 'email',
1943
- 'class' => 'text',
1944
  'div' => 'div_text',
1945
  ),
1946
  ),
129
  $accept = '';
130
  }
131
  $class = ( 'textbox' == $class ) ? "file" : $this->sanitize_class( $class );
132
+ $str = "<input name=\"$name\" type=\"file\" id=\"$id\" value=\"" . esc_attr( $value ) . "\" class=\"$class\"$accept" . ( ( $required ) ? " required " : "" ) . ( ( 'image' == $file_type ) ? ' onchange="loadFile(event, this.id)"' : '' ) . ' />';
133
  break;
134
 
135
  case "checkbox":
803
  * @since 3.1.7 Moved to forms object class as register_form().
804
  * @since 3.2.5 use_nonce now obsolete (nonce is added automatically).
805
  * @since 3.3.0 $heading argument obsolete.
806
+ * @since 3.3.3 Image field type now shows the preview image when "choose file" is clicked.
807
  *
808
  * @global object $wpmem The WP_Members object.
809
  * @global string $wpmem_regchk Used to determine if the form is in an error state.
922
  $wpmem_fields = apply_filters( 'wpmem_register_fields_arr', $wpmem_fields, $tag );
923
 
924
  $hidden_rows = array();
925
+ $form_has_file = false;
926
 
927
  // Loop through the remaining fields.
928
  foreach ( $wpmem_fields as $meta_key => $field ) {
1083
  $valtochk = '';
1084
  }
1085
 
1086
+ if ( ( 'file' == $field['type'] || 'image' == $field['type'] ) ) {
1087
+
1088
+ $form_has_file = true;
1089
+
1090
  $attachment_url = wp_get_attachment_url( $val );
1091
  $empty_file = '<span class="description">' . __( 'None' ) . '</span>';
1092
+ if ( 'edit' == $tag ) {
1093
+ if ( 'file' == $field['type'] ) {
1094
+ $input = ( $attachment_url ) ? '<a href="' . esc_url( $attachment_url ) . '" id="' . $meta_key . '_file">' . get_the_title( $val ) . '</a>' : $empty_file;
1095
+ } else {
1096
+ $input = ( $attachment_url ) ? '<img src="' . esc_url( $attachment_url ) . '" id="' . $meta_key . '_img" />' : $empty_file;
1097
+ }
1098
+ $input.= '<br />' . $wpmem->get_text( 'profile_upload' ) . '<br />';
1099
  } else {
1100
+ if ( 'image' == $field['type'] ) {
1101
+ $input = '<img src="" id="' . $meta_key . '_img" />';
1102
+ }
1103
  }
 
1104
  $input.= wpmem_form_field( array(
1105
  'name' => $meta_key,
1106
  'type' => $field['type'],
1406
  // Remove line breaks if enabled for easier filtering later.
1407
  $form = ( $args['strip_breaks'] ) ? $this->strip_breaks( $form, $rows ) : $form; //str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $form ) : $form;
1408
 
1409
+ // If there is an image input type, include the following script.
1410
+ $form = ( $form_has_file ) ? $form . '
1411
+ <script>
1412
+ var loadFile = function(event, clicked_id) {
1413
+ var reader = new FileReader();
1414
+ var the_id = clicked_id + "_img";
1415
+ reader.onload = function() {
1416
+ var output = document.getElementById(the_id);
1417
+ output.src = reader.result;
1418
+ };
1419
+ reader.readAsDataURL(event.target.files[0]);
1420
+ };
1421
+ </script>' : $form;
1422
+
1423
  /**
1424
  * Filter the generated HTML of the entire form.
1425
  *
1964
  'name' => $wpmem->get_text( 'pwdreset_email' ),
1965
  'type' => 'text',
1966
  'tag' => 'email',
1967
+ 'class' => 'textbox',
1968
  'div' => 'div_text',
1969
  ),
1970
  ),
includes/class-wp-members-menus.php CHANGED
@@ -62,12 +62,19 @@ class WP_Members_Menus {
62
  * @since 3.3.0
63
  */
64
  public function load_hooks() {
65
- add_filter( 'wp_edit_nav_menu_walker', array( $this, 'edit_nav_menu_walker' ) );
 
 
 
 
 
66
  add_action( 'wp_update_nav_menu_item', array( $this, 'update_nav_menu_item' ), 10, 2 );
67
  add_filter( 'wp_setup_nav_menu_item', array( $this, 'setup_nav_menu_item' ) );
68
  add_action( 'admin_enqueue_scripts' , array( $this, 'enqueue_scripts' ) );
69
 
70
- add_action( 'wp_nav_menu_item_custom_fields', array( $this, 'nav_menu_item_fields' ), 5, 4 );
 
 
71
  add_action( 'wpmem_nav_menu_logged_in_criteria', array( $this, 'add_product_criteria' ) );
72
 
73
  // Handles removing front end menu items.
@@ -75,6 +82,7 @@ class WP_Members_Menus {
75
  add_filter( 'wp_get_nav_menu_items', array( $this, 'exclude_menu_items' ), 20 );
76
  }
77
  }
 
78
  /**
79
  * Override the Admin Menu Walker
80
  *
62
  * @since 3.3.0
63
  */
64
  public function load_hooks() {
65
+
66
+ global $wp_version;
67
+ if ( version_compare( $wp_version, '5.4', '<' ) ) {
68
+ add_filter( 'wp_edit_nav_menu_walker', array( $this, 'edit_nav_menu_walker' ) ); // @todo No longer needed in WP 5.4?
69
+ }
70
+
71
  add_action( 'wp_update_nav_menu_item', array( $this, 'update_nav_menu_item' ), 10, 2 );
72
  add_filter( 'wp_setup_nav_menu_item', array( $this, 'setup_nav_menu_item' ) );
73
  add_action( 'admin_enqueue_scripts' , array( $this, 'enqueue_scripts' ) );
74
 
75
+ add_action( 'wp_nav_menu_item_custom_fields', array( $this, 'nav_menu_item_fields' ), 5, 4 );
76
+ // add_action( 'wp_nav_menu_item_custom_fields_customize_template', array( $this, 'nav_menu_item_fields' ), 5 ); // @todo Work this out.
77
+
78
  add_action( 'wpmem_nav_menu_logged_in_criteria', array( $this, 'add_product_criteria' ) );
79
 
80
  // Handles removing front end menu items.
82
  add_filter( 'wp_get_nav_menu_items', array( $this, 'exclude_menu_items' ), 20 );
83
  }
84
  }
85
+
86
  /**
87
  * Override the Admin Menu Walker
88
  *
includes/class-wp-members-products.php CHANGED
@@ -213,7 +213,26 @@ class WP_Members_Products {
213
  * @type string $slug
214
  * }
215
  */
216
- $content = ( $access ) ? $content : apply_filters( 'wpmem_product_restricted_msg', $wpmem->get_text( 'product_restricted' ), $post_products );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
 
218
  // Handle comments.
219
  if ( ! $access ) {
213
  * @type string $slug
214
  * }
215
  */
216
+ $message = apply_filters( 'wpmem_product_restricted_msg', $wpmem->get_text( 'product_restricted' ), $post_products );
217
+
218
+ /**
219
+ * Filter the product restricted message HTML.
220
+ *
221
+ * @since 3.3.3
222
+ *
223
+ * @param array $product_restricted {
224
+ * $type string $wrapper_before
225
+ * $type string $message
226
+ * $type string $wrapper_after
227
+ * }
228
+ */
229
+ $product_restricted = apply_filters( 'wpmem_product_restricted', array(
230
+ 'wrapper_before' => '<div class="wpmem_msg" align="center">',
231
+ 'message' => '<p>' . $message . '</p>',
232
+ 'wrapper_after' => '</div>',
233
+ ) );
234
+
235
+ $content = ( $access ) ? $content : $product_restricted['wrapper_before'] . $product_restricted['message'] . $product_restricted['wrapper_after'];
236
 
237
  // Handle comments.
238
  if ( ! $access ) {
includes/class-wp-members-shortcodes.php CHANGED
@@ -314,10 +314,11 @@ class WP_Members_Shortcodes {
314
  * Filter the access failed message.
315
  *
316
  * @since 3.3.0
 
317
  *
318
  * @param array $settings.
319
  */
320
- $settings = apply_filters( 'wpmem_sc_product_access_denied', $settings );
321
  $content = $settings['wrapper_before'] . $settings['msg'] . $settings['wrapper_after'];
322
  }
323
  }
314
  * Filter the access failed message.
315
  *
316
  * @since 3.3.0
317
+ * @since 3.3.3 Changed from 'wpmem_sc_product_access_denied'
318
  *
319
  * @param array $settings.
320
  */
321
+ $settings = apply_filters( 'wpmem_sc_product_restricted', $settings );
322
  $content = $settings['wrapper_before'] . $settings['msg'] . $settings['wrapper_after'];
323
  }
324
  }
includes/class-wp-members-user-profile.php CHANGED
@@ -454,29 +454,32 @@ class WP_Members_User_Profile {
454
  global $wpmem;
455
  // See if reg is moderated, and if the user has been activated.
456
  if ( $wpmem->mod_reg == 1 ) {
457
- $user_active_flag = get_user_meta( $user_id, 'active', true );
458
- switch( $user_active_flag ) {
459
-
460
- case "0":
461
- $label = __( 'Reactivate this user?', 'wp-members' );
462
- $action = 1;
463
- break;
464
-
465
- case "1":
466
- $label = __( 'Deactivate this user?', 'wp-members' );
467
- $action = 0;
468
- break;
469
-
470
- default:
471
- $label = __( 'Activate this user?', 'wp-members' );
472
- $action = 1;
473
- break;
474
- } ?>
475
- <tr>
476
- <th><label><?php echo $label; ?></label></th>
477
- <td><input id="activate_user" type="checkbox" class="input" name="activate_user" value="<?php echo $action; ?>" /></td>
478
- </tr>
479
- <?php }
 
 
 
480
  }
481
 
482
  /**
454
  global $wpmem;
455
  // See if reg is moderated, and if the user has been activated.
456
  if ( $wpmem->mod_reg == 1 ) {
457
+ // Make sure this isn't an admin looking at their own profile.
458
+ if ( current_user_can( 'edit_users' ) && $user_id != get_current_user_id() ) {
459
+ $user_active_flag = get_user_meta( $user_id, 'active', true );
460
+ switch( $user_active_flag ) {
461
+
462
+ case "0":
463
+ $label = __( 'Reactivate this user?', 'wp-members' );
464
+ $action = 1;
465
+ break;
466
+
467
+ case "1":
468
+ $label = __( 'Deactivate this user?', 'wp-members' );
469
+ $action = 0;
470
+ break;
471
+
472
+ default:
473
+ $label = __( 'Activate this user?', 'wp-members' );
474
+ $action = 1;
475
+ break;
476
+ } ?>
477
+ <tr>
478
+ <th><label><?php echo $label; ?></label></th>
479
+ <td><input id="activate_user" type="checkbox" class="input" name="activate_user" value="<?php echo $action; ?>" /></td>
480
+ </tr>
481
+ <?php }
482
+ }
483
  }
484
 
485
  /**
includes/class-wp-members.php CHANGED
@@ -1,1934 +1,1979 @@
1
- <?php
2
- /**
3
- * The WP_Members Class.
4
- *
5
- * This is the main WP_Members object class. This class contains functions
6
- * for loading settings, shortcodes, hooks to WP, plugin dropins, constants,
7
- * and registration fields. It also manages whether content should be blocked.
8
- *
9
- * @package WP-Members
10
- * @subpackage WP_Members Object Class
11
- * @since 3.0.0
12
- */
13
-
14
- // Exit if accessed directly.
15
- if ( ! defined( 'ABSPATH' ) ) {
16
- exit();
17
- }
18
-
19
- class WP_Members {
20
-
21
- /**
22
- * Plugin version.
23
- *
24
- * @since 3.0.0
25
- * @access public
26
- * @var string
27
- */
28
- public $version = WPMEM_VERSION;
29
-
30
- /**
31
- * Database version
32
- *
33
- * @since 3.2.2
34
- * @access public
35
- * @var string
36
- */
37
- public $db_version = WPMEM_DB_VERSION;
38
-
39
- /**
40
- * Plugin path.
41
- *
42
- * @since 3.3.0
43
- * @access public
44
- * @var string
45
- */
46
- public $path;
47
-
48
- /**
49
- * Plugin __FILE__.
50
- *
51
- * @since 3.3.0
52
- * @access public
53
- * @var string
54
- */
55
- public $name;
56
-
57
- /**
58
- * Plugin slug.
59
- *
60
- * @since 3.3.0
61
- * @access public
62
- * @var string
63
- */
64
- public $slug;
65
-
66
- /**
67
- * Plugin URL.
68
- *
69
- * @since 3.3.0
70
- * @access public
71
- * @var string
72
- */
73
- public $url;
74
-
75
-
76
- /**
77
- * Content block settings.
78
- *
79
- * @since 3.0.0
80
- * @access public
81
- * @var array
82
- */
83
- public $block;
84
-
85
- /**
86
- * Excerpt settings.
87
- *
88
- * @since 3.0.0
89
- * @access public
90
- * @var array
91
- */
92
- public $show_excerpt;
93
-
94
- /**
95
- * Show login form settings.
96
- *
97
- * @since 3.0.0
98
- * @access public
99
- * @var array
100
- */
101
- public $show_login;
102
-
103
- /**
104
- * Show registration form settings.
105
- *
106
- * @since 3.0.0
107
- * @access public
108
- * @var array
109
- */
110
- public $show_reg;
111
-
112
- /**
113
- * Auto-excerpt settings.
114
- *
115
- * @since 3.0.0
116
- * @access public
117
- * @var array
118
- */
119
- public $autoex;
120
-
121
- /**
122
- * Notify admin settings.
123
- *
124
- * @since 3.0.0
125
- * @access public
126
- * @var string
127
- */
128
- public $notify;
129
-
130
- /**
131
- * Moderated registration settings.
132
- *
133
- * @since 3.0.0
134
- * @access public
135
- * @var string
136
- */
137
- public $mod_reg;
138
-
139
- /**
140
- * Captcha settings.
141
- *
142
- * @since 3.0.0
143
- * @access public
144
- * @var array
145
- */
146
- public $captcha;
147
-
148
- /**
149
- * Enable expiration extension settings.
150
- *
151
- * @since 3.0.0
152
- * @access public
153
- * @var string
154
- */
155
- public $use_exp;
156
-
157
- /**
158
- * Expiration extension enable trial period.
159
- *
160
- * @since 3.0.0
161
- * @access public
162
- * @var string
163
- */
164
- public $use_trial;
165
-
166
- /**
167
- *
168
- *
169
- * @since 3.0.0
170
- * @access public
171
- * @var array
172
- */
173
- public $warnings;
174
-
175
- /**
176
- * Enable drop-ins setting.
177
- *
178
- * @since 3.1.9
179
- * @access public
180
- * @var string
181
- */
182
- public $dropins = 0;
183
-
184
- /**
185
- * Container for enabled dropins.
186
- *
187
- * @since 3.1.9
188
- * @access public
189
- * @var array
190
- */
191
- public $dropins_enabled = array();
192
-
193
- /**
194
- * Current plugin action container.
195
- *
196
- * @since 3.0.0
197
- * @access public
198
- * @var string
199
- */
200
- public $action;
201
-
202
- /**
203
- * Regchk container.
204
- *
205
- * @since 3.0.0
206
- * @access public
207
- * @var string
208
- */
209
- public $regchk;
210
-
211
- /**
212
- * User page settings.
213
- *
214
- * @since 3.0.0
215
- * @access public
216
- * @var array
217
- */
218
- public $user_pages;
219
-
220
- /**
221
- * Custom Post Type settings.
222
- *
223
- * @since 3.0.0
224
- * @access public
225
- * @var array
226
- */
227
- public $post_types;
228
-
229
- /**
230
- * Setting for applying texturization.
231
- *
232
- * @since 3.1.7
233
- * @access public
234
- * @var boolean
235
- */
236
- public $texturize;
237
-
238
- /**
239
- * Enable product creation.
240
- *
241
- * @since 3.2.0
242
- * @access public
243
- * @var boolean
244
- */
245
- public $enable_products;
246
-
247
- /**
248
- * Enable logged-in menu clones.
249
- *
250
- * @since 3.2.0
251
- * @access public
252
- * @var string
253
- */
254
- public $clone_menus;
255
-
256
- /**
257
- * Container for error messages.
258
- *
259
- * @since 3.2.0
260
- * @access public
261
- * @var string
262
- */
263
- public $error;
264
-
265
- /**
266
- * Container for admin notices.
267
- *
268
- * @since 3.3.0
269
- * @access public
270
- * @var array
271
- */
272
- public $admin_notices;
273
-
274
- /**
275
- * Container for stylesheet setting.
276
- *
277
- * @since 3.2.7
278
- * @access public
279
- * @var string
280
- */
281
- public $select_style;
282
-
283
- /**
284
- * Container for dropin folder location.
285
- *
286
- * @since 3.3.0
287
- * @access public
288
- * @var string
289
- */
290
- public $dropin_dir;
291
-
292
- /**
293
- * REST conditional.
294
- *
295
- * @since 3.3.2
296
- * @access public
297
- * @var boolean
298
- */
299
- public $is_rest = false;
300
-
301
- /**
302
- * Plugin initialization function.
303
- *
304
- * @since 3.0.0
305
- * @since 3.1.6 Dependencies now loaded by object.
306
- */
307
- function __construct() {
308
-
309
- // Constants.
310
- $this->path = plugin_dir_path( __DIR__ );
311
- $this->name = $this->path . 'wp-members.php';
312
- $this->slug = substr( basename( $this->name ), 0, -4 );
313
- $this->url = plugin_dir_url ( __DIR__ );
314
-
315
- // Load dependent files.
316
- $this->load_dependencies();
317
-
318
- /**
319
- * Filter the options before they are loaded into constants.
320
- *
321
- * @since 2.9.0
322
- * @since 3.0.0 Moved to the WP_Members class.
323
- *
324
- * @param array $this->settings An array of the WP-Members settings.
325
- */
326
- $settings = apply_filters( 'wpmem_settings', get_option( 'wpmembers_settings' ) );
327
-
328
- // Validate that v3 settings are loaded.
329
- if ( ! isset( $settings['version'] )
330
- || $settings['version'] != $this->version
331
- || ! isset( $settings['db_version'] )
332
- || $settings['db_version'] != $this->db_version ) {
333
- /**
334
- * Load installation routine.
335
- */
336
- require_once( $this->path . 'includes/install.php' );
337
- // Update settings.
338
- /** This filter is documented in /inc/class-wp-members.php */
339
- $settings = apply_filters( 'wpmem_settings', wpmem_do_install() );
340
- }
341
-
342
- // Assemble settings.
343
- foreach ( $settings as $key => $val ) {
344
- $this->$key = $val;
345
- }
346
-
347
- $this->load_user_pages();
348
- $this->set_style();
349
-
350
- $this->forms = new WP_Members_Forms; // Load forms.
351
- $this->api = new WP_Members_API; // Load api.
352
- $this->shortcodes = new WP_Members_Shortcodes(); // Load shortcodes.
353
- $this->membership = new WP_Members_Products(); // Load membership plans
354
- $this->email = new WP_Members_Email; // Load email functions
355
- $this->user = new WP_Members_User( $this ); // Load user functions.
356
- $this->menus = new WP_Members_Menus();
357
- if ( $this->clone_menus ) {
358
- $this->menus_clone = new WP_Members_Clone_Menus(); // Load clone menus.
359
- }
360
-
361
- /**
362
- * Fires after main settings are loaded.
363
- *
364
- * @since 3.0
365
- * @deprecated 3.2.0 Use wpmem_after_init instead.
366
- */
367
- do_action( 'wpmem_settings_loaded' );
368
-
369
- // Preload the expiration module, if available.
370
- $exp_active = ( function_exists( 'wpmem_exp_init' ) || function_exists( 'wpmem_set_exp' ) ) ? true : false;
371
- define( 'WPMEM_EXP_MODULE', $exp_active );
372
-
373
- // Load actions and filters.
374
- $this->load_hooks();
375
-
376
- // Load contants.
377
- $this->load_constants();
378
-
379
- // Load dropins.
380
- if ( $this->dropins ) {
381
- $this->load_dropins();
382
- }
383
-
384
- // Check for anything that we should stop execution for (currently just the default tos).
385
- if ( 'display' == wpmem_get( 'tos', false, 'get' ) ) {
386
- // If themes are not loaded, we don't need them.
387
- $user_themes = ( ! defined( 'WP_USE_THEMES' ) ) ? define( 'WP_USE_THEMES', false ) : '';
388
- $this->load_default_tos();
389
- die();
390
- }
391
- }
392
-
393
- /**
394
- * Plugin initialization function to load hooks.
395
- *
396
- * @since 3.0.0
397
- */
398
- function load_hooks() {
399
-
400
- /**
401
- * Fires before action and filter hooks load.
402
- *
403
- * @since 3.0.0
404
- * @since 3.1.6 Fires before hooks load.
405
- */
406
- do_action( 'wpmem_load_hooks' );
407
-
408
- // Add actions.
409
-
410
- add_action( 'init', array( $this, 'load_textdomain' ) ); //add_action( 'plugins_loaded', 'wpmem_load_textdomain' );
411
- add_action( 'init', array( $this->membership, 'add_cpt' ), 0 ); // Adds membership plans custom post type.
412
- add_action( 'widgets_init', array( $this, 'widget_init' ) ); // initializes the widget
413
- add_action( 'admin_init', array( $this, 'load_admin' ) ); // check user role to load correct dashboard
414
- add_action( 'rest_api_init', array( $this, 'rest_init' ) );
415
- add_action( 'template_redirect', array( $this, 'get_action' ) );
416
- add_action( 'login_enqueue_scripts', array( $this, 'enqueue_style_wp_login' ) ); // styles the native registration
417
- add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) ); // Enqueues the stylesheet.
418
- add_action( 'wp_enqueue_scripts', array( $this, 'loginout_script' ) );
419
- add_action( 'pre_get_posts', array( $this, 'do_hide_posts' ) );
420
- add_action( 'customize_register', array( $this, 'customizer_settings' ) );
421
- add_action( 'admin_menu', 'wpmem_admin_options' ); // adds admin menu
422
-
423
- if ( is_user_logged_in() ) {
424
- add_action( 'wpmem_pwd_change', array( $this->user, 'set_password' ), 9, 2 );
425
- add_action( 'wpmem_pwd_change', array( $this->user, 'set_as_logged_in' ), 10 );
426
- }
427
-
428
- add_filter( 'register_form', 'wpmem_wp_register_form' ); // adds fields to the default wp registration
429
- add_action( 'woocommerce_register_form', 'wpmem_woo_register_form' );
430
-
431
- // Add filters.
432
- add_filter( 'the_content', array( $this, 'do_securify' ), 99 );
433
- add_filter( 'comments_open', array( $this, 'do_securify_comments' ), 99, 2 ); // securifies the comments
434
- add_filter( 'wpmem_securify', array( $this, 'reg_securify' ) ); // adds success message on login form if redirected
435
- add_filter( 'rest_prepare_post', array( $this, 'do_securify_rest' ), 10, 3 );
436
- add_filter( 'rest_prepare_page', array( $this, 'do_securify_rest' ), 10, 3 );
437
- foreach( $this->post_types as $post_type ) {
438
- add_filter( "rest_prepare_{$post_type}", array( $this, 'do_securify_rest' ), 10, 3 );
439
- }
440
-
441
- //add_filter( 'query_vars', array( $this, 'add_query_vars' ), 10, 2 ); // adds custom query vars
442
- add_filter( 'get_pages', array( $this, 'filter_get_pages' ) );
443
- add_filter( 'wp_get_nav_menu_items', array( $this, 'filter_nav_menu_items' ), null, 3 );
444
- add_filter( 'get_previous_post_where', array( $this, 'filter_get_adjacent_post_where' ) );
445
- add_filter( 'get_next_post_where', array( $this, 'filter_get_adjacent_post_where' ) );
446
- add_filter( 'allow_password_reset', array( $this->user, 'no_reset' ) ); // no password reset for non-activated users
447
-
448
- // If registration is moderated, check for activation (blocks backend login by non-activated users).
449
- if ( $this->mod_reg == 1 ) {
450
- add_filter( 'authenticate', array( $this->user, 'check_activated' ), 99, 3 );
451
- }
452
-
453
- /**
454
- * Fires after action and filter hooks load.
455
- *
456
- * @since 3.0.0
457
- * @since 3.1.6 Was wpmem_load_hooks, now wpmem_hooks_loaded.
458
- */
459
- do_action( 'wpmem_hooks_loaded' );
460
- }
461
-
462
- /**
463
- * Load drop-ins.
464
- *
465
- * @since 3.0.0
466
- *
467
- * @todo This is experimental. The function and its operation is subject to change.
468
- */
469
- function load_dropins() {
470
-
471
- /**
472
- * Fires before dropins load (for adding additional drop-ins).
473
- *
474
- * @since 3.0.0
475
- * @since 3.1.6 Fires before dropins.
476
- */
477
- do_action( 'wpmem_load_dropins' );
478
-
479
- /**
480
- * Filters the drop-in file directory.
481
- *
482
- * @since 3.0.0
483
- * @since 3.3.0 Filter previously unpublished, changed hook name.
484
- *
485
- * @param string $wpmem->dropin_dir The drop-in file directory.
486
- */
487
- $dir = apply_filters( 'wpmem_dropin_dir', $this->dropin_dir );
488
-
489
- // Load any drop-ins.
490
- $settings = get_option( 'wpmembers_dropins' );
491
- $this->dropins_enabled = ( $settings ) ? $settings : array();
492
- if ( ! empty( $this->dropins_enabled ) ) {
493
- foreach ( $this->dropins_enabled as $filename ) {
494
- $dropin = $dir . $filename;
495
- if ( file_exists( $dropin ) ) {
496
- include_once( $dropin );
497
- }
498
- }
499
- }
500
-
501
- /**
502
- * Fires before dropins load (for adding additional drop-ins).
503
- *
504
- * @since 3.0.0
505
- * @since 3.1.6 Was wpmem_load_dropins, now wpmem_dropins_loaded.
506
- */
507
- do_action( 'wpmem_dropins_loaded' );
508
- }
509
-
510
- /**
511
- * Loads pre-3.0 constants (included primarily for add-on compatibility).
512
- *
513
- * @since 3.0.0
514
- * @since 3.3.0 Deprecated all but exp and trl constants.
515
- */
516
- function load_constants() {
517
- ( ! defined( 'WPMEM_MOD_REG' ) ) ? define( 'WPMEM_MOD_REG', $this->mod_reg ) : '';
518
- ( ! defined( 'WPMEM_USE_EXP' ) ) ? define( 'WPMEM_USE_EXP', $this->use_exp ) : '';
519
- ( ! defined( 'WPMEM_USE_TRL' ) ) ? define( 'WPMEM_USE_TRL', $this->use_trial ) : '';
520
- }
521
-
522
- /**
523
- * Load dependent files.
524
- *
525
- * @since 3.1.6
526
- */
527
- function load_dependencies() {
528
-
529
- /**
530
- * Filter the location and name of the pluggable file.
531
- *
532
- * @since 2.9.0
533
- * @since 3.1.6 Moved in load order to come before dependencies.
534
- *
535
- * @param string The path to WP-Members plugin functions file.
536
- */
537
- $wpmem_pluggable = apply_filters( 'wpmem_plugins_file', WP_PLUGIN_DIR . '/wp-members-pluggable.php' );
538
-
539
- // Preload any custom functions, if available.
540
- if ( file_exists( $wpmem_pluggable ) ) {
541
- include( $wpmem_pluggable );
542
- }
543
-
544
- require_once( $this->path . 'includes/class-wp-members-api.php' );
545
- require_once( $this->path . 'includes/class-wp-members-clone-menus.php' );
546
- require_once( $this->path . 'includes/class-wp-members-captcha.php' );
547
- require_once( $this->path . 'includes/class-wp-members-email.php' );
548
- require_once( $this->path . 'includes/class-wp-members-forms.php' );
549
- require_once( $this->path . 'includes/class-wp-members-menus.php' );
550
- require_once( $this->path . 'includes/class-wp-members-products.php' );
551
- require_once( $this->path . 'includes/class-wp-members-shortcodes.php' );
552
- require_once( $this->path . 'includes/class-wp-members-user.php' );
553
- require_once( $this->path . 'includes/class-wp-members-user-profile.php' );
554
- require_once( $this->path . 'includes/class-wp-members-widget.php' );
555
- require_once( $this->path . 'includes/api/api.php' );
556
- require_once( $this->path . 'includes/api/api-email.php' );
557
- require_once( $this->path . 'includes/api/api-forms.php' );
558
- require_once( $this->path . 'includes/api/api-products.php' );
559
- require_once( $this->path . 'includes/api/api-users.php' );
560
- require_once( $this->path . 'includes/api/api-utilities.php' );
561
- require_once( $this->path . 'includes/legacy/dialogs.php' );
562
- require_once( $this->path . 'includes/deprecated.php' );
563
- }
564
-
565
- /**
566
- * Load admin API and dependencies.
567
- *
568
- * Determines which scripts to load and actions to use based on the
569
- * current users capabilities.
570
- *
571
- * @since 2.5.2
572
- * @since 3.1.0 Added admin api object.
573
- * @since 3.1.7 Moved from main plugin file as wpmem_chk_admin() to main object.
574
- */
575
- function load_admin() {
576
-
577
- /**
578
- * Fires before initialization of admin options.
579
- *
580
- * @since 2.9.0
581
- */
582
- do_action( 'wpmem_pre_admin_init' );
583
-
584
- // Initilize the admin api.
585
- if ( is_admin() ) {
586
- /**
587
- * Load the admin api class.
588
- *
589
- * @since 3.1.0
590
- */
591
- include_once( $this->path . 'includes/admin/class-wp-members-admin-api.php' );
592
- $this->admin = new WP_Members_Admin_API;
593
- }
594
-
595
- /**
596
- * Fires after initialization of admin options.
597
- *
598
- * @since 2.9.0
599
- */
600
- do_action( 'wpmem_after_admin_init' );
601
- }
602
-
603
- /**
604
- * Gets the requested action.
605
- *
606
- * @since 3.0.0
607
- *
608
- * @global string $wpmem_a The WP-Members action variable.
609
- */
610
- function get_action() {
611
-
612
- // Get the action being done (if any).
613
- $this->action = sanitize_text_field( wpmem_get( 'a', '', 'request' ) );
614
-
615
- // For backward compatibility with processes that check $wpmem_a.
616
- global $wpmem_a;
617
- $wpmem_a = $this->action;
618
-
619
- /**
620
- * Fires when the wpmem action is retrieved.
621
- *
622
- * @since 3.1.7
623
- */
624
- do_action( 'wpmem_get_action' );
625
-
626
- // Get the regchk value (if any).
627
- $this->regchk = $this->get_regchk( $this->action );
628
- }
629
-
630
- /**
631
- * Gets the regchk value.
632
- *
633
- * regchk is a legacy variable that contains information about the current
634
- * action being performed. Login, logout, password, registration, profile
635
- * update functions all return a specific value that is stored in regchk.
636
- * This value and information about the current action can then be used to
637
- * determine what content is to be displayed by the securify function.
638
- *
639
- * @since 3.0.0
640
- *
641
- * @global string $wpmem_a The WP-Members action variable.
642
- *
643
- * @param string $action The current action.
644
- * @return string The regchk value.
645
- */
646
- function get_regchk( $action ) {
647
-
648
- switch ( $action ) {
649
-
650
- case 'login':
651
- $regchk = $this->user->login();
652
- break;
653
-
654
- case 'logout':
655
- $regchk = $this->user->logout();
656
- break;
657
-
658
- case 'pwdchange':
659
- $regchk = $this->user->password_update( 'change' );
660
- break;
661
-
662
- case 'pwdreset':
663
- $regchk = $this->user->password_update( 'reset' );
664
- break;
665
-
666
- case 'getusername':
667
- $regchk = $this->user->retrieve_username();
668
- break;
669
-
670
- case 'register':
671
- case 'update':
672
- $regchk = wpmem_user_register( $action );
673
- break;
674
-
675
- default:
676
- $regchk = ( isset( $regchk ) ) ? $regchk : '';
677
- break;
678
- }
679
-
680
- /**
681
- * Filter wpmem_regchk.
682
- *
683
- * The value of regchk is determined by functions that may be run in the get_regchk function.
684
- * This value determines what happens in the wpmem_securify() function.
685
- *
686
- * @since 2.9.0
687
- * @since 3.0.0 Moved to get_regchk() in WP_Members object.
688
- *
689
- * @param string $this->regchk The value of wpmem_regchk.
690
- * @param string $this->action The $wpmem_a action.
691
- */
692
- $regchk = apply_filters( 'wpmem_regchk', $regchk, $action );
693
-
694
- // Legacy global variable for use with older extensions.
695
- global $wpmem_regchk;
696
- $wpmem_regchk = $regchk;
697
-
698
- return $regchk;
699
- }
700
-
701
- /**
702
- * Determines if content should be blocked.
703
- *
704
- * This function was originally stand alone in the core file and
705
- * was moved to the WP_Members class in 3.0.
706
- *
707
- * @since 3.0.0
708
- * @since 3.3.0 Added $post_id
709
- *
710
- * @global object $post The WordPress Post object.
711
- *
712
- * @param int $post_id
713
- * @return bool $block true|false
714
- */
715
- function is_blocked( $post_id = false ) {
716
-
717
- global $post;
718
-
719
- if ( $post || $post_id ) {
720
-
721
- $the_post = ( false === $post_id ) ? $post : get_post( $post_id );
722
-
723
- $meta = wpmem_get_block_setting( $the_post->ID );
724
-
725
- // Backward compatibility for old block/unblock meta.
726
- if ( ! $meta ) {
727
- // Check for old meta.
728
- $old_block = get_post_meta( $the_post->ID, 'block', true );
729
- $old_unblock = get_post_meta( $the_post->ID, 'unblock', true );
730
- $meta = ( $old_block ) ? 1 : ( ( $old_unblock ) ? 0 : $meta );
731
- }
732
-
733
- // Setup defaults.
734
- $defaults = array(
735
- 'post_id' => $the_post->ID,
736
- 'post_type' => $the_post->post_type,
737
- 'block' => ( isset( $this->block[ $the_post->post_type ] ) && $this->block[ $the_post->post_type ] == 1 ) ? true : false,
738
- 'block_meta' => $meta,
739
- 'block_type' => ( isset( $this->block[ $the_post->post_type ] ) ) ? $this->block[ $the_post->post_type ] : 0,
740
- );
741
-
742
- /**
743
- * Filter the block arguments.
744
- *
745
- * @since 2.9.8
746
- * @since 3.0.0 Moved to is_blocked() in WP_Members object.
747
- * @since 3.3.0 Passes $defaults, second argument deprecated.
748
- *
749
- * @param array $args $defaults.
750
- * @param array $defaults Deprecated 3.3.0.
751
- */
752
- $args = apply_filters( 'wpmem_block_args', $defaults, $defaults );
753
-
754
- // Merge $args with defaults.
755
- $args = ( wp_parse_args( $args, $defaults ) );
756
-
757
- if ( is_single() || is_page() || wpmem_is_rest() ) {
758
- switch( $args['block_type'] ) {
759
- case 1: // If content is blocked by default.
760
- $args['block'] = ( $args['block_meta'] == '0' ) ? false : $args['block'];
761
- break;
762
- case 0 : // If content is unblocked by default.
763
- $args['block'] = ( $args['block_meta'] == '1' ) ? true : $args['block'];
764
- break;
765
- }
766
-
767
- } else {
768
- $args['block'] = false;
769
- }
770
-
771
- } else {
772
- $args = array( 'block' => false );
773
- }
774
-
775
- // Don't block user pages.
776
- $args['block'] = ( in_array( get_permalink(), $this->user_pages ) ) ? false : $args['block'];
777
-
778
- /**
779
- * Filter the block boolean.
780
- *
781
- * @since 2.7.5
782
- *
783
- * @param bool $args['block']
784
- * @param array $args {
785
- * An array of arguments used in the function.
786
- *
787
- * @type string $post_id
788
- * @type string $post_type
789
- * @type string $block
790
- * @type string $block_meta
791
- * @tyep string $block_type
792
- * }
793
- */
794
- return apply_filters( 'wpmem_block', $args['block'], $args );
795
- }
796
-
797
- /**
798
- * The Securify Content Filter.
799
- *
800
- * This is the primary function that picks up where get_action() leaves off.
801
- * Determines whether content is shown or hidden for both post and pages. This
802
- * is a filter function for the_content.
803
- *
804
- * @link https://developer.wordpress.org/reference/functions/the_content/
805
- * @link https://developer.wordpress.org/reference/hooks/the_content/
806
- *
807
- * @since 3.0.0
808
- *
809
- * @global object $post The WordPress Post object.
810
- * @global object $wpmem The WP_Members object.
811
- * @global string $wpmem_themsg Contains messages to be output.
812
- * @param string $content
813
- * @return string $content
814
- */
815
- function do_securify( $content = null ) {
816
-
817
- global $post, $wpmem, $wpmem_themsg;
818
-
819
- $content = ( is_single() || is_page() ) ? $content : wpmem_do_excerpt( $content );
820
-
821
- if ( $this->regchk == "captcha" ) {
822
- global $wpmem_captcha_err;
823
- $wpmem_themsg = $wpmem->get_text( 'reg_captcha_err' ) . '<br /><br />' . $wpmem_captcha_err;
824
- }
825
-
826
- // Block/unblock Posts.
827
- if ( ! is_user_logged_in() && $this->is_blocked() == true ) {
828
-
829
- //Show the login and registration forms.
830
- if ( $this->regchk ) {
831
-
832
- // Empty content in any of these scenarios.
833
- $content = '';
834
-
835
- switch ( $this->regchk ) {
836
-
837
- case "loginfailed":
838
- $content = wpmem_inc_loginfailed();
839
- break;
840
-
841
- case "success":
842
- $content = wpmem_inc_regmessage( $this->regchk, $wpmem_themsg );
843
- $content = $content . wpmem_inc_login();
844
- break;
845
-
846
- default:
847
- $content = wpmem_inc_regmessage( $this->regchk, $wpmem_themsg );
848
- $content = $content . wpmem_register_form();
849
- break;
850
- }
851
-
852
- } else {
853
-
854
- // Toggle shows excerpt above login/reg on posts/pages.
855
- global $wp_query;
856
- if ( isset( $wp_query->query_vars['page'] ) && $wp_query->query_vars['page'] > 1 ) {
857
-
858
- // Shuts down excerpts on multipage posts if not on first page.
859
- $content = '';
860
-
861
- } elseif ( isset( $this->show_excerpt[ $post->post_type ] ) && $this->show_excerpt[ $post->post_type ] == 1 ) {
862
-
863
- $len = strpos( $content, '<span id="more' );
864
- if ( false === $len ) {
865
- $content = wpmem_do_excerpt( $content );
866
- } else {
867
- $content = substr( $content, 0, $len );
868
- }
869
-
870
- } else {
871
-
872
- // Empty all content.
873
- $content = '';
874
-
875
- }
876
-
877
- $content = ( isset( $this->show_login[ $post->post_type ] ) && $this->show_login[ $post->post_type ] == 1 ) ? $content . wpmem_inc_login() : $content . wpmem_inc_login( 'page', '', 'hide' );
878
-
879
- $content = ( isset( $this->show_reg[ $post->post_type ] ) && $this->show_reg[ $post->post_type ] == 1 ) ? $content . wpmem_register_form() : $content;
880
- }
881
-
882
- // Protects comments if expiration module is used and user is expired.
883
- } elseif ( is_user_logged_in() && $this->is_blocked() == true ){
884
-
885
- if ( $this->use_exp == 1 && function_exists( 'wpmem_do_expmessage' ) ) {
886
- /**
887
- * Filters the user expired message used by the PayPal extension.
888
- *
889
- * @since 3.2.0
890
- *
891
- * @param string $message
892
- * @param string $content
893
- */
894
- $content = apply_filters( 'wpmem_do_expmessage', wpmem_do_expmessage( $content ), $content );
895
- }
896
- }
897
-
898
- /**
899
- * Filter the value of $content after wpmem_securify has run.
900
- *
901
- * @since 2.7.7
902
- * @since 3.0.0 Moved to new method in WP_Members Class.
903
- *
904
- * @param string $content The content after securify has run.
905
- */
906
- $content = apply_filters( 'wpmem_securify', $content );
907
-
908
- if ( 1 == $this->texturize && strstr( $content, '[wpmem_txt]' ) ) {
909
- // Fix the wptexturize.
910
- remove_filter( 'the_content', 'wpautop' );
911
- remove_filter( 'the_content', 'wptexturize' );
912
- add_filter( 'the_content', array( $this, 'texturize' ), 999 );
913
- }
914
-
915
- return $content;
916
-
917
- }
918
-
919
- /**
920
- * Securifies the comments.
921
- *
922
- * If the user is not logged in and the content is blocked
923
- * (i.e. wpmem->is_blocked() returns true), function loads a
924
- * dummy/empty comments template.
925
- *
926
- * @since 2.9.9
927
- * @since 3.2.0 Moved wpmem_securify_comments() to main class, renamed.
928
- * @since 3.3.2 Added $post_id.
929
- *
930
- * @param bool $open Whether the current post is open for comments.
931
- * @param int $post_id The post ID.
932
- * @return bool $open True if current post is open for comments, otherwise false.
933
- */
934
- function do_securify_comments( $open, $post_id ) {
935
-
936
- $open = ( ! is_user_logged_in() && wpmem_is_blocked( $post_id ) ) ? false : $open;
937
-
938
- /**
939
- * Filters whether comments are open or not.
940
- *
941
- * @since 3.0.0
942
- * @since 3.2.0 Moved to main class.
943
- * @since 3.3.2 Added $post_id.
944
- *
945
- * @param bool $open true if current post is open for comments, otherwise false.
946
- */
947
- $open = apply_filters( 'wpmem_securify_comments', $open, $post_id );
948
-
949
- if ( ! $open ) {
950
- /** This filter is documented in wp-includes/comment-template.php */
951
- add_filter( 'comments_array', array( $this, 'do_securify_comments_array' ), 10, 2 );
952
- }
953
-
954
- return $open;
955
- }
956
-
957
- /**
958
- * Empties the comments array if content is blocked.
959
- *
960
- * @since 3.0.1
961
- * @since 3.2.0 Moved wpmem_securify_comments_array() to main class, renamed.
962
- *
963
- * @param array $comments
964
- * @param int $post_id
965
- * @return array $comments The comments array.
966
- */
967
- function do_securify_comments_array( $comments , $post_id ) {
968
- $comments = ( ! is_user_logged_in() && wpmem_is_blocked( $post_id ) ) ? array() : $comments;
969
- return $comments;
970
- }
971
-
972
- /**
973
- * Handles REST request.
974
- *
975
- * @since 3.3.2
976
- *
977
- * @param WP_REST_Response $response The response object.
978
- * @param WP_Post $post Post object.
979
- * @param WP_REST_Request $request Request object.
980
- * @return
981
- */
982
- function do_securify_rest( $response, $post, $request ) {
983
-
984
- if ( ! is_user_logged_in() ) {
985
- // Response for restricted content
986
- $block_value = wpmem_is_blocked( $response->data['id'] );
987
- if ( $block_value ) {
988
- if ( isset( $response->data['content']['rendered'] ) ) {
989
- /**
990
- * Filters restricted content message.
991
- *
992
- * @since 3.3.2
993
- *
994
- * @param string $message
995
- */
996
- $response->data['content']['rendered'] = apply_filters( "wpmem_securify_rest_{$post->post_type}_content", __( "You must be logged in to view this content.", 'wp-members' ) );
997
- }
998
- if ( isset( $response->data['excerpt']['rendered'] ) ) {
999
- /**
1000
- * Filters restricted excerpt message.
1001
- *
1002
- * @since 3.3.2
1003
- *
1004
- * @param string $message
1005
- */
1006
- $response->data['excerpt']['rendered'] = apply_filters( "wpmem_securify_rest_{$post->post_type}_excerpt", __( "You must be logged in to view this content.", 'wp-members' ) );
1007
- }
1008
- }
1009
-
1010
- // Response for hidden content. @todo This needs to be changed to check for whether the user has access (for internal requests).
1011
- if ( ! is_admin() && in_array( $post->ID, $this->hidden_posts() ) ) {
1012
- return new WP_REST_Response( __( 'The page you are looking for does not exist', 'wp-members' ), 404 );
1013
- }
1014
- }
1015
- return $response;
1016
- }
1017
-
1018
- /**
1019
- * Adds the successful registration message on the login page if reg_nonce validates.
1020
- *
1021
- * @since 3.1.7
1022
- * @since 3.2.0 Moved to wpmem object, renamed reg_securify()
1023
- *
1024
- * @param string $content
1025
- * @return string $content
1026
- */
1027
- function reg_securify( $content ) {
1028
- global $wpmem, $wpmem_themsg;
1029
- $nonce = wpmem_get( 'reg_nonce', false, 'get' );
1030
- if ( $nonce && wp_verify_nonce( $nonce, 'register_redirect' ) ) {
1031
- $content = wpmem_inc_regmessage( 'success', $wpmem_themsg );
1032
- $content = $content . wpmem_inc_login();
1033
- }
1034
- return $content;
1035
- }
1036
-
1037
- /**
1038
- * Runs if the REST API is initialized.
1039
- *
1040
- * @since 3.3.2
1041
- */
1042
- function rest_init() {
1043
- $this->is_rest = true;
1044
- }
1045
-
1046
- /**
1047
- * Gets an array of hidden post IDs.
1048
- *
1049
- * @since 3.2.0
1050
- *
1051
- * @global object $wpdb
1052
- * @return array $hidden
1053
- */
1054
- function hidden_posts() {
1055
- global $wpdb;
1056
- $hidden = get_transient( '_wpmem_hidden_posts' );
1057
- if ( false === $hidden ) {
1058
- $hidden = $this->update_hidden_posts();
1059
- }
1060
- return $hidden;
1061
- }
1062
-
1063
- /**
1064
- * Updates the hidden post array transient.
1065
- *
1066
- * @since 3.2.0
1067
- *
1068
- * @global object $wpdb
1069
- * @return array $hidden
1070
- */
1071
- function update_hidden_posts() {
1072
- global $wpdb;
1073
- $hidden = array();
1074
- $results = $wpdb->get_results( "SELECT post_id FROM " . $wpdb->prefix . "postmeta WHERE meta_key = '_wpmem_block' AND meta_value = 2" );
1075
- foreach( $results as $result ) {
1076
- $hidden[] = $result->post_id;
1077
- }
1078
- set_transient( '_wpmem_hidden_posts', $hidden, 60*5 );
1079
- return $hidden;
1080
- }
1081
-
1082
- /**
1083
- * Gets an array of hidden post IDs.
1084
- *
1085
- * @since 3.2.0
1086
- *
1087
- * @global stdClass $wpdb
1088
- * @return array $hidden
1089
- */
1090
- function get_hidden_posts() {
1091
- $hidden = array();
1092
-
1093
- // Return empty array if this is the admin and user can edit posts.
1094
- if ( is_admin() && current_user_can( 'edit_posts' ) ) {
1095
- return $hidden;
1096
- }
1097
-
1098
- // If the user is not logged in, return all hidden posts.
1099
- if ( ! is_user_logged_in() ) {
1100
- $hidden = $this->hidden_posts();
1101
- } else {
1102
- // If the user is logged in.
1103
- if ( 1 == $this->enable_products ) {
1104
- // Get user product access.
1105
- $hidden = $this->hidden_posts();
1106
- $hidden = ( is_array( $hidden ) ) ? $hidden : array();
1107
-
1108
- // Remove posts with a product the user has access to.
1109
- foreach ( $this->membership->products as $key => $value ) {
1110
- if ( isset( $this->user->access[ $key ] ) && ( true == $this->user->access[ $key ] || $this->user->is_current( $this->user->access[ $key ] ) ) ) {
1111
- foreach ( $hidden as $post_id ) {
1112
- if ( 1 == get_post_meta( $post_id, $this->membership->post_stem . $key, true ) ) {
1113
- $hidden_key = array_search( $post_id, $hidden );
1114
- unset( $hidden[ $hidden_key ] );
1115
- }
1116
- }
1117
- }
1118
- }
1119
-
1120
- // Remove posts that don't have a product assignment (general login).
1121
- foreach( $hidden as $hidden_key ) {
1122
- $unattached = get_post_meta( $hidden_key, '_wpmem_products', true );
1123
- if ( false == $unattached ) {
1124
- $hidden_key = array_search( $hidden_key, $hidden );
1125
- unset( $hidden[ $hidden_key ] );
1126
- }
1127
- }
1128
- }
1129
- }
1130
- return $hidden;
1131
- }
1132
-
1133
- /**
1134
- * Hides posts based on settings and meta.
1135
- *
1136
- * @since 3.2.0
1137
- *
1138
- * @param array $query
1139
- * @return array $query
1140
- */
1141
- function do_hide_posts( $query ) {
1142
- $hidden_posts = $this->get_hidden_posts();
1143
- if ( ! empty( $hidden_posts ) ) {
1144
- $query->set( 'post__not_in', $hidden_posts );
1145
- }
1146
- return $query;
1147
- }
1148
-
1149
- /**
1150
- * Filter to hide pages for get_pages().
1151
- *
1152
- * @since 3.2.0
1153
- *
1154
- * @global object $wpdb
1155
- * @param array $pages
1156
- * @return array $pages
1157
- */
1158
- function filter_get_pages( $pages ) {
1159
- $hidden_posts = $this->get_hidden_posts();
1160
- if ( ! empty ( $hidden_posts ) ) {
1161
- $new_pages = array();
1162
- foreach ( $pages as $key => $page ) {
1163
- if ( ! in_array( $page->ID, $hidden_posts ) ) {
1164
- $new_pages[ $key ] = $page;
1165
- }
1166
- }
1167
- $pages = $new_pages;
1168
- }
1169
- return $pages;
1170
- }
1171
-
1172
- /**
1173
- * Filter to hide menu items.
1174
- *
1175
- * @since 3.2.0
1176
- *
1177
- * @param array $items
1178
- * @param $menu
1179
- * @param array $args
1180
- * @return array $items
1181
- */
1182
- function filter_nav_menu_items( $items, $menu, $args ) {
1183
- $hidden_posts = $this->get_hidden_posts();
1184
- if ( ! empty( $hidden_posts ) ) {
1185
- foreach ( $items as $key => $item ) {
1186
- if ( in_array( $item->object_id, $hidden_posts ) ) {
1187
- unset( $items[ $key ] );
1188
- }
1189
- }
1190
- }
1191
- return $items;
1192
- }
1193
-
1194
- /**
1195
- * Filter to remove hidden posts from prev/next links.
1196
- *
1197
- * @since 3.2.4
1198
- *
1199
- * @global object $wpmem
1200
- * @param string $where
1201
- * @return string $where
1202
- */
1203
- function filter_get_adjacent_post_where( $where ) {
1204
- global $wpmem;
1205
- if ( ! is_user_logged_in() ) {
1206
- $hidden_posts = $this->get_hidden_posts();
1207
- if ( ! empty( $hidden_posts ) ) {
1208
- $hidden = implode( ",", $hidden_posts );
1209
- $where = $where . " AND p.ID NOT IN ( $hidden )";
1210
- }
1211
- }
1212
- return $where;
1213
- }
1214
-
1215
- /**
1216
- * Sets the registration fields.
1217
- *
1218
- * @since 3.0.0
1219
- * @since 3.1.5 Added $form argument.
1220
- * @since 3.3.0 Added $tag argument.
1221
- *
1222
- * @param string $form The form being generated.
1223
- */
1224
- function load_fields( $tag = 'new', $form = 'default' ) {
1225
-
1226
- // Get stored fields settings.
1227
- $fields = get_option( 'wpmembers_fields' );
1228
-
1229
- // Validate fields settings.
1230
- if ( ! isset( $fields ) || empty( $fields ) ) {
1231
- // Update settings.
1232
- $fields = array( array( 10, 'Email', 'user_email', 'email', 'y', 'y', 'y', 'profile'=>true ) );
1233
- }
1234
-
1235
- // Add new field array keys
1236
- foreach ( $fields as $key => $val ) {
1237
-
1238
- // Key fields with meta key.
1239
- $meta_key = $val[2];
1240
-
1241
- // Old format, new key.
1242
- foreach ( $val as $subkey => $subval ) {
1243
- $this->fields[ $meta_key ][ $subkey ] = $subval;
1244
- }
1245
-
1246
- // Setup field properties.
1247
- $this->fields[ $meta_key ]['label'] = $val[1];
1248
- $this->fields[ $meta_key ]['type'] = $val[3];
1249
- $this->fields[ $meta_key ]['register'] = ( 'y' == $val[4] ) ? true : false;
1250
- $this->fields[ $meta_key ]['required'] = ( 'y' == $val[5] ) ? true : false;
1251
- $this->fields[ $meta_key ]['profile'] = ( 'y' == $val[4] ) ? true : false;// ( isset( $val['profile'] ) ) ? $val['profile'] : true ; // // @todo Wait for profile fix
1252
- $this->fields[ $meta_key ]['native'] = ( 'y' == $val[6] ) ? true : false;
1253
-
1254
- // Certain field types have additional properties.
1255
- switch ( $val[3] ) {
1256
-
1257
- case 'checkbox':
1258
- $this->fields[ $meta_key ]['checked_value'] = $val[7];
1259
- $this->fields[ $meta_key ]['checked_default'] = ( 'y' == $val[8] ) ? true : false;
1260
- break;
1261
-
1262
- case 'select':
1263
- case 'multiselect':
1264
- case 'multicheckbox':
1265
- case 'radio':
1266
- // Correct a malformed value (if last value is empty due to a trailing comma).
1267
- if ( '' == end( $val[7] ) ) {
1268
- array_pop( $val[7] );
1269
- $this->fields[ $meta_key ][7] = $val[7];
1270
- }
1271
- $this->fields[ $meta_key ]['values'] = $val[7];
1272
- $this->fields[ $meta_key ]['delimiter'] = ( isset( $val[8] ) ) ? $val[8] : '|';
1273
- $this->fields[ $meta_key ]['options'] = array();
1274
- foreach ( $val[7] as $value ) {
1275
- $pieces = explode( '|', trim( $value ) );
1276
- if ( isset( $pieces[1] ) && $pieces[1] != '' ) {
1277
- $this->fields[ $meta_key ]['options'][ $pieces[1] ] = $pieces[0];
1278
- }
1279
- }
1280
- break;
1281
-
1282
- case 'file':
1283
- case 'image':
1284
- $this->fields[ $meta_key ]['file_types'] = $val[7];
1285
- break;
1286
-
1287
- case 'hidden':
1288
- $this->fields[ $meta_key ]['value'] = $val[7];
1289
- break;
1290
-
1291
- }
1292
- }
1293
- }
1294
-
1295
- /**
1296
- * Get excluded meta fields.
1297
- *
1298
- * @since 3.0.0
1299
- *
1300
- * @param string $tag A tag so we know where the function is being used.
1301
- * @return array The excluded fields.
1302
- */
1303
- function excluded_fields( $tag ) {
1304
-
1305
- // Default excluded fields.
1306
- $excluded_fields = array( 'password', 'confirm_password', 'confirm_email', 'password_confirm', 'email_confirm' );
1307
-
1308
- if ( 'update' == $tag || 'admin-profile' == $tag || 'user-profile' == $tag || 'wp-register' == $tag ) {
1309
- $excluded_fields[] = 'username';
1310
- }
1311
-
1312
- if ( 'admin-profile' == $tag || 'user-profile' == $tag ) {
1313
- array_push( $excluded_fields, 'first_name', 'last_name', 'nickname', 'display_name', 'user_email', 'description', 'user_url' );
1314
- }
1315
-
1316
- /**
1317
- * Filter the fields to be excluded when user is created/updated.
1318
- *
1319
- * @since 2.9.3
1320
- * @since 3.0.0 Moved to new method in WP_Members Class.
1321
- *
1322
- * @param array An array of the field meta names to exclude.
1323
- * @param string $tag A tag so we know where the function is being used.
1324
- */
1325
- $excluded_fields = apply_filters( 'wpmem_exclude_fields', $excluded_fields, $tag );
1326
-
1327
- // Return excluded fields.
1328
- return $excluded_fields;
1329
- }
1330
-
1331
- /**
1332
- * Set page locations.
1333
- *
1334
- * Handles numeric page IDs while maintaining
1335
- * compatibility with old full url settings.
1336
- *
1337
- * @since 3.0.8
1338
- */
1339
- function load_user_pages() {
1340
- foreach ( $this->user_pages as $key => $val ) {
1341
- if ( is_numeric( $val ) ) {
1342
- if ( false !== get_post_status( $val ) ) {
1343
- $this->user_pages[ $key ] = get_page_link( $val );
1344
- } else {
1345
- $notice = sprintf( __( 'You have a linked page in the WP-Members page settings that corresponds to a post ID that no longer exists. Please %s review and update the %s page settings %s.', 'wp-members' ), '<a href="' . esc_url( get_admin_url() . '/options-general.php?page=wpmem-settings&tab=options' ) . '">', $key, '</a>' );
1346
- $this->admin_notices[] = array(
1347
- 'type'=>'error',
1348
- 'notice'=>$notice
1349
- );
1350
- }
1351
- }
1352
- }
1353
- }
1354
-
1355
- /**
1356
- * Sets the stylesheet URL.
1357
- *
1358
- * @since 3.3.0
1359
- */
1360
- function set_style() {
1361
- $this->cssurl = ( 'use_custom' == $this->select_style ) ? $this->cssurl : $this->url . 'assets/css/forms/' . $this->select_style . wpmem_get_suffix() . '.css'; // Set the stylesheet.
1362
- }
1363
-
1364
- /**
1365
- * Returns a requested text string.
1366
- *
1367
- * This function manages all of the front-end facing text.
1368
- * All defaults can be filtered using wpmem_default_text_strings.
1369
- *
1370
- * @since 3.1.0
1371
- *
1372
- * @global object $wpmem
1373
- *
1374
- * @param string $str
1375
- * @return string $text
1376
- */
1377
- function get_text( $str ) {
1378
-
1379
- global $wpmem;
1380
-
1381
- // Default Form Fields.
1382
- $default_form_fields = array(
1383
- 'first_name' => __( 'First Name', 'wp-members' ),
1384
- 'last_name' => __( 'Last Name', 'wp-members' ),
1385
- 'addr1' => __( 'Address 1', 'wp-members' ),
1386
- 'addr2' => __( 'Address 2', 'wp-members' ),
1387
- 'city' => __( 'City', 'wp-members' ),
1388
- 'thestate' => __( 'State', 'wp-members' ),
1389
- 'zip' => __( 'Zip', 'wp-members' ),
1390
- 'country' => __( 'Country', 'wp-members' ),
1391
- 'phone1' => __( 'Day Phone', 'wp-members' ),
1392
- 'user_email' => __( 'Email', 'wp-members' ),
1393
- 'confirm_email' => __( 'Confirm Email', 'wp-members' ),
1394
- 'user_url' => __( 'Website', 'wp-members' ),
1395
- 'description' => __( 'Biographical Info', 'wp-members' ),
1396
- 'password' => __( 'Password', 'wp-members' ),
1397
- 'confirm_password' => __( 'Confirm Password', 'wp-members' ),
1398
- 'tos' => __( 'TOS', 'wp-members' ),
1399
- );
1400
-
1401
- /*
1402
- * Strings to be added or removed in future versions, included so they will
1403
- * be in the translation template.
1404
- * @todo Check whether any of these should be removed.
1405
- */
1406
- $benign_strings = array(
1407
- __( 'No fields selected for deletion', 'wp-members' ),
1408
- __( 'You are not logged in.', 'wp-members' ), // Technically removed 3.5
1409
- );
1410
-
1411
- $defaults = array(
1412
-
1413
- // Login form.
1414
- 'login_heading' => __( 'Existing Users Log In', 'wp-members' ),
1415
- 'login_username' => __( 'Username or Email', 'wp-members' ),
1416
- 'login_password' => __( 'Password', 'wp-members' ),
1417
- 'login_button' => __( 'Log In', 'wp-members' ),
1418
- 'remember_me' => __( 'Remember Me', 'wp-members' ),
1419
- 'forgot_link_before' => __( 'Forgot password?', 'wp-members' ) . '&nbsp;',
1420
- 'forgot_link' => __( 'Click here to reset', 'wp-members' ),
1421
- 'register_link_before' => __( 'New User?', 'wp-members' ) . '&nbsp;',
1422
- 'register_link' => __( 'Click here to register', 'wp-members' ),
1423
-
1424
- // Password change form.
1425
- 'pwdchg_heading' => __( 'Change Password', 'wp-members' ),
1426
- 'pwdchg_password1' => __( 'New password', 'wp-members' ),
1427
- 'pwdchg_password2' => __( 'Confirm new password', 'wp-members' ),
1428
- 'pwdchg_button' => __( 'Update Password', 'wp-members' ),
1429
-
1430
- // Password reset form.
1431
- 'pwdreset_heading' => __( 'Reset Forgotten Password', 'wp-members' ),
1432
- 'pwdreset_username' => __( 'Username', 'wp-members' ),
1433
- 'pwdreset_email' => __( 'Email', 'wp-members' ),
1434
- 'pwdreset_button' => __( 'Reset Password' ),
1435
- 'username_link_before' => __( 'Forgot username?', 'wp-members' ) . '&nbsp;',
1436
- 'username_link' => __( 'Click here', 'wp-members' ),
1437
-
1438
- // Retrieve username form.
1439
- 'username_heading' => __( 'Retrieve username', 'wp-members' ),
1440
- 'username_email' => __( 'Email Address', 'wp-members' ),
1441
- 'username_button' => __( 'Retrieve username', 'wp-members' ),
1442
-
1443
- // Register form.
1444
- 'register_heading' => __( 'New User Registration', 'wp-members' ),
1445
- 'register_username' => __( 'Choose a Username', 'wp-members' ),
1446
- 'register_rscaptcha' => __( 'Input the code:', 'wp-members' ),
1447
- 'register_tos' => __( 'Please indicate that you agree to the %s Terms of Service %s', 'wp-members' ), // @note: if default changes, default check after wpmem_tos_link_txt must change.
1448
- 'register_clear' => __( 'Reset Form', 'wp-members' ),
1449
- 'register_submit' => __( 'Register', 'wp-members' ),
1450
- 'register_req_mark' => '<span class="req">*</span>',
1451
- 'register_required' => '<span class="req">*</span>' . __( 'Required field', 'wp-members' ),
1452
-
1453
- // User profile update form.
1454
- 'profile_heading' => __( 'Edit Your Information', 'wp-members' ),
1455
- 'profile_username' => __( 'Username', 'wp-members' ),
1456
- 'profile_submit' => __( 'Update Profile', 'wp-members' ),
1457
- 'profile_upload' => __( 'Update this file', 'wp-members' ),
1458
-
1459
- // Error messages and dialogs.
1460
- 'login_failed_heading' => __( 'Login Failed!', 'wp-members' ),
1461
- 'login_failed' => __( 'You entered an invalid username or password.', 'wp-members' ),
1462
- 'login_failed_link' => __( 'Click here to continue.', 'wp-members' ),
1463
- 'pwdchangempty' => __( 'Password fields cannot be empty', 'wp-members' ),
1464
- 'usernamefailed' => __( 'Sorry, that email address was not found.', 'wp-members' ),
1465
- 'usernamesuccess' => __( 'An email was sent to %s with your username.', 'wp-members' ),
1466
- 'reg_empty_field' => __( 'Sorry, %s is a required field.', 'wp-members' ),
1467
- 'reg_valid_email' => __( 'You must enter a valid email address.', 'wp-members' ),
1468
- 'reg_non_alphanumeric' => __( 'The username cannot include non-alphanumeric characters.', 'wp-members' ),
1469
- 'reg_empty_username' => __( 'Sorry, username is a required field', 'wp-members' ),
1470
- 'reg_password_match' => __( 'Passwords did not match.', 'wp-members' ),
1471
- 'reg_email_match' => __( 'Emails did not match.', 'wp-members' ),
1472
- 'reg_empty_captcha' => __( 'You must complete the CAPTCHA form.', 'wp-members' ),
1473
- 'reg_invalid_captcha' => __( 'CAPTCHA was not valid.', 'wp-members' ),
1474
- 'reg_generic' => __( 'There was an error processing the form.', 'wp-members' ),
1475
- 'reg_captcha_err' => __( 'There was an error with the CAPTCHA form.', 'wp-members' ),
1476
- 'reg_file_type' => __( 'Sorry, you can only upload the following file types for the %s field: %s.', 'wp-members' ),
1477
-
1478
- // Links.
1479
- 'profile_edit' => __( 'Edit My Information', 'wp-members' ),
1480
- 'profile_password' => __( 'Change Password', 'wp-members' ),
1481
- 'register_status' => __( 'You are logged in as %s', 'wp-members' ),
1482
- 'register_logout' => __( 'Log out', 'wp-members' ),
1483
- 'register_continue' => ( isset( $wpmem->user_pages['profile'] ) && '' != $wpmem->user_pages['profile'] ) ? __( 'Edit profile', 'wp-members' ) : __( 'Begin using the site.', 'wp-members' ),
1484
- 'login_welcome' => __( 'You are logged in as %s', 'wp-members' ),
1485
- 'login_logout' => __( 'Click to log out', 'wp-members' ),
1486
- 'status_welcome' => __( 'You are logged in as %s', 'wp-members' ),
1487
- 'status_logout' => __( 'click to log out', 'wp-members' ),
1488
- 'menu_logout' => __( 'Log Out', 'wp-members' ),
1489
-
1490
- // Widget.
1491
- 'sb_status' => __( 'You are logged in as %s', 'wp-members' ),
1492
- 'sb_logout' => __( 'click here to log out', 'wp-members' ),
1493
- 'sb_login_failed' => __( 'Login Failed!<br />You entered an invalid username or password.', 'wp-members' ),
1494
- 'sb_not_logged_in' => '',
1495
- 'sb_login_username' => __( 'Username or Email', 'wp-members' ),
1496
- 'sb_login_password' => __( 'Password', 'wp-members' ),
1497
- 'sb_login_button' => __( 'log in', 'wp-members' ),
1498
- 'sb_login_forgot' => __( 'Forgot?', 'wp-members' ),
1499
- 'sb_login_register' => __( 'Register', 'wp-members' ),
1500
-
1501
- // Default Dialogs.
1502
- 'restricted_msg' => __( "This content is restricted to site members. If you are an existing user, please log in. New users may register below.", 'wp-members' ),
1503
- 'success' => __( "Congratulations! Your registration was successful.<br /><br />You may now log in using the password that was emailed to you.", 'wp-members' ),
1504
-
1505
- // @todo Under consideration for removal from the Dialogs tab.
1506
- 'user' => __( "Sorry, that username is taken, please try another.", 'wp-members' ),
1507
- 'email' => __( "Sorry, that email address already has an account.<br />Please try another.", 'wp-members' ),
1508
- 'editsuccess' => __( "Your information was updated!", 'wp-members' ),
1509
-
1510
- // @todo These are defaults and are under consideration for removal from the dialogs tab, possibly as we change the password reset to a link based process.
1511
- 'pwdchangerr' => __( "Passwords did not match.<br /><br />Please try again.", 'wp-members' ),
1512
- 'pwdchangesuccess' => __( "Password successfully changed!", 'wp-members' ),
1513
- 'pwdreseterr' => __( "Either the username or email address do not exist in our records.", 'wp-members' ),
1514
- 'pwdresetsuccess' => __( "Password successfully reset!<br /><br />An email containing a new password has been sent to the email address on file for your account.", 'wp-members' ),
1515
-
1516
- 'product_restricted' => __( "Sorry, you do not have access to this content.", 'wp-members' ),
1517
-
1518
- ); // End of $defaults array.
1519
-
1520
- /**
1521
- * Filter default terms.
1522
- *
1523
- * @since 3.1.0
1524
- * @deprecated 3.2.7 Use wpmem_default_text instead.
1525
- */
1526
- $text = apply_filters( 'wpmem_default_text_strings', '' );
1527
-
1528
- // Merge filtered $terms with $defaults.
1529
- $text = wp_parse_args( $text, $defaults );
1530
-
1531
- /**
1532
- * Filter the default terms.
1533
- *
1534
- * Replaces 'wpmem_default_text_strings' so that multiple filters could
1535
- * be run. This allows for custom filters when also running the Text
1536
- * String Editor extension.
1537
- *
1538
- * @since 3.2.7
1539
- */
1540
- $text = apply_filters( 'wpmem_default_text', $text );
1541
-
1542
- // Return the requested text string.
1543
- return $text[ $str ];
1544
-
1545
- } // End of get_text().
1546
-
1547
- /**
1548
- * Initializes the WP-Members widget.
1549
- *
1550
- * @since 3.2.0 Replaces widget_wpmemwidget_init
1551
- */
1552
- public function widget_init() {
1553
- // Register the WP-Members widget.
1554
- register_widget( 'widget_wpmemwidget' );
1555
- }
1556
-
1557
- /**
1558
- * Adds WP-Members query vars to WP's public query vars.
1559
- *
1560
- * @since 3.2.0
1561
- *
1562
- * @see https://codex.wordpress.org/Plugin_API/Filter_Reference/query_vars
1563
- *
1564
- * @param array $qvars
1565
- */
1566
- public function add_query_vars ( $qvars ) {
1567
- $qvars[] = 'a'; // The WP-Members action variable.
1568
- return $qvars;
1569
- }
1570
-
1571
- /**
1572
- * Enqueues login/out script for the footer.
1573
- *
1574
- * @since 3.2.0
1575
- */
1576
- public function loginout_script() {
1577
- if ( is_user_logged_in() ) {
1578
- wp_enqueue_script( 'jquery' );
1579
- add_action( 'wp_footer', array( $this, 'do_loginout_script' ), 50 );
1580
- }
1581
- }
1582
-
1583
- /**
1584
- * Outputs login/out script for the footer.
1585
- *
1586
- * @since 3.2.0
1587
- *
1588
- * @global object $wpmem
1589
- */
1590
- public function do_loginout_script() {
1591
- global $wpmem;
1592
- $logout = apply_filters( 'wpmem_logout_link', add_query_arg( 'a', 'logout' ) );
1593
- ?><script type="text/javascript">
1594
- jQuery('.wpmem_loginout').html('<a class="login_button" href="<?php echo esc_url( $logout ); ?>"><?php echo $this->get_text( 'menu_logout' ); ?></a>');
1595
- </script><?php
1596
- }
1597
-
1598
- /**
1599
- * Adds WP-Members controls to the Customizer
1600
- *
1601
- * @since 3.2.0
1602
- *
1603
- * @param object $wp_customize The Customizer object.
1604
- */
1605
- function customizer_settings( $wp_customize ) {
1606
- $wp_customize->add_section( 'wp_members' , array(
1607
- 'title' => 'WP-Members',
1608
- 'priority' => 190,
1609
- ) );
1610
-
1611
- // Add settings for output description
1612
- $wp_customize->add_setting( 'wpmem_show_logged_out_state', array(
1613
- 'default' => '1',
1614
- 'type' => 'theme_mod', //'option'
1615
- 'capability' => 'edit_theme_options',
1616
- 'transport' => 'refresh',
1617
- ) );
1618
-
1619
- // Add settings for output description
1620
- $wp_customize->add_setting( 'wpmem_show_form_message_dialog', array(
1621
- 'default' => '1',
1622
- 'type' => 'theme_mod', //'option'
1623
- 'capability' => 'edit_theme_options',
1624
- 'transport' => 'refresh',
1625
- ) );
1626
-
1627
- // Add control and output for select field
1628
- $wp_customize->add_control( 'wpmem_show_form_logged_out', array(
1629
- 'label' => __( 'Show forms as logged out', 'wp-members' ),
1630
- 'section' => 'wp_members',
1631
- 'settings' => 'wpmem_show_logged_out_state',
1632
- 'type' => 'checkbox',
1633
- 'std' => '1'
1634
- ) );
1635
-
1636
- // Add control for showing dialog
1637
- $wp_customize->add_control( 'wpmem_show_form_dialog', array(
1638
- 'label' => __( 'Show form message dialog', 'wp-members' ),
1639
- 'section' => 'wp_members',
1640
- 'settings' => 'wpmem_show_form_message_dialog',
1641
- 'type' => 'checkbox',
1642
- 'std' => '0'
1643
- ) );
1644
- }
1645
-
1646
- /**
1647
- * Overrides the wptexturize filter.
1648
- *
1649
- * Currently only used for the login form to remove the <br> tag that WP puts in after the "Remember Me".
1650
- *
1651
- * @since 2.6.4
1652
- * @since 3.2.3 Moved to WP_Members class.
1653
- *
1654
- * @todo Possibly deprecate or severely alter this process as its need may be obsolete.
1655
- *
1656
- * @param string $content
1657
- * @return string $new_content
1658
- */
1659
- function texturize( $content ) {
1660
-
1661
- $new_content = '';
1662
- $pattern_full = '{(\[wpmem_txt\].*?\[/wpmem_txt\])}is';
1663
- $pattern_contents = '{\[wpmem_txt\](.*?)\[/wpmem_txt\]}is';
1664
- $pieces = preg_split( $pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE );
1665
-
1666
- foreach ( $pieces as $piece ) {
1667
- if ( preg_match( $pattern_contents, $piece, $matches ) ) {
1668
- $new_content .= $matches[1];
1669
- } else {
1670
- $new_content .= wptexturize( wpautop( $piece ) );
1671
- }
1672
- }
1673
-
1674
- return $new_content;
1675
- }
1676
-
1677
- /**
1678
- * Loads the stylesheet for tableless forms.
1679
- *
1680
- * @since 2.6
1681
- * @since 3.2.3 Moved to WP_Members class.
1682
- *
1683
- * @global object $wpmem The WP_Members object.
1684
- */
1685
- function enqueue_style() {
1686
- global $wpmem;
1687
- wp_enqueue_style ( 'wp-members', wpmem_force_ssl( $wpmem->cssurl ), false, $wpmem->version );
1688
- }
1689
-
1690
- /**
1691
- * Loads the wp-login.php stylesheet.
1692
- *
1693
- * @since 3.3.0
1694
- *
1695
- * @global stdClass $wpmem
1696
- */
1697
- function enqueue_style_wp_login() {
1698
- global $wpmem;
1699
- wp_enqueue_style( 'wp-members', $wpmem->url . 'assets/css/wp-login' . wpmem_get_suffix() . '.css', false, $wpmem->version );
1700
- }
1701
-
1702
- /**
1703
- * Creates an excerpt on the fly if there is no 'more' tag.
1704
- *
1705
- * @since 2.6
1706
- * @since 3.2.3 Moved to WP_Members class.
1707
- * @since 3.2.5 Check if post object exists.
1708
- *
1709
- * @global object $post The post object.
1710
- * @global object $wpmem The WP_Members object.
1711
- *
1712
- * @param string $content
1713
- * @return string $content
1714
- */
1715
- function do_excerpt( $content ) {
1716
-
1717
- global $post, $more, $wpmem;
1718
-
1719
- if ( is_object( $post ) ) {
1720
-
1721
- $post_id = $post->ID;
1722
- $post_type = $post->post_type;
1723
-
1724
- $autoex = ( isset( $wpmem->autoex[ $post->post_type ] ) && 1 == $wpmem->autoex[ $post->post_type ]['enabled'] ) ? $wpmem->autoex[ $post->post_type ] : false;
1725
-
1726
- // Is there already a 'more' link in the content?
1727
- $has_more_link = ( stristr( $content, 'class="more-link"' ) ) ? true : false;
1728
-
1729
- // If auto_ex is on.
1730
- if ( $autoex ) {
1731
-
1732
- // Build an excerpt if one does not exist.
1733
- if ( ! $has_more_link ) {
1734
-
1735
- $is_singular = ( is_singular( $post->post_type ) ) ? true : false;
1736
-
1737
- if ( $is_singular ) {
1738
- // If it's a single post, we don't need the 'more' link.
1739
- $more_link_text = '';
1740
- $more_link = '';
1741
- } else {
1742
- // The default $more_link_text.
1743
- if ( isset( $wpmem->autoex[ $post->post_type ]['text'] ) && '' != $wpmem->autoex[ $post->post_type ]['text'] ) {
1744
- $more_link_text = __( $wpmem->autoex[ $post->post_type ]['text'], 'wp-members' );
1745
- } else {
1746
- $more_link_text = __( '(more&hellip;)' );
1747
- }
1748
- // The default $more_link.
1749
- $more_link = ' <a href="'. get_permalink( $post->ID ) . '" class="more-link">' . $more_link_text . '</a>';
1750
- }
1751
-
1752
- // Apply the_content_more_link filter if one exists (will match up all 'more' link text).
1753
- /** This filter is documented in /wp-includes/post-template.php */
1754
- $more_link = apply_filters( 'the_content_more_link', $more_link, $more_link_text );
1755
-
1756
- $defaults = array(
1757
- 'length' => $autoex['length'],
1758
- 'more_link' => $more_link,
1759
- 'blocked_only' => false,
1760
- );
1761
- /**
1762
- * Filter auto excerpt defaults.
1763
- *
1764
- * @since 3.0.9
1765
- * @since 3.1.5 Deprecated add_ellipsis, strip_tags, close_tags, parse_shortcodes, strip_shortcodes.
1766
- *
1767
- * @param array {
1768
- * An array of settings to override the function defaults.
1769
- *
1770
- * @type int $length The default length of the excerpt.
1771
- * @type string $more_link The more link HTML.
1772
- * @type boolean $blocked_only Run autoexcerpt only on blocked content. default: false.
1773
- * }
1774
- * @param string $post->ID The post ID.
1775
- * @param string $post->post_type The content's post type.
1776
- */
1777
- $args = apply_filters( 'wpmem_auto_excerpt_args', '', $post->ID, $post->post_type );
1778
-
1779
- // Merge settings.
1780
- $args = wp_parse_args( $args, $defaults );
1781
-
1782
- // Are we only excerpting blocked content?
1783
- if ( $args['blocked_only'] ) {
1784
- $post_meta = get_post_meta( $post->ID, '_wpmem_block', true );
1785
- if ( 1 == $wpmem->block[ $post->post_type ] ) {
1786
- // Post type is blocked, if post meta unblocks it, don't do excerpt.
1787
- $do_excerpt = ( "0" == $post_meta ) ? false : true;
1788
- } else {
1789
- // Post type is unblocked, if post meta blocks it, do excerpt.
1790
- $do_excerpt = ( "1" == $post_meta ) ? true : false;
1791
- }
1792
- } else {
1793
- $do_excerpt = true;
1794
- }
1795
-
1796
- if ( true === $do_excerpt ) {
1797
- $content = wp_trim_words( $content, $args['length'], $args['more_link'] );
1798
- // Check if the more link was added (note: singular has no more_link):
1799
- if ( ! $is_singular && ! strpos( $content, $args['more_link'] ) ) {
1800
- $content = $content . $args['more_link'];
1801
- }
1802
- }
1803
- }
1804
- }
1805
- } else {
1806
- $post_id = false;
1807
- $post_type = false;
1808
- }
1809
-
1810
- /**
1811
- * Filter the auto excerpt.
1812
- *
1813
- * @since 2.8.1
1814
- * @since 3.0.9 Added post ID and post type parameters.
1815
- * @since 3.2.5 Post ID and post type may be false if there is no post object.
1816
- *
1817
- * @param string $content The content excerpt.
1818
- * @param string $post_id The post ID.
1819
- * @param string $post_type The content's post type.
1820
- */
1821
- $content = apply_filters( 'wpmem_auto_excerpt', $content, $post_id, $post_type );
1822
-
1823
- // Return the excerpt.
1824
- return $content;
1825
- }
1826
-
1827
- /**
1828
- * Convert form tag.
1829
- *
1830
- * @todo This is temporary to handle form tag conversion.
1831
- *
1832
- * @since 3.1.7
1833
- * @since 3.2.3 Moved to WP_Members class.
1834
- *
1835
- * @param string $tag
1836
- * @return string $tag
1837
- */
1838
- function convert_tag( $tag ) {
1839
- switch ( $tag ) {
1840
- case 'new':
1841
- return 'register';
1842
- break;
1843
- case 'edit':
1844
- case 'update':
1845
- return 'profile';
1846
- break;
1847
- case 'wp':
1848
- case 'wp_validate':
1849
- case 'wp_finalize':
1850
- return 'register_wp';
1851
- break;
1852
- case 'dashboard_profile':
1853
- case 'dashboard_profile_update':
1854
- return 'profile_dashboard';
1855
- break;
1856
- case 'admin_profile':
1857
- case 'admin_profile_update':
1858
- return 'profile_admin';
1859
- break;
1860
- default:
1861
- return $tag;
1862
- break;
1863
- }
1864
- return $tag;
1865
- }
1866
-
1867
- /**
1868
- * Loads translation files.
1869
- *
1870
- * @since 3.0.0
1871
- * @since 3.2.5 Moved to main object, dropped wpmem_ stem.
1872
- */
1873
- function load_textdomain() {
1874
-
1875
- // @see: https://ulrich.pogson.ch/load-theme-plugin-translations for notes on changes.
1876
-
1877
- // Plugin textdomain.
1878
- $domain = 'wp-members';
1879
-
1880
- // Wordpress locale.
1881
- /** This filter is documented in wp-includes/l10n.php */
1882
- $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
1883
-
1884
- /**
1885
- * Filter translation file.
1886
- *
1887
- * If the translate.wordpress.org language pack is available, it will
1888
- * be /wp-content/languages/plugins/wp-members-{locale}.mo by default.
1889
- * You can filter this if you want to load a language pack from a
1890
- * different location (or different file name).
1891
- *
1892
- * @since 3.0.0
1893
- * @since 3.2.0 Added locale as a parameter.
1894
- *
1895
- * @param string $file The translation file to load.
1896
- * @param string $locale The current locale.
1897
- */
1898
- $file = apply_filters( 'wpmem_localization_file', trailingslashit( WP_LANG_DIR ) . 'plugins/' . $domain . '-' . $locale . '.mo', $locale );
1899
-
1900
- $loaded = load_textdomain( $domain, $file );
1901
- if ( $loaded ) {
1902
- return $loaded;
1903
- } else {
1904
- /**
1905
- * Filter translation directory.
1906
- *
1907
- * @since 3.0.3
1908
- * @since 3.2.0 Added locale as a parameter.
1909
- *
1910
- * @param string $dir The translation directory.
1911
- * @param string $locale The current locale.
1912
- */
1913
- $dir = apply_filters( 'wpmem_localization_dir', basename( $this->path ) . '/i18n/languages/', $locale );
1914
- load_plugin_textdomain( $domain, FALSE, $dir );
1915
- }
1916
- return;
1917
- }
1918
-
1919
- /**
1920
- * Load default tos template.
1921
- *
1922
- * @since 3.2.8
1923
- */
1924
- function load_default_tos() {
1925
- // Check for custom template or load default.
1926
- $custom_template = get_stylesheet_directory() . '/wp-members/templates/tos.php';
1927
- if ( file_exists( $custom_template ) ) {
1928
- require_once( $custom_template );
1929
- } else {
1930
- require_once( $this->path . 'templates/tos.php' );
1931
- }
1932
- }
1933
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1934
  } // End of WP_Members class.
1
+ <?php
2
+ /**
3
+ * The WP_Members Class.
4
+ *
5
+ * This is the main WP_Members object class. This class contains functions
6
+ * for loading settings, shortcodes, hooks to WP, plugin dropins, constants,
7
+ * and registration fields. It also manages whether content should be blocked.
8
+ *
9
+ * @package WP-Members
10
+ * @subpackage WP_Members Object Class
11
+ * @since 3.0.0
12
+ */
13
+
14
+ // Exit if accessed directly.
15
+ if ( ! defined( 'ABSPATH' ) ) {
16
+ exit();
17
+ }
18
+
19
+ class WP_Members {
20
+
21
+ /**
22
+ * Plugin version.
23
+ *
24
+ * @since 3.0.0
25
+ * @access public
26
+ * @var string
27
+ */
28
+ public $version = WPMEM_VERSION;
29
+
30
+ /**
31
+ * Database version
32
+ *
33
+ * @since 3.2.2
34
+ * @access public
35
+ * @var string
36
+ */
37
+ public $db_version = WPMEM_DB_VERSION;
38
+
39
+ /**
40
+ * Plugin path.
41
+ *
42
+ * @since 3.3.0
43
+ * @access public
44
+ * @var string
45
+ */
46
+ public $path;
47
+
48
+ /**
49
+ * Plugin __FILE__.
50
+ *
51
+ * @since 3.3.0
52
+ * @access public
53
+ * @var string
54
+ */
55
+ public $name;
56
+
57
+ /**
58
+ * Plugin slug.
59
+ *
60
+ * @since 3.3.0
61
+ * @access public
62
+ * @var string
63
+ */
64
+ public $slug;
65
+
66
+ /**
67
+ * Plugin URL.
68
+ *
69
+ * @since 3.3.0
70
+ * @access public
71
+ * @var string
72
+ */
73
+ public $url;
74
+
75
+
76
+ /**
77
+ * Content block settings.
78
+ *
79
+ * @since 3.0.0
80
+ * @access public
81
+ * @var array
82
+ */
83
+ public $block;
84
+
85
+ /**
86
+ * Excerpt settings.
87
+ *
88
+ * @since 3.0.0
89
+ * @access public
90
+ * @var array
91
+ */
92
+ public $show_excerpt;
93
+
94
+ /**
95
+ * Show login form settings.
96
+ *
97
+ * @since 3.0.0
98
+ * @access public
99
+ * @var array
100
+ */
101
+ public $show_login;
102
+
103
+ /**
104
+ * Show registration form settings.
105
+ *
106
+ * @since 3.0.0
107
+ * @access public
108
+ * @var array
109
+ */
110
+ public $show_reg;
111
+
112
+ /**
113
+ * Auto-excerpt settings.
114
+ *
115
+ * @since 3.0.0
116
+ * @access public
117
+ * @var array
118
+ */
119
+ public $autoex;
120
+
121
+ /**
122
+ * Notify admin settings.
123
+ *
124
+ * @since 3.0.0
125
+ * @access public
126
+ * @var string
127
+ */
128
+ public $notify;
129
+
130
+ /**
131
+ * Moderated registration settings.
132
+ *
133
+ * @since 3.0.0
134
+ * @access public
135
+ * @var string
136
+ */
137
+ public $mod_reg;
138
+
139
+ /**
140
+ * Captcha settings.
141
+ *
142
+ * @since 3.0.0
143
+ * @access public
144
+ * @var array
145
+ */
146
+ public $captcha;
147
+
148
+ /**
149
+ * Enable expiration extension settings.
150
+ *
151
+ * @since 3.0.0
152
+ * @access public
153
+ * @var string
154
+ */
155
+ public $use_exp;
156
+
157
+ /**
158
+ * Expiration extension enable trial period.
159
+ *
160
+ * @since 3.0.0
161
+ * @access public
162
+ * @var string
163
+ */
164
+ public $use_trial;
165
+
166
+ /**
167
+ *
168
+ *
169
+ * @since 3.0.0
170
+ * @access public
171
+ * @var array
172
+ */
173
+ public $warnings;
174
+
175
+ /**
176
+ * Enable drop-ins setting.
177
+ *
178
+ * @since 3.1.9
179
+ * @access public
180
+ * @var string
181
+ */
182
+ public $dropins = 0;
183
+
184
+ /**
185
+ * Container for enabled dropins.
186
+ *
187
+ * @since 3.1.9
188
+ * @access public
189
+ * @var array
190
+ */
191
+ public $dropins_enabled = array();
192
+
193
+ /**
194
+ * Current plugin action container.
195
+ *
196
+ * @since 3.0.0
197
+ * @access public
198
+ * @var string
199
+ */
200
+ public $action;
201
+
202
+ /**
203
+ * Regchk container.
204
+ *
205
+ * @since 3.0.0
206
+ * @access public
207
+ * @var string
208
+ */
209
+ public $regchk;
210
+
211
+ /**
212
+ * User page settings.
213
+ *
214
+ * @since 3.0.0
215
+ * @access public
216
+ * @var array
217
+ */
218
+ public $user_pages;
219
+
220
+ /**
221
+ * Custom Post Type settings.
222
+ *
223
+ * @since 3.0.0
224
+ * @access public
225
+ * @var array
226
+ */
227
+ public $post_types;
228
+
229
+ /**
230
+ * Setting for applying texturization.
231
+ *
232
+ * @since 3.1.7
233
+ * @access public
234
+ * @var boolean
235
+ */
236
+ public $texturize;
237
+
238
+ /**
239
+ * Enable product creation.
240
+ *
241
+ * @since 3.2.0
242
+ * @access public
243
+ * @var boolean
244
+ */
245
+ public $enable_products;
246
+
247
+ /**
248
+ * Enable logged-in menu clones.
249
+ *
250
+ * @since 3.2.0
251
+ * @access public
252
+ * @var string
253
+ */
254
+ public $clone_menus;
255
+
256
+ /**
257
+ * Container for error messages.
258
+ *
259
+ * @since 3.2.0
260
+ * @access public
261
+ * @var string
262
+ */
263
+ public $error;
264
+
265
+ /**
266
+ * Container for admin notices.
267
+ *
268
+ * @since 3.3.0
269
+ * @access public
270
+ * @var array
271
+ */
272
+ public $admin_notices;
273
+
274
+ /**
275
+ * Container for stylesheet setting.
276
+ *
277
+ * @since 3.2.7
278
+ * @access public
279
+ * @var string
280
+ */
281
+ public $select_style;
282
+
283
+ /**
284
+ * Container for dropin folder location.
285
+ *
286
+ * @since 3.3.0
287
+ * @access public
288
+ * @var string
289
+ */
290
+ public $dropin_dir;
291
+
292
+ /**
293
+ * REST conditional.
294
+ *
295
+ * @since 3.3.2
296
+ * @access public
297
+ * @var boolean
298
+ */
299
+ public $is_rest = false;
300
+
301
+ /**
302
+ * Plugin initialization function.
303
+ *
304
+ * @since 3.0.0
305
+ * @since 3.1.6 Dependencies now loaded by object.
306
+ */
307
+ function __construct() {
308
+
309
+ // Constants.
310
+ $this->path = plugin_dir_path( __DIR__ );
311
+ $this->name = $this->path . 'wp-members.php';
312
+ $this->slug = substr( basename( $this->name ), 0, -4 );
313
+ $this->url = plugin_dir_url ( __DIR__ );
314
+
315
+ // Load dependent files.
316
+ $this->load_dependencies();
317
+
318
+ /**
319
+ * Filter the options before they are loaded into constants.
320
+ *
321
+ * @since 2.9.0
322
+ * @since 3.0.0 Moved to the WP_Members class.
323
+ *
324
+ * @param array $this->settings An array of the WP-Members settings.
325
+ */
326
+ $settings = apply_filters( 'wpmem_settings', get_option( 'wpmembers_settings' ) );
327
+
328
+ // Validate that v3 settings are loaded.
329
+ if ( ! isset( $settings['version'] )
330
+ || $settings['version'] != $this->version
331
+ || ! isset( $settings['db_version'] )
332
+ || $settings['db_version'] != $this->db_version ) {
333
+ /**
334
+ * Load installation routine.
335
+ */
336
+ require_once( $this->path . 'includes/install.php' );
337
+ // Update settings.
338
+ /** This filter is documented in /inc/class-wp-members.php */
339
+ $settings = apply_filters( 'wpmem_settings', wpmem_do_install() );
340
+ }
341
+
342
+ // Assemble settings.
343
+ foreach ( $settings as $key => $val ) {
344
+ $this->$key = $val;
345
+ }
346
+
347
+ $this->load_user_pages();
348
+ $this->set_style();
349
+
350
+ $this->forms = new WP_Members_Forms; // Load forms.
351
+ $this->api = new WP_Members_API; // Load api.
352
+ $this->shortcodes = new WP_Members_Shortcodes(); // Load shortcodes.
353
+ $this->membership = new WP_Members_Products(); // Load membership plans
354
+ $this->email = new WP_Members_Email; // Load email functions
355
+ $this->user = new WP_Members_User( $this ); // Load user functions.
356
+ $this->menus = new WP_Members_Menus();
357
+ if ( $this->clone_menus ) {
358
+ $this->menus_clone = new WP_Members_Clone_Menus(); // Load clone menus.
359
+ }
360
+
361
+ // @todo Is this a temporary fix?
362
+ $this->email->load_from();
363
+
364
+ /**
365
+ * Fires after main settings are loaded.
366
+ *
367
+ * @since 3.0
368
+ * @deprecated 3.2.0 Use wpmem_after_init instead.
369
+ */
370
+ do_action( 'wpmem_settings_loaded' );
371
+
372
+ // Preload the expiration module, if available.
373
+ $exp_active = ( function_exists( 'wpmem_exp_init' ) || function_exists( 'wpmem_set_exp' ) ) ? true : false;
374
+ define( 'WPMEM_EXP_MODULE', $exp_active );
375
+
376
+ // Load actions and filters.
377
+ $this->load_hooks();
378
+
379
+ // Load contants.
380
+ $this->load_constants();
381
+
382
+ // Load dropins.
383
+ if ( $this->dropins ) {
384
+ $this->load_dropins();
385
+ }
386
+
387
+ // Check for anything that we should stop execution for (currently just the default tos).
388
+ if ( 'display' == wpmem_get( 'tos', false, 'get' ) ) {
389
+ // If themes are not loaded, we don't need them.
390
+ $user_themes = ( ! defined( 'WP_USE_THEMES' ) ) ? define( 'WP_USE_THEMES', false ) : '';
391
+ $this->load_default_tos();
392
+ die();
393
+ }
394
+ }
395
+
396
+ /**
397
+ * Plugin initialization function to load hooks.
398
+ *
399
+ * @since 3.0.0
400
+ */
401
+ function load_hooks() {
402
+
403
+ /**
404
+ * Fires before action and filter hooks load.
405
+ *
406
+ * @since 3.0.0
407
+ * @since 3.1.6 Fires before hooks load.
408
+ */
409
+ do_action( 'wpmem_load_hooks' );
410
+
411
+ // Add actions.
412
+
413
+ add_action( 'init', array( $this, 'load_textdomain' ) ); //add_action( 'plugins_loaded', 'wpmem_load_textdomain' );
414
+ add_action( 'init', array( $this->membership, 'add_cpt' ), 0 ); // Adds membership plans custom post type.
415
+ add_action( 'widgets_init', array( $this, 'widget_init' ) ); // initializes the widget
416
+ add_action( 'admin_init', array( $this, 'load_admin' ) ); // check user role to load correct dashboard
417
+ add_action( 'rest_api_init', array( $this, 'rest_init' ) );
418
+ add_action( 'template_redirect', array( $this, 'get_action' ) );
419
+ add_action( 'login_enqueue_scripts', array( $this, 'enqueue_style_wp_login' ) ); // styles the native registration
420
+ add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) ); // Enqueues the stylesheet.
421
+ add_action( 'wp_enqueue_scripts', array( $this, 'loginout_script' ) );
422
+ add_action( 'pre_get_posts', array( $this, 'do_hide_posts' ) );
423
+ add_action( 'customize_register', array( $this, 'customizer_settings' ) );
424
+ add_action( 'admin_menu', 'wpmem_admin_options' ); // adds admin menu
425
+
426
+ if ( is_user_logged_in() ) {
427
+ add_action( 'wpmem_pwd_change', array( $this->user, 'set_password' ), 9, 2 );
428
+ add_action( 'wpmem_pwd_change', array( $this->user, 'set_as_logged_in' ), 10 );
429
+ }
430
+
431
+ add_filter( 'register_form', 'wpmem_wp_register_form' ); // adds fields to the default wp registration
432
+ add_action( 'woocommerce_register_form', 'wpmem_woo_register_form' );
433
+
434
+ // Add filters.
435
+ add_filter( 'the_content', array( $this, 'do_securify' ), 99 );
436
+ add_filter( 'comments_open', array( $this, 'do_securify_comments' ), 99, 2 ); // securifies the comments
437
+ add_filter( 'wpmem_securify', array( $this, 'reg_securify' ) ); // adds success message on login form if redirected
438
+ add_filter( 'rest_prepare_post', array( $this, 'do_securify_rest' ), 10, 3 );
439
+ add_filter( 'rest_prepare_page', array( $this, 'do_securify_rest' ), 10, 3 );
440
+ foreach( $this->post_types as $post_type ) {
441
+ add_filter( "rest_prepare_{$post_type}", array( $this, 'do_securify_rest' ), 10, 3 );
442
+ }
443
+
444
+ //add_filter( 'query_vars', array( $this, 'add_query_vars' ), 10, 2 ); // adds custom query vars
445
+ add_filter( 'get_pages', array( $this, 'filter_get_pages' ) );
446
+ add_filter( 'wp_get_nav_menu_items', array( $this, 'filter_nav_menu_items' ), null, 3 );
447
+ add_filter( 'get_previous_post_where', array( $this, 'filter_get_adjacent_post_where' ) );
448
+ add_filter( 'get_next_post_where', array( $this, 'filter_get_adjacent_post_where' ) );
449
+ add_filter( 'allow_password_reset', array( $this->user, 'no_reset' ) ); // no password reset for non-activated users
450
+
451
+ // If registration is moderated, check for activation (blocks backend login by non-activated users).
452
+ if ( $this->mod_reg == 1 ) {
453
+ add_filter( 'authenticate', array( $this->user, 'check_activated' ), 99, 3 );
454
+ }
455
+
456
+ /**
457
+ * Fires after action and filter hooks load.
458
+ *
459
+ * @since 3.0.0
460
+ * @since 3.1.6 Was wpmem_load_hooks, now wpmem_hooks_loaded.
461
+ */
462
+ do_action( 'wpmem_hooks_loaded' );
463
+ }
464
+
465
+ /**
466
+ * Load drop-ins.
467
+ *
468
+ * @since 3.0.0
469
+ *
470
+ * @todo This is experimental. The function and its operation is subject to change.
471
+ */
472
+ function load_dropins() {
473
+
474
+ /**
475
+ * Fires before dropins load (for adding additional drop-ins).
476
+ *
477
+ * @since 3.0.0
478
+ * @since 3.1.6 Fires before dropins.
479
+ */
480
+ do_action( 'wpmem_load_dropins' );
481
+
482
+ /**
483
+ * Filters the drop-in file directory.
484
+ *
485
+ * @since 3.0.0
486
+ * @since 3.3.0 Filter previously unpublished, changed hook name.
487
+ *
488
+ * @param string $wpmem->dropin_dir The drop-in file directory.
489
+ */
490
+ $dir = apply_filters( 'wpmem_dropin_dir', $this->dropin_dir );
491
+
492
+ // Load any drop-ins.
493
+ $settings = get_option( 'wpmembers_dropins' );
494
+ $this->dropins_enabled = ( $settings ) ? $settings : array();
495
+ if ( ! empty( $this->dropins_enabled ) ) {
496
+ foreach ( $this->dropins_enabled as $filename ) {
497
+ $dropin = $dir . $filename;
498
+ if ( file_exists( $dropin ) ) {
499
+ include_once( $dropin );
500
+ }
501
+ }
502
+ }
503
+
504
+ /**
505
+ * Fires before dropins load (for adding additional drop-ins).
506
+ *
507
+ * @since 3.0.0
508
+ * @since 3.1.6 Was wpmem_load_dropins, now wpmem_dropins_loaded.
509
+ */
510
+ do_action( 'wpmem_dropins_loaded' );
511
+ }
512
+
513
+ /**
514
+ * Loads pre-3.0 constants (included primarily for add-on compatibility).
515
+ *
516
+ * @since 3.0.0
517
+ * @since 3.3.0 Deprecated all but exp and trl constants.
518
+ */
519
+ function load_constants() {
520
+ ( ! defined( 'WPMEM_MOD_REG' ) ) ? define( 'WPMEM_MOD_REG', $this->mod_reg ) : '';
521
+ ( ! defined( 'WPMEM_USE_EXP' ) ) ? define( 'WPMEM_USE_EXP', $this->use_exp ) : '';
522
+ ( ! defined( 'WPMEM_USE_TRL' ) ) ? define( 'WPMEM_USE_TRL', $this->use_trial ) : '';
523
+ }
524
+
525
+ /**
526
+ * Load dependent files.
527
+ *
528
+ * @since 3.1.6
529
+ */
530
+ function load_dependencies() {
531
+
532
+ /**
533
+ * Filter the location and name of the pluggable file.
534
+ *
535
+ * @since 2.9.0
536
+ * @since 3.1.6 Moved in load order to come before dependencies.
537
+ *
538
+ * @param string The path to WP-Members plugin functions file.
539
+ */
540
+ $wpmem_pluggable = apply_filters( 'wpmem_plugins_file', WP_PLUGIN_DIR . '/wp-members-pluggable.php' );
541
+
542
+ // Preload any custom functions, if available.
543
+ if ( file_exists( $wpmem_pluggable ) ) {
544
+ include( $wpmem_pluggable );
545
+ }
546
+
547
+ require_once( $this->path . 'includes/class-wp-members-api.php' );
548
+ require_once( $this->path . 'includes/class-wp-members-clone-menus.php' );
549
+ require_once( $this->path . 'includes/class-wp-members-captcha.php' );
550
+ require_once( $this->path . 'includes/class-wp-members-email.php' );
551
+ require_once( $this->path . 'includes/class-wp-members-forms.php' );
552
+ require_once( $this->path . 'includes/class-wp-members-menus.php' );
553
+ require_once( $this->path . 'includes/class-wp-members-products.php' );
554
+ require_once( $this->path . 'includes/class-wp-members-shortcodes.php' );
555
+ require_once( $this->path . 'includes/class-wp-members-user.php' );
556
+ require_once( $this->path . 'includes/class-wp-members-user-profile.php' );
557
+ require_once( $this->path . 'includes/class-wp-members-widget.php' );
558
+ require_once( $this->path . 'includes/api/api.php' );
559
+ require_once( $this->path . 'includes/api/api-email.php' );
560
+ require_once( $this->path . 'includes/api/api-forms.php' );
561
+ require_once( $this->path . 'includes/api/api-products.php' );
562
+ require_once( $this->path . 'includes/api/api-users.php' );
563
+ require_once( $this->path . 'includes/api/api-utilities.php' );
564
+ require_once( $this->path . 'includes/legacy/dialogs.php' );
565
+ require_once( $this->path . 'includes/deprecated.php' );
566
+ }
567
+
568
+ /**
569
+ * Load admin API and dependencies.
570
+ *
571
+ * Determines which scripts to load and actions to use based on the
572
+ * current users capabilities.
573
+ *
574
+ * @since 2.5.2
575
+ * @since 3.1.0 Added admin api object.
576
+ * @since 3.1.7 Moved from main plugin file as wpmem_chk_admin() to main object.
577
+ */
578
+ function load_admin() {
579
+
580
+ /**
581
+ * Fires before initialization of admin options.
582
+ *
583
+ * @since 2.9.0
584
+ */
585
+ do_action( 'wpmem_pre_admin_init' );
586
+
587
+ // Initilize the admin api.
588
+ if ( is_admin() ) {
589
+ /**
590
+ * Load the admin api class.
591
+ *
592
+ * @since 3.1.0
593
+ */
594
+ include_once( $this->path . 'includes/admin/class-wp-members-admin-api.php' );
595
+ $this->admin = new WP_Members_Admin_API;
596
+ }
597
+
598
+ /**
599
+ * Fires after initialization of admin options.
600
+ *
601
+ * @since 2.9.0
602
+ */
603
+ do_action( 'wpmem_after_admin_init' );
604
+ }
605
+
606
+ /**
607
+ * Gets the requested action.
608
+ *
609
+ * @since 3.0.0
610
+ *
611
+ * @global string $wpmem_a The WP-Members action variable.
612
+ */
613
+ function get_action() {
614
+
615
+ // Get the action being done (if any).
616
+ $this->action = sanitize_text_field( wpmem_get( 'a', '', 'request' ) );
617
+
618
+ // For backward compatibility with processes that check $wpmem_a.
619
+ global $wpmem_a;
620
+ $wpmem_a = $this->action;
621
+
622
+ /**
623
+ * Fires when the wpmem action is retrieved.
624
+ *
625
+ * @since 3.1.7
626
+ */
627
+ do_action( 'wpmem_get_action' );
628
+
629
+ // Get the regchk value (if any).
630
+ $this->regchk = $this->get_regchk( $this->action );
631
+ }
632
+
633
+ /**
634
+ * Gets the regchk value.
635
+ *
636
+ * regchk is a legacy variable that contains information about the current
637
+ * action being performed. Login, logout, password, registration, profile
638
+ * update functions all return a specific value that is stored in regchk.
639
+ * This value and information about the current action can then be used to
640
+ * determine what content is to be displayed by the securify function.
641
+ *
642
+ * @since 3.0.0
643
+ *
644
+ * @global string $wpmem_a The WP-Members action variable.
645
+ *
646
+ * @param string $action The current action.
647
+ * @return string The regchk value.
648
+ */
649
+ function get_regchk( $action ) {
650
+
651
+ switch ( $action ) {
652
+
653
+ case 'login':
654
+ $regchk = $this->user->login();
655
+ break;
656
+
657
+ case 'logout':
658
+ $regchk = $this->user->logout();
659
+ break;
660
+
661
+ case 'pwdchange':
662
+ $regchk = $this->user->password_update( 'change' );
663
+ break;
664
+
665
+ case 'pwdreset':
666
+ $regchk = $this->user->password_update( 'reset' );
667
+ break;
668
+
669
+ case 'getusername':
670
+ $regchk = $this->user->retrieve_username();
671
+ break;
672
+
673
+ case 'register':
674
+ case 'update':
675
+ $regchk = wpmem_user_register( $action );
676
+ break;
677
+
678
+ default:
679
+ $regchk = ( isset( $regchk ) ) ? $regchk : '';
680
+ break;
681
+ }
682
+
683
+ /**
684
+ * Filter wpmem_regchk.
685
+ *
686
+ * The value of regchk is determined by functions that may be run in the get_regchk function.
687
+ * This value determines what happens in the wpmem_securify() function.
688
+ *
689
+ * @since 2.9.0
690
+ * @since 3.0.0 Moved to get_regchk() in WP_Members object.
691
+ *
692
+ * @param string $this->regchk The value of wpmem_regchk.
693
+ * @param string $this->action The $wpmem_a action.
694
+ */
695
+ $regchk = apply_filters( 'wpmem_regchk', $regchk, $action );
696
+
697
+ // Legacy global variable for use with older extensions.
698
+ global $wpmem_regchk;
699
+ $wpmem_regchk = $regchk;
700
+
701
+ return $regchk;
702
+ }
703
+
704
+ /**
705
+ * Determines if content should be blocked.
706
+ *
707
+ * This function was originally stand alone in the core file and
708
+ * was moved to the WP_Members class in 3.0.
709
+ *
710
+ * @since 3.0.0
711
+ * @since 3.3.0 Added $post_id
712
+ *
713
+ * @global object $post The WordPress Post object.
714
+ *
715
+ * @param int $post_id
716
+ * @return bool $block true|false
717
+ */
718
+ function is_blocked( $post_id = false ) {
719
+
720
+ global $post;
721
+
722
+ if ( $post || $post_id ) {
723
+
724
+ $the_post = ( false === $post_id ) ? $post : get_post( $post_id );
725
+
726
+ $meta = wpmem_get_block_setting( $the_post->ID );
727
+
728
+ // Backward compatibility for old block/unblock meta.
729
+ if ( ! $meta ) {
730
+ // Check for old meta.
731
+ $old_block = get_post_meta( $the_post->ID, 'block', true );
732
+ $old_unblock = get_post_meta( $the_post->ID, 'unblock', true );
733
+ $meta = ( $old_block ) ? 1 : ( ( $old_unblock ) ? 0 : $meta );
734
+ }
735
+
736
+ // Setup defaults.
737
+ $defaults = array(
738
+ 'post_id' => $the_post->ID,
739
+ 'post_type' => $the_post->post_type,
740
+ 'block' => ( isset( $this->block[ $the_post->post_type ] ) && $this->block[ $the_post->post_type ] == 1 ) ? true : false,
741
+ 'block_meta' => $meta,
742
+ 'block_type' => ( isset( $this->block[ $the_post->post_type ] ) ) ? $this->block[ $the_post->post_type ] : 0,
743
+ );
744
+
745
+ /**
746
+ * Filter the block arguments.
747
+ *
748
+ * @since 2.9.8
749
+ * @since 3.0.0 Moved to is_blocked() in WP_Members object.
750
+ * @since 3.3.0 Passes $defaults, second argument deprecated.
751
+ *
752
+ * @param array $args $defaults.
753
+ * @param array $defaults Deprecated 3.3.0.
754
+ */
755
+ $args = apply_filters( 'wpmem_block_args', $defaults, $defaults );
756
+
757
+ // Merge $args with defaults.
758
+ $args = ( wp_parse_args( $args, $defaults ) );
759
+
760
+ if ( is_single() || is_page() || wpmem_is_rest() ) {
761
+ switch( $args['block_type'] ) {
762
+ case 1: // If content is blocked by default.
763
+ $args['block'] = ( $args['block_meta'] == '0' ) ? false : $args['block'];
764
+ break;
765
+ case 0 : // If content is unblocked by default.
766
+ $args['block'] = ( $args['block_meta'] == '1' ) ? true : $args['block'];
767
+ break;
768
+ }
769
+
770
+ } else {
771
+ $args['block'] = false;
772
+ }
773
+
774
+ } else {
775
+ $args = array( 'block' => false );
776
+ }
777
+
778
+ // Don't block user pages.
779
+ $args['block'] = ( in_array( get_permalink(), $this->user_pages ) ) ? false : $args['block'];
780
+
781
+ /**
782
+ * Filter the block boolean.
783
+ *
784
+ * @since 2.7.5
785
+ *
786
+ * @param bool $args['block']
787
+ * @param array $args {
788
+ * An array of arguments used in the function.
789
+ *
790
+ * @type string $post_id
791
+ * @type string $post_type
792
+ * @type string $block
793
+ * @type string $block_meta
794
+ * @tyep string $block_type
795
+ * }
796
+ */
797
+ return apply_filters( 'wpmem_block', $args['block'], $args );
798
+ }
799
+
800
+ /**
801
+ * The Securify Content Filter.
802
+ *
803
+ * This is the primary function that picks up where get_action() leaves off.
804
+ * Determines whether content is shown or hidden for both post and pages. This
805
+ * is a filter function for the_content.
806
+ *
807
+ * @link https://developer.wordpress.org/reference/functions/the_content/
808
+ * @link https://developer.wordpress.org/reference/hooks/the_content/
809
+ *
810
+ * @since 3.0.0
811
+ *
812
+ * @global object $post The WordPress Post object.
813
+ * @global object $wpmem The WP_Members object.
814
+ * @global string $wpmem_themsg Contains messages to be output.
815
+ * @param string $content
816
+ * @return string $content
817
+ */
818
+ function do_securify( $content = null ) {
819
+
820
+ global $post, $wpmem, $wpmem_themsg;
821
+
822
+ $content = ( is_single() || is_page() ) ? $content : wpmem_do_excerpt( $content );
823
+
824
+ if ( $this->regchk == "captcha" ) {
825
+ global $wpmem_captcha_err;
826
+ $wpmem_themsg = $wpmem->get_text( 'reg_captcha_err' ) . '<br /><br />' . $wpmem_captcha_err;
827
+ }
828
+
829
+ // Block/unblock Posts.
830
+ if ( ! is_user_logged_in() && $this->is_blocked() == true ) {
831
+
832
+ //Show the login and registration forms.
833
+ if ( $this->regchk ) {
834
+
835
+ // Empty content in any of these scenarios.
836
+ $content = '';
837
+
838
+ switch ( $this->regchk ) {
839
+
840
+ case "loginfailed":
841
+ $content = wpmem_inc_loginfailed();
842
+ break;
843
+
844
+ case "success":
845
+ $content = wpmem_inc_regmessage( $this->regchk, $wpmem_themsg );
846
+ $content = $content . wpmem_inc_login();
847
+ break;
848
+
849
+ default:
850
+ $content = wpmem_inc_regmessage( $this->regchk, $wpmem_themsg );
851
+ $content = $content . wpmem_register_form();
852
+ break;
853
+ }
854
+
855
+ } else {
856
+
857
+ // Toggle shows excerpt above login/reg on posts/pages.
858
+ global $wp_query;
859
+ if ( isset( $wp_query->query_vars['page'] ) && $wp_query->query_vars['page'] > 1 ) {
860
+
861
+ // Shuts down excerpts on multipage posts if not on first page.
862
+ $content = '';
863
+
864
+ } elseif ( isset( $this->show_excerpt[ $post->post_type ] ) && $this->show_excerpt[ $post->post_type ] == 1 ) {
865
+
866
+ $len = strpos( $content, '<span id="more' );
867
+ if ( false === $len ) {
868
+ $content = wpmem_do_excerpt( $content );
869
+ } else {
870
+ $content = substr( $content, 0, $len );
871
+ }
872
+
873
+ } else {
874
+
875
+ // Empty all content.
876
+ $content = '';
877
+
878
+ }
879
+
880
+ $content = ( isset( $this->show_login[ $post->post_type ] ) && $this->show_login[ $post->post_type ] == 1 ) ? $content . wpmem_inc_login() : $content . wpmem_inc_login( 'page', '', 'hide' );
881
+
882
+ $content = ( isset( $this->show_reg[ $post->post_type ] ) && $this->show_reg[ $post->post_type ] == 1 ) ? $content . wpmem_register_form() : $content;
883
+ }
884
+
885
+ // Protects comments if expiration module is used and user is expired.
886
+ } elseif ( is_user_logged_in() && $this->is_blocked() == true ){
887
+
888
+ if ( $this->use_exp == 1 && function_exists( 'wpmem_do_expmessage' ) ) {
889
+ /**
890
+ * Filters the user expired message used by the PayPal extension.
891
+ *
892
+ * @since 3.2.0
893
+ *
894
+ * @param string $message
895
+ * @param string $content
896
+ */
897
+ $content = apply_filters( 'wpmem_do_expmessage', wpmem_do_expmessage( $content ), $content );
898
+ }
899
+ }
900
+
901
+ /**
902
+ * Filter the value of $content after wpmem_securify has run.
903
+ *
904
+ * @since 2.7.7
905
+ * @since 3.0.0 Moved to new method in WP_Members Class.
906
+ *
907
+ * @param string $content The content after securify has run.
908
+ */
909
+ $content = apply_filters( 'wpmem_securify', $content );
910
+
911
+ if ( 1 == $this->texturize && strstr( $content, '[wpmem_txt]' ) ) {
912
+ // Fix the wptexturize.
913
+ remove_filter( 'the_content', 'wpautop' );
914
+ remove_filter( 'the_content', 'wptexturize' );
915
+ add_filter( 'the_content', array( $this, 'texturize' ), 999 );
916
+ }
917
+
918
+ return $content;
919
+
920
+ }
921
+
922
+ /**
923
+ * Securifies the comments.
924
+ *
925
+ * If the user is not logged in and the content is blocked
926
+ * (i.e. wpmem->is_blocked() returns true), function loads a
927
+ * dummy/empty comments template.
928
+ *
929
+ * @since 2.9.9
930
+ * @since 3.2.0 Moved wpmem_securify_comments() to main class, renamed.
931
+ * @since 3.3.2 Added $post_id.
932
+ *
933
+ * @param bool $open Whether the current post is open for comments.
934
+ * @param int $post_id The post ID.
935
+ * @return bool $open True if current post is open for comments, otherwise false.
936
+ */
937
+ function do_securify_comments( $open, $post_id ) {
938
+
939
+ $open = ( ! is_user_logged_in() && wpmem_is_blocked( $post_id ) ) ? false : $open;
940
+
941
+ /**
942
+ * Filters whether comments are open or not.
943
+ *
944
+ * @since 3.0.0
945
+ * @since 3.2.0 Moved to main class.
946
+ * @since 3.3.2 Added $post_id.
947
+ *
948
+ * @param bool $open true if current post is open for comments, otherwise false.
949
+ */
950
+ $open = apply_filters( 'wpmem_securify_comments', $open, $post_id );
951
+
952
+ if ( ! $open ) {
953
+ /** This filter is documented in wp-includes/comment-template.php */
954
+ add_filter( 'comments_array', array( $this, 'do_securify_comments_array' ), 10, 2 );
955
+ }
956
+
957
+ return $open;
958
+ }
959
+
960
+ /**
961
+ * Empties the comments array if content is blocked.
962
+ *
963
+ * @since 3.0.1
964
+ * @since 3.2.0 Moved wpmem_securify_comments_array() to main class, renamed.
965
+ *
966
+ * @param array $comments
967
+ * @param int $post_id
968
+ * @return array $comments The comments array.
969
+ */
970
+ function do_securify_comments_array( $comments , $post_id ) {
971
+ $comments = ( ! is_user_logged_in() && wpmem_is_blocked( $post_id ) ) ? array() : $comments;
972
+ return $comments;
973
+ }
974
+
975
+ /**
976
+ * Handles REST request.
977
+ *
978
+ * @since 3.3.2
979
+ *
980
+ * @param WP_REST_Response $response The response object.
981
+ * @param WP_Post $post Post object.
982
+ * @param WP_REST_Request $request Request object.
983
+ * @return
984
+ */
985
+ function do_securify_rest( $response, $post, $request ) {
986
+
987
+ if ( ! is_user_logged_in() ) { // @todo This needs to be changed to check for whether the user has access (for internal requests).
988
+ // Response for restricted content
989
+ $block_value = wpmem_is_blocked( $response->data['id'] );
990
+ if ( $block_value ) {
991
+ if ( isset( $response->data['content']['rendered'] ) ) {
992
+ /**
993
+ * Filters restricted content message.
994
+ *
995
+ * @since 3.3.2
996
+ *
997
+ * @param string $message
998
+ */
999
+ $response->data['content']['rendered'] = apply_filters( "wpmem_securify_rest_{$post->post_type}_content", __( "You must be logged in to view this content.", 'wp-members' ) );
1000
+ }
1001
+ if ( isset( $response->data['excerpt']['rendered'] ) ) {
1002
+ /**
1003
+ * Filters restricted excerpt message.
1004
+ *
1005
+ * @since 3.3.2
1006
+ *
1007
+ * @param string $message
1008
+ */
1009
+ $response->data['excerpt']['rendered'] = apply_filters( "wpmem_securify_rest_{$post->post_type}_excerpt", __( "You must be logged in to view this content.", 'wp-members' ) );
1010
+ }
1011
+ }
1012
+
1013
+ // Response for hidden content. @todo This needs to be changed to check for whether the user has access (for internal requests).
1014
+ if ( ! is_admin() && in_array( $post->ID, $this->hidden_posts() ) ) {
1015
+ return new WP_REST_Response( __( 'The page you are looking for does not exist', 'wp-members' ), 404 );
1016
+ }
1017
+ }
1018
+ return $response;
1019
+ }
1020
+
1021
+ /**
1022
+ * Adds the successful registration message on the login page if reg_nonce validates.
1023
+ *
1024
+ * @since 3.1.7
1025
+ * @since 3.2.0 Moved to wpmem object, renamed reg_securify()
1026
+ *
1027
+ * @param string $content
1028
+ * @return string $content
1029
+ */
1030
+ function reg_securify( $content ) {
1031
+ global $wpmem, $wpmem_themsg;
1032
+ $nonce = wpmem_get( 'reg_nonce', false, 'get' );
1033
+ if ( $nonce && wp_verify_nonce( $nonce, 'register_redirect' ) ) {
1034
+ $content = wpmem_inc_regmessage( 'success', $wpmem_themsg );
1035
+ $content = $content . wpmem_inc_login();
1036
+ }
1037
+ return $content;
1038
+ }
1039
+
1040
+ /**
1041
+ * Runs if the REST API is initialized.
1042
+ *
1043
+ * @since 3.3.2
1044
+ */
1045
+ function rest_init() {
1046
+ $this->is_rest = true;
1047
+ }
1048
+
1049
+ /**
1050
+ * Gets an array of hidden post IDs.
1051
+ *
1052
+ * @since 3.2.0
1053
+ *
1054
+ * @global object $wpdb
1055
+ * @return array $hidden
1056
+ */
1057
+ function hidden_posts() {
1058
+ global $wpdb;
1059
+ $hidden = get_transient( '_wpmem_hidden_posts' );
1060
+ if ( false === $hidden ) {
1061
+ $hidden = $this->update_hidden_posts();
1062
+ }
1063
+ return $hidden;
1064
+ }
1065
+
1066
+ /**
1067
+ * Updates the hidden post array transient.
1068
+ *
1069
+ * @since 3.2.0
1070
+ * @since 3.3.3 Don't include posts from post types not set as handled by WP-Members.
1071
+ *
1072
+ * @global object $wpdb
1073
+ * @return array $hidden
1074
+ */
1075
+ function update_hidden_posts() {
1076
+ global $wpdb;
1077
+ $hidden = array();
1078
+ $default_post_types = array( 'post'=>'Posts', 'page'=>'Page' );
1079
+ $post_types = array_merge( $this->post_types, $default_post_types );
1080
+ // $results = $wpdb->get_results( "SELECT post_id FROM " . $wpdb->prefix . "postmeta WHERE meta_key = '_wpmem_block' AND meta_value = 2" );
1081
+ $results = $wpdb->get_results(
1082
+ "SELECT
1083
+ p1.id,
1084
+ p1.post_type,
1085
+ m1.meta_key AS _wpmem_block
1086
+ FROM " . $wpdb->prefix . "posts p1
1087
+ JOIN " . $wpdb->prefix . "postmeta m1 ON (m1.post_id = p1.id AND m1.meta_key = '_wpmem_block')
1088
+ WHERE m1.meta_value = '2';"
1089
+ );
1090
+ foreach( $results as $result ) {
1091
+ if ( array_key_exists( $result->post_type, $post_types ) ) {
1092
+ $hidden[] = $result->id;
1093
+ }
1094
+ }
1095
+ set_transient( '_wpmem_hidden_posts', $hidden, 60*5 );
1096
+ return $hidden;
1097
+ }
1098
+
1099
+ /**
1100
+ * Gets an array of hidden post IDs.
1101
+ *
1102
+ * @since 3.2.0
1103
+ *
1104
+ * @global stdClass $wpdb
1105
+ * @return array $hidden
1106
+ */
1107
+ function get_hidden_posts() {
1108
+ $hidden = array();
1109
+
1110
+ // Return empty array if this is the admin and user can edit posts.
1111
+ if ( is_admin() && current_user_can( 'edit_posts' ) ) {
1112
+ return $hidden;
1113
+ }
1114
+
1115
+ // If the user is not logged in, return all hidden posts.
1116
+ if ( ! is_user_logged_in() ) {
1117
+ $hidden = $this->hidden_posts();
1118
+ } else {
1119
+ // If the user is logged in.
1120
+ if ( 1 == $this->enable_products ) {
1121
+ // Get user product access.
1122
+ $hidden = $this->hidden_posts();
1123
+ $hidden = ( is_array( $hidden ) ) ? $hidden : array();
1124
+
1125
+ // Remove posts with a product the user has access to.
1126
+ foreach ( $this->membership->products as $key => $value ) {
1127
+ if ( isset( $this->user->access[ $key ] ) && ( true == $this->user->access[ $key ] || $this->user->is_current( $this->user->access[ $key ] ) ) ) {
1128
+ foreach ( $hidden as $post_id ) {
1129
+ if ( 1 == get_post_meta( $post_id, $this->membership->post_stem . $key, true ) ) {
1130
+ $hidden_key = array_search( $post_id, $hidden );
1131
+ unset( $hidden[ $hidden_key ] );
1132
+ }
1133
+ }
1134
+ }
1135
+ }
1136
+
1137
+ // Remove posts that don't have a product assignment (general login).
1138
+ foreach( $hidden as $hidden_key ) {
1139
+ $unattached = get_post_meta( $hidden_key, '_wpmem_products', true );
1140
+ if ( false == $unattached ) {
1141
+ $hidden_key = array_search( $hidden_key, $hidden );
1142
+ unset( $hidden[ $hidden_key ] );
1143
+ }
1144
+ }
1145
+ }
1146
+ }
1147
+ return $hidden;
1148
+ }
1149
+
1150
+ /**
1151
+ * Hides posts based on settings and meta.
1152
+ *
1153
+ * @since 3.2.0
1154
+ *
1155
+ * @param array $query
1156
+ * @return array $query
1157
+ */
1158
+ function do_hide_posts( $query ) {
1159
+ $hidden_posts = $this->get_hidden_posts();
1160
+ if ( ! empty( $hidden_posts ) ) {
1161
+ $query->set( 'post__not_in', $hidden_posts );
1162
+ }
1163
+ return $query;
1164
+ }
1165
+
1166
+ /**
1167
+ * Filter to hide pages for get_pages().
1168
+ *
1169
+ * @since 3.2.0
1170
+ *
1171
+ * @global object $wpdb
1172
+ * @param array $pages
1173
+ * @return array $pages
1174
+ */
1175
+ function filter_get_pages( $pages ) {
1176
+ $hidden_posts = $this->get_hidden_posts();
1177
+ if ( ! empty ( $hidden_posts ) ) {
1178
+ $new_pages = array();
1179
+ foreach ( $pages as $key => $page ) {
1180
+ if ( ! in_array( $page->ID, $hidden_posts ) ) {
1181
+ $new_pages[ $key ] = $page;
1182
+ }
1183
+ }
1184
+ $pages = $new_pages;
1185
+ }
1186
+ return $pages;
1187
+ }
1188
+
1189
+ /**
1190
+ * Filter to hide menu items.
1191
+ *
1192
+ * @since 3.2.0
1193
+ *
1194
+ * @param array $items
1195
+ * @param $menu
1196
+ * @param array $args
1197
+ * @return array $items
1198
+ */
1199
+ function filter_nav_menu_items( $items, $menu, $args ) {
1200
+ $hidden_posts = $this->get_hidden_posts();
1201
+ if ( ! empty( $hidden_posts ) ) {
1202
+ foreach ( $items as $key => $item ) {
1203
+ if ( in_array( $item->object_id, $hidden_posts ) ) {
1204
+ unset( $items[ $key ] );
1205
+ }
1206
+ }
1207
+ }
1208
+ return $items;
1209
+ }
1210
+
1211
+ /**
1212
+ * Filter to remove hidden posts from prev/next links.
1213
+ *
1214
+ * @since 3.2.4
1215
+ *
1216
+ * @global object $wpmem
1217
+ * @param string $where
1218
+ * @return string $where
1219
+ */
1220
+ function filter_get_adjacent_post_where( $where ) {
1221
+ global $wpmem;
1222
+ if ( ! is_user_logged_in() ) {
1223
+ $hidden_posts = $this->get_hidden_posts();
1224
+ if ( ! empty( $hidden_posts ) ) {
1225
+ $hidden = implode( ",", $hidden_posts );
1226
+ $where = $where . " AND p.ID NOT IN ( $hidden )";
1227
+ }
1228
+ }
1229
+ return $where;
1230
+ }
1231
+
1232
+ /**
1233
+ * Sets the registration fields.
1234
+ *
1235
+ * @since 3.0.0
1236
+ * @since 3.1.5 Added $form argument.
1237
+ * @since 3.3.0 Added $tag argument.
1238
+ *
1239
+ * @param string $form The form being generated.
1240
+ */
1241
+ function load_fields( $tag = 'new', $form = 'default' ) {
1242
+
1243
+ // Get stored fields settings.
1244
+ $fields = get_option( 'wpmembers_fields' );
1245
+
1246
+ // Validate fields settings.
1247
+ if ( ! isset( $fields ) || empty( $fields ) ) {
1248
+ // Update settings.
1249
+ $fields = array( array( 10, 'Email', 'user_email', 'email', 'y', 'y', 'y', 'profile'=>true ) );
1250
+ }
1251
+
1252
+ // Add new field array keys
1253
+ foreach ( $fields as $key => $val ) {
1254
+
1255
+ // Key fields with meta key.
1256
+ $meta_key = $val[2];
1257
+
1258
+ // Old format, new key.
1259
+ foreach ( $val as $subkey => $subval ) {
1260
+ $this->fields[ $meta_key ][ $subkey ] = $subval;
1261
+ }
1262
+
1263
+ // Setup field properties.
1264
+ $this->fields[ $meta_key ]['label'] = $val[1];
1265
+ $this->fields[ $meta_key ]['type'] = $val[3];
1266
+ $this->fields[ $meta_key ]['register'] = ( 'y' == $val[4] ) ? true : false;
1267
+ $this->fields[ $meta_key ]['required'] = ( 'y' == $val[5] ) ? true : false;
1268
+ $this->fields[ $meta_key ]['profile'] = ( 'y' == $val[4] ) ? true : false;// ( isset( $val['profile'] ) ) ? $val['profile'] : true ; // // @todo Wait for profile fix
1269
+ $this->fields[ $meta_key ]['native'] = ( 'y' == $val[6] ) ? true : false;
1270
+
1271
+ // Certain field types have additional properties.
1272
+ switch ( $val[3] ) {
1273
+
1274
+ case 'checkbox':
1275
+ $this->fields[ $meta_key ]['checked_value'] = $val[7];
1276
+ $this->fields[ $meta_key ]['checked_default'] = ( 'y' == $val[8] ) ? true : false;
1277
+ break;
1278
+
1279
+ case 'select':
1280
+ case 'multiselect':
1281
+ case 'multicheckbox':
1282
+ case 'radio':
1283
+ // Correct a malformed value (if last value is empty due to a trailing comma).
1284
+ if ( '' == end( $val[7] ) ) {
1285
+ array_pop( $val[7] );
1286
+ $this->fields[ $meta_key ][7] = $val[7];
1287
+ }
1288
+ $this->fields[ $meta_key ]['values'] = $val[7];
1289
+ $this->fields[ $meta_key ]['delimiter'] = ( isset( $val[8] ) ) ? $val[8] : '|';
1290
+ $this->fields[ $meta_key ]['options'] = array();
1291
+ foreach ( $val[7] as $value ) {
1292
+ $pieces = explode( '|', trim( $value ) );
1293
+ if ( isset( $pieces[1] ) && $pieces[1] != '' ) {
1294
+ $this->fields[ $meta_key ]['options'][ $pieces[1] ] = $pieces[0];
1295
+ }
1296
+ }
1297
+ break;
1298
+
1299
+ case 'file':
1300
+ case 'image':
1301
+ $this->fields[ $meta_key ]['file_types'] = $val[7];
1302
+ break;
1303
+
1304
+ case 'hidden':
1305
+ $this->fields[ $meta_key ]['value'] = $val[7];
1306
+ break;
1307
+
1308
+ }
1309
+ }
1310
+ }
1311
+
1312
+ /**
1313
+ * Get excluded meta fields.
1314
+ *
1315
+ * @since 3.0.0
1316
+ * @since 3.3.3 Update $tag to match wpmem_fields() tags.
1317
+ *
1318
+ * @param string $tag A tag so we know where the function is being used.
1319
+ * @return array The excluded fields.
1320
+ */
1321
+ function excluded_fields( $tag ) {
1322
+
1323
+ // Default excluded fields.
1324
+ $excluded_fields = array( 'password', 'confirm_password', 'confirm_email', 'password_confirm', 'email_confirm' );
1325
+
1326
+ if ( 'update' == $tag || 'admin-profile' == $tag || 'user-profile' == $tag || 'wp-register' == $tag ) {
1327
+ $excluded_fields[] = 'username';
1328
+ }
1329
+
1330
+ if ( 'admin-profile' == $tag || 'user-profile' == $tag ) {
1331
+ array_push( $excluded_fields, 'first_name', 'last_name', 'nickname', 'display_name', 'user_email', 'description', 'user_url' );
1332
+
1333
+ // If WooCommerce is used, remove these meta - WC already adds them in their own section.
1334
+ if ( class_exists( 'woocommerce' ) ) {
1335
+ array_push( $excluded_fields,
1336
+ 'billing_first_name',
1337
+ 'billing_last_name',
1338
+ 'billing_company',
1339
+ 'billing_address_1',
1340
+ 'billing_address_2',
1341
+ 'billing_city',
1342
+ 'billing_postcode',
1343
+ 'billing_country',
1344
+ 'billing_state',
1345
+ 'billing_email',
1346
+ 'billing_phone',
1347
+ 'shipping_first_name',
1348
+ 'shipping_last_name',
1349
+ 'shipping_company',
1350
+ 'shipping_address_1',
1351
+ 'shipping_address_2',
1352
+ 'shipping_city',
1353
+ 'shipping_postcode',
1354
+ 'shipping_country',
1355
+ 'shipping_state'
1356
+ );
1357
+ }
1358
+ }
1359
+
1360
+ /**
1361
+ * Filter excluded meta fields.
1362
+ *
1363
+ * @since 2.9.3
1364
+ * @since 3.0.0 Moved to new method in WP_Members Class.
1365
+ * @since 3.3.3 Update $tag to match wpmem_fields() tags.
1366
+ *
1367
+ * @param array An array of the field meta names to exclude.
1368
+ * @param string $tag A tag so we know where the function is being used.
1369
+ */
1370
+ $excluded_fields = apply_filters( 'wpmem_exclude_fields', $excluded_fields, $tag );
1371
+
1372
+ // Return excluded fields.
1373
+ return $excluded_fields;
1374
+ }
1375
+
1376
+ /**
1377
+ * Set page locations.
1378
+ *
1379
+ * Handles numeric page IDs while maintaining
1380
+ * compatibility with old full url settings.
1381
+ *
1382
+ * @since 3.0.8
1383
+ */
1384
+ function load_user_pages() {
1385
+ foreach ( $this->user_pages as $key => $val ) {
1386
+ if ( is_numeric( $val ) ) {
1387
+ if ( false !== get_post_status( $val ) ) {
1388
+ $this->user_pages[ $key ] = get_page_link( $val );
1389
+ } else {
1390
+ $notice = sprintf( __( 'You have a linked page in the WP-Members page settings that corresponds to a post ID that no longer exists. Please %s review and update the %s page settings %s.', 'wp-members' ), '<a href="' . esc_url( get_admin_url() . '/options-general.php?page=wpmem-settings&tab=options' ) . '">', $key, '</a>' );
1391
+ $this->admin_notices[] = array(
1392
+ 'type'=>'error',
1393
+ 'notice'=>$notice
1394
+ );
1395
+ }
1396
+ }
1397
+ }
1398
+ }
1399
+
1400
+ /**
1401
+ * Sets the stylesheet URL.
1402
+ *
1403
+ * @since 3.3.0
1404
+ */
1405
+ function set_style() {
1406
+ $this->cssurl = ( 'use_custom' == $this->select_style ) ? $this->cssurl : $this->url . 'assets/css/forms/' . $this->select_style . wpmem_get_suffix() . '.css'; // Set the stylesheet.
1407
+ }
1408
+
1409
+ /**
1410
+ * Returns a requested text string.
1411
+ *
1412
+ * This function manages all of the front-end facing text.
1413
+ * All defaults can be filtered using wpmem_default_text_strings.
1414
+ *
1415
+ * @since 3.1.0
1416
+ *
1417
+ * @global object $wpmem
1418
+ *
1419
+ * @param string $str
1420
+ * @return string $text
1421
+ */
1422
+ function get_text( $str ) {
1423
+
1424
+ global $wpmem;
1425
+
1426
+ // Default Form Fields.
1427
+ $default_form_fields = array(
1428
+ 'first_name' => __( 'First Name', 'wp-members' ),
1429
+ 'last_name' => __( 'Last Name', 'wp-members' ),
1430
+ 'addr1' => __( 'Address 1', 'wp-members' ),
1431
+ 'addr2' => __( 'Address 2', 'wp-members' ),
1432
+ 'city' => __( 'City', 'wp-members' ),
1433
+ 'thestate' => __( 'State', 'wp-members' ),
1434
+ 'zip' => __( 'Zip', 'wp-members' ),
1435
+ 'country' => __( 'Country', 'wp-members' ),
1436
+ 'phone1' => __( 'Day Phone', 'wp-members' ),
1437
+ 'user_email' => __( 'Email', 'wp-members' ),
1438
+ 'confirm_email' => __( 'Confirm Email', 'wp-members' ),
1439
+ 'user_url' => __( 'Website', 'wp-members' ),
1440
+ 'description' => __( 'Biographical Info', 'wp-members' ),
1441
+ 'password' => __( 'Password', 'wp-members' ),
1442
+ 'confirm_password' => __( 'Confirm Password', 'wp-members' ),
1443
+ 'tos' => __( 'TOS', 'wp-members' ),
1444
+ );
1445
+
1446
+ /*
1447
+ * Strings to be added or removed in future versions, included so they will
1448
+ * be in the translation template.
1449
+ * @todo Check whether any of these should be removed.
1450
+ */
1451
+ $benign_strings = array(
1452
+ __( 'No fields selected for deletion', 'wp-members' ),
1453
+ __( 'You are not logged in.', 'wp-members' ), // Technically removed 3.5
1454
+ );
1455
+
1456
+ $defaults = array(
1457
+
1458
+ // Login form.
1459
+ 'login_heading' => __( 'Existing Users Log In', 'wp-members' ),
1460
+ 'login_username' => __( 'Username or Email', 'wp-members' ),
1461
+ 'login_password' => __( 'Password', 'wp-members' ),
1462
+ 'login_button' => __( 'Log In', 'wp-members' ),
1463
+ 'remember_me' => __( 'Remember Me', 'wp-members' ),
1464
+ 'forgot_link_before' => __( 'Forgot password?', 'wp-members' ) . '&nbsp;',
1465
+ 'forgot_link' => __( 'Click here to reset', 'wp-members' ),
1466
+ 'register_link_before' => __( 'New User?', 'wp-members' ) . '&nbsp;',
1467
+ 'register_link' => __( 'Click here to register', 'wp-members' ),
1468
+
1469
+ // Password change form.
1470
+ 'pwdchg_heading' => __( 'Change Password', 'wp-members' ),
1471
+ 'pwdchg_password1' => __( 'New password', 'wp-members' ),
1472
+ 'pwdchg_password2' => __( 'Confirm new password', 'wp-members' ),
1473
+ 'pwdchg_button' => __( 'Update Password', 'wp-members' ),
1474
+
1475
+ // Password reset form.
1476
+ 'pwdreset_heading' => __( 'Reset Forgotten Password', 'wp-members' ),
1477
+ 'pwdreset_username' => __( 'Username', 'wp-members' ),
1478
+ 'pwdreset_email' => __( 'Email', 'wp-members' ),
1479
+ 'pwdreset_button' => __( 'Reset Password' ),
1480
+ 'username_link_before' => __( 'Forgot username?', 'wp-members' ) . '&nbsp;',
1481
+ 'username_link' => __( 'Click here', 'wp-members' ),
1482
+
1483
+ // Retrieve username form.
1484
+ 'username_heading' => __( 'Retrieve username', 'wp-members' ),
1485
+ 'username_email' => __( 'Email Address', 'wp-members' ),
1486
+ 'username_button' => __( 'Retrieve username', 'wp-members' ),
1487
+
1488
+ // Register form.
1489
+ 'register_heading' => __( 'New User Registration', 'wp-members' ),
1490
+ 'register_username' => __( 'Choose a Username', 'wp-members' ),
1491
+ 'register_rscaptcha' => __( 'Input the code:', 'wp-members' ),
1492
+ 'register_tos' => __( 'Please indicate that you agree to the %s Terms of Service %s', 'wp-members' ), // @note: if default changes, default check after wpmem_tos_link_txt must change.
1493
+ 'register_clear' => __( 'Reset Form', 'wp-members' ),
1494
+ 'register_submit' => __( 'Register', 'wp-members' ),
1495
+ 'register_req_mark' => '<span class="req">*</span>',
1496
+ 'register_required' => '<span class="req">*</span>' . __( 'Required field', 'wp-members' ),
1497
+
1498
+ // User profile update form.
1499
+ 'profile_heading' => __( 'Edit Your Information', 'wp-members' ),
1500
+ 'profile_username' => __( 'Username', 'wp-members' ),
1501
+ 'profile_submit' => __( 'Update Profile', 'wp-members' ),
1502
+ 'profile_upload' => __( 'Update this file', 'wp-members' ),
1503
+
1504
+ // Error messages and dialogs.
1505
+ 'login_failed_heading' => __( 'Login Failed!', 'wp-members' ),
1506
+ 'login_failed' => __( 'You entered an invalid username or password.', 'wp-members' ),
1507
+ 'login_failed_link' => __( 'Click here to continue.', 'wp-members' ),
1508
+ 'pwdchangempty' => __( 'Password fields cannot be empty', 'wp-members' ),
1509
+ 'usernamefailed' => __( 'Sorry, that email address was not found.', 'wp-members' ),
1510
+ 'usernamesuccess' => __( 'An email was sent to %s with your username.', 'wp-members' ),
1511
+ 'reg_empty_field' => __( 'Sorry, %s is a required field.', 'wp-members' ),
1512
+ 'reg_valid_email' => __( 'You must enter a valid email address.', 'wp-members' ),
1513
+ 'reg_non_alphanumeric' => __( 'The username cannot include non-alphanumeric characters.', 'wp-members' ),
1514
+ 'reg_empty_username' => __( 'Sorry, username is a required field', 'wp-members' ),
1515
+ 'reg_password_match' => __( 'Passwords did not match.', 'wp-members' ),
1516
+ 'reg_email_match' => __( 'Emails did not match.', 'wp-members' ),
1517
+ 'reg_empty_captcha' => __( 'You must complete the CAPTCHA form.', 'wp-members' ),
1518
+ 'reg_invalid_captcha' => __( 'CAPTCHA was not valid.', 'wp-members' ),
1519
+ 'reg_generic' => __( 'There was an error processing the form.', 'wp-members' ),
1520
+ 'reg_captcha_err' => __( 'There was an error with the CAPTCHA form.', 'wp-members' ),
1521
+ 'reg_file_type' => __( 'Sorry, you can only upload the following file types for the %s field: %s.', 'wp-members' ),
1522
+
1523
+ // Links.
1524
+ 'profile_edit' => __( 'Edit My Information', 'wp-members' ),
1525
+ 'profile_password' => __( 'Change Password', 'wp-members' ),
1526
+ 'register_status' => __( 'You are logged in as %s', 'wp-members' ),
1527
+ 'register_logout' => __( 'Log out', 'wp-members' ),
1528
+ 'register_continue' => ( isset( $wpmem->user_pages['profile'] ) && '' != $wpmem->user_pages['profile'] ) ? __( 'Edit profile', 'wp-members' ) : __( 'Begin using the site.', 'wp-members' ),
1529
+ 'login_welcome' => __( 'You are logged in as %s', 'wp-members' ),
1530
+ 'login_logout' => __( 'Click to log out', 'wp-members' ),
1531
+ 'status_welcome' => __( 'You are logged in as %s', 'wp-members' ),
1532
+ 'status_logout' => __( 'click to log out', 'wp-members' ),
1533
+ 'menu_logout' => __( 'Log Out', 'wp-members' ),
1534
+
1535
+ // Widget.
1536
+ 'sb_status' => __( 'You are logged in as %s', 'wp-members' ),
1537
+ 'sb_logout' => __( 'click here to log out', 'wp-members' ),
1538
+ 'sb_login_failed' => __( 'Login Failed!<br />You entered an invalid username or password.', 'wp-members' ),
1539
+ 'sb_not_logged_in' => '',
1540
+ 'sb_login_username' => __( 'Username or Email', 'wp-members' ),
1541
+ 'sb_login_password' => __( 'Password', 'wp-members' ),
1542
+ 'sb_login_button' => __( 'log in', 'wp-members' ),
1543
+ 'sb_login_forgot' => __( 'Forgot?', 'wp-members' ),
1544
+ 'sb_login_register' => __( 'Register', 'wp-members' ),
1545
+
1546
+ // Default Dialogs.
1547
+ 'restricted_msg' => __( "This content is restricted to site members. If you are an existing user, please log in. New users may register below.", 'wp-members' ),
1548
+ 'success' => __( "Congratulations! Your registration was successful.<br /><br />You may now log in using the password that was emailed to you.", 'wp-members' ),
1549
+
1550
+ // @todo Under consideration for removal from the Dialogs tab.
1551
+ 'user' => __( "Sorry, that username is taken, please try another.", 'wp-members' ),
1552
+ 'email' => __( "Sorry, that email address already has an account.<br />Please try another.", 'wp-members' ),
1553
+ 'editsuccess' => __( "Your information was updated!", 'wp-members' ),
1554
+
1555
+ // @todo These are defaults and are under consideration for removal from the dialogs tab, possibly as we change the password reset to a link based process.
1556
+ 'pwdchangerr' => __( "Passwords did not match.<br /><br />Please try again.", 'wp-members' ),
1557
+ 'pwdchangesuccess' => __( "Password successfully changed!", 'wp-members' ),
1558
+ 'pwdreseterr' => __( "Either the username or email address do not exist in our records.", 'wp-members' ),
1559
+ 'pwdresetsuccess' => __( "Password successfully reset!<br /><br />An email containing a new password has been sent to the email address on file for your account.", 'wp-members' ),
1560
+
1561
+ 'product_restricted' => __( "Sorry, you do not have access to this content.", 'wp-members' ),
1562
+
1563
+ ); // End of $defaults array.
1564
+
1565
+ /**
1566
+ * Filter default terms.
1567
+ *
1568
+ * @since 3.1.0
1569
+ * @deprecated 3.2.7 Use wpmem_default_text instead.
1570
+ */
1571
+ $text = apply_filters( 'wpmem_default_text_strings', '' );
1572
+
1573
+ // Merge filtered $terms with $defaults.
1574
+ $text = wp_parse_args( $text, $defaults );
1575
+
1576
+ /**
1577
+ * Filter the default terms.
1578
+ *
1579
+ * Replaces 'wpmem_default_text_strings' so that multiple filters could
1580
+ * be run. This allows for custom filters when also running the Text
1581
+ * String Editor extension.
1582
+ *
1583
+ * @since 3.2.7
1584
+ */
1585
+ $text = apply_filters( 'wpmem_default_text', $text );
1586
+
1587
+ // Return the requested text string.
1588
+ return $text[ $str ];
1589
+
1590
+ } // End of get_text().
1591
+
1592
+ /**
1593
+ * Initializes the WP-Members widget.
1594
+ *
1595
+ * @since 3.2.0 Replaces widget_wpmemwidget_init
1596
+ */
1597
+ public function widget_init() {
1598
+ // Register the WP-Members widget.
1599
+ register_widget( 'widget_wpmemwidget' );
1600
+ }
1601
+
1602
+ /**
1603
+ * Adds WP-Members query vars to WP's public query vars.
1604
+ *
1605
+ * @since 3.2.0
1606
+ *
1607
+ * @see https://codex.wordpress.org/Plugin_API/Filter_Reference/query_vars
1608
+ *
1609
+ * @param array $qvars
1610
+ */
1611
+ public function add_query_vars ( $qvars ) {
1612
+ $qvars[] = 'a'; // The WP-Members action variable.
1613
+ return $qvars;
1614
+ }
1615
+
1616
+ /**
1617
+ * Enqueues login/out script for the footer.
1618
+ *
1619
+ * @since 3.2.0
1620
+ */
1621
+ public function loginout_script() {
1622
+ if ( is_user_logged_in() ) {
1623
+ wp_enqueue_script( 'jquery' );
1624
+ add_action( 'wp_footer', array( $this, 'do_loginout_script' ), 50 );
1625
+ }
1626
+ }
1627
+
1628
+ /**
1629
+ * Outputs login/out script for the footer.
1630
+ *
1631
+ * @since 3.2.0
1632
+ *
1633
+ * @global object $wpmem
1634
+ */
1635
+ public function do_loginout_script() {
1636
+ global $wpmem;
1637
+ $logout = apply_filters( 'wpmem_logout_link', add_query_arg( 'a', 'logout' ) );
1638
+ ?><script type="text/javascript">
1639
+ jQuery('.wpmem_loginout').html('<a class="login_button" href="<?php echo esc_url( $logout ); ?>"><?php echo $this->get_text( 'menu_logout' ); ?></a>');
1640
+ </script><?php
1641
+ }
1642
+
1643
+ /**
1644
+ * Adds WP-Members controls to the Customizer
1645
+ *
1646
+ * @since 3.2.0
1647
+ *
1648
+ * @param object $wp_customize The Customizer object.
1649
+ */
1650
+ function customizer_settings( $wp_customize ) {
1651
+ $wp_customize->add_section( 'wp_members' , array(
1652
+ 'title' => 'WP-Members',
1653
+ 'priority' => 190,
1654
+ ) );
1655
+
1656
+ // Add settings for output description
1657
+ $wp_customize->add_setting( 'wpmem_show_logged_out_state', array(
1658
+ 'default' => '1',
1659
+ 'type' => 'theme_mod', //'option'
1660
+ 'capability' => 'edit_theme_options',
1661
+ 'transport' => 'refresh',
1662
+ ) );
1663
+
1664
+ // Add settings for output description
1665
+ $wp_customize->add_setting( 'wpmem_show_form_message_dialog', array(
1666
+ 'default' => '1',
1667
+ 'type' => 'theme_mod', //'option'
1668
+ 'capability' => 'edit_theme_options',
1669
+ 'transport' => 'refresh',
1670
+ ) );
1671
+
1672
+ // Add control and output for select field
1673
+ $wp_customize->add_control( 'wpmem_show_form_logged_out', array(
1674
+ 'label' => __( 'Show forms as logged out', 'wp-members' ),
1675
+ 'section' => 'wp_members',
1676
+ 'settings' => 'wpmem_show_logged_out_state',
1677
+ 'type' => 'checkbox',
1678
+ 'std' => '1'
1679
+ ) );
1680
+
1681
+ // Add control for showing dialog
1682
+ $wp_customize->add_control( 'wpmem_show_form_dialog', array(
1683
+ 'label' => __( 'Show form message dialog', 'wp-members' ),
1684
+ 'section' => 'wp_members',
1685
+ 'settings' => 'wpmem_show_form_message_dialog',
1686
+ 'type' => 'checkbox',
1687
+ 'std' => '0'
1688
+ ) );
1689
+ }
1690
+
1691
+ /**
1692
+ * Overrides the wptexturize filter.
1693
+ *
1694
+ * Currently only used for the login form to remove the <br> tag that WP puts in after the "Remember Me".
1695
+ *
1696
+ * @since 2.6.4
1697
+ * @since 3.2.3 Moved to WP_Members class.
1698
+ *
1699
+ * @todo Possibly deprecate or severely alter this process as its need may be obsolete.
1700
+ *
1701
+ * @param string $content
1702
+ * @return string $new_content
1703
+ */
1704
+ function texturize( $content ) {
1705
+
1706
+ $new_content = '';
1707
+ $pattern_full = '{(\[wpmem_txt\].*?\[/wpmem_txt\])}is';
1708
+ $pattern_contents = '{\[wpmem_txt\](.*?)\[/wpmem_txt\]}is';
1709
+ $pieces = preg_split( $pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE );
1710
+
1711
+ foreach ( $pieces as $piece ) {
1712
+ if ( preg_match( $pattern_contents, $piece, $matches ) ) {
1713
+ $new_content .= $matches[1];
1714
+ } else {
1715
+ $new_content .= wptexturize( wpautop( $piece ) );
1716
+ }
1717
+ }
1718
+
1719
+ return $new_content;
1720
+ }
1721
+
1722
+ /**
1723
+ * Loads the stylesheet for tableless forms.
1724
+ *
1725
+ * @since 2.6
1726
+ * @since 3.2.3 Moved to WP_Members class.
1727
+ *
1728
+ * @global object $wpmem The WP_Members object.
1729
+ */
1730
+ function enqueue_style() {
1731
+ global $wpmem;
1732
+ wp_enqueue_style ( 'wp-members', wpmem_force_ssl( $wpmem->cssurl ), false, $wpmem->version );
1733
+ }
1734
+
1735
+ /**
1736
+ * Loads the wp-login.php stylesheet.
1737
+ *
1738
+ * @since 3.3.0
1739
+ *
1740
+ * @global stdClass $wpmem
1741
+ */
1742
+ function enqueue_style_wp_login() {
1743
+ global $wpmem;
1744
+ wp_enqueue_style( 'wp-members', $wpmem->url . 'assets/css/wp-login' . wpmem_get_suffix() . '.css', false, $wpmem->version );
1745
+ }
1746
+
1747
+ /**
1748
+ * Creates an excerpt on the fly if there is no 'more' tag.
1749
+ *
1750
+ * @since 2.6
1751
+ * @since 3.2.3 Moved to WP_Members class.
1752
+ * @since 3.2.5 Check if post object exists.
1753
+ *
1754
+ * @global object $post The post object.
1755
+ * @global object $wpmem The WP_Members object.
1756
+ *
1757
+ * @param string $content
1758
+ * @return string $content
1759
+ */
1760
+ function do_excerpt( $content ) {
1761
+
1762
+ global $post, $more, $wpmem;
1763
+
1764
+ if ( is_object( $post ) ) {
1765
+
1766
+ $post_id = $post->ID;
1767
+ $post_type = $post->post_type;
1768
+
1769
+ $autoex = ( isset( $wpmem->autoex[ $post->post_type ] ) && 1 == $wpmem->autoex[ $post->post_type ]['enabled'] ) ? $wpmem->autoex[ $post->post_type ] : false;
1770
+
1771
+ // Is there already a 'more' link in the content?
1772
+ $has_more_link = ( stristr( $content, 'class="more-link"' ) ) ? true : false;
1773
+
1774
+ // If auto_ex is on.
1775
+ if ( $autoex ) {
1776
+
1777
+ // Build an excerpt if one does not exist.
1778
+ if ( ! $has_more_link ) {
1779
+
1780
+ $is_singular = ( is_singular( $post->post_type ) ) ? true : false;
1781
+
1782
+ if ( $is_singular ) {
1783
+ // If it's a single post, we don't need the 'more' link.
1784
+ $more_link_text = '';
1785
+ $more_link = '';
1786
+ } else {
1787
+ // The default $more_link_text.
1788
+ if ( isset( $wpmem->autoex[ $post->post_type ]['text'] ) && '' != $wpmem->autoex[ $post->post_type ]['text'] ) {
1789
+ $more_link_text = __( $wpmem->autoex[ $post->post_type ]['text'], 'wp-members' );
1790
+ } else {
1791
+ $more_link_text = __( '(more&hellip;)' );
1792
+ }
1793
+ // The default $more_link.
1794
+ $more_link = ' <a href="'. get_permalink( $post->ID ) . '" class="more-link">' . $more_link_text . '</a>';
1795
+ }
1796
+
1797
+ // Apply the_content_more_link filter if one exists (will match up all 'more' link text).
1798
+ /** This filter is documented in /wp-includes/post-template.php */
1799
+ $more_link = apply_filters( 'the_content_more_link', $more_link, $more_link_text );
1800
+
1801
+ $defaults = array(
1802
+ 'length' => $autoex['length'],
1803
+ 'more_link' => $more_link,
1804
+ 'blocked_only' => false,
1805
+ );
1806
+ /**
1807
+ * Filter auto excerpt defaults.
1808
+ *
1809
+ * @since 3.0.9
1810
+ * @since 3.1.5 Deprecated add_ellipsis, strip_tags, close_tags, parse_shortcodes, strip_shortcodes.
1811
+ *
1812
+ * @param array {
1813
+ * An array of settings to override the function defaults.
1814
+ *
1815
+ * @type int $length The default length of the excerpt.
1816
+ * @type string $more_link The more link HTML.
1817
+ * @type boolean $blocked_only Run autoexcerpt only on blocked content. default: false.
1818
+ * }
1819
+ * @param string $post->ID The post ID.
1820
+ * @param string $post->post_type The content's post type.
1821
+ */
1822
+ $args = apply_filters( 'wpmem_auto_excerpt_args', '', $post->ID, $post->post_type );
1823
+
1824
+ // Merge settings.
1825
+ $args = wp_parse_args( $args, $defaults );
1826
+
1827
+ // Are we only excerpting blocked content?
1828
+ if ( $args['blocked_only'] ) {
1829
+ $post_meta = get_post_meta( $post->ID, '_wpmem_block', true );
1830
+ if ( 1 == $wpmem->block[ $post->post_type ] ) {
1831
+ // Post type is blocked, if post meta unblocks it, don't do excerpt.
1832
+ $do_excerpt = ( "0" == $post_meta ) ? false : true;
1833
+ } else {
1834
+ // Post type is unblocked, if post meta blocks it, do excerpt.
1835
+ $do_excerpt = ( "1" == $post_meta ) ? true : false;
1836
+ }
1837
+ } else {
1838
+ $do_excerpt = true;
1839
+ }
1840
+
1841
+ if ( true === $do_excerpt ) {
1842
+ $content = wp_trim_words( $content, $args['length'], $args['more_link'] );
1843
+ // Check if the more link was added (note: singular has no more_link):
1844
+ if ( ! $is_singular && ! strpos( $content, $args['more_link'] ) ) {
1845
+ $content = $content . $args['more_link'];
1846
+ }
1847
+ }
1848
+ }
1849
+ }
1850
+ } else {
1851
+ $post_id = false;
1852
+ $post_type = false;
1853
+ }
1854
+
1855
+ /**
1856
+ * Filter the auto excerpt.
1857
+ *
1858
+ * @since 2.8.1
1859
+ * @since 3.0.9 Added post ID and post type parameters.
1860
+ * @since 3.2.5 Post ID and post type may be false if there is no post object.
1861
+ *
1862
+ * @param string $content The content excerpt.
1863
+ * @param string $post_id The post ID.
1864
+ * @param string $post_type The content's post type.
1865
+ */
1866
+ $content = apply_filters( 'wpmem_auto_excerpt', $content, $post_id, $post_type );
1867
+
1868
+ // Return the excerpt.
1869
+ return $content;
1870
+ }
1871
+
1872
+ /**
1873
+ * Convert form tag.
1874
+ *
1875
+ * @todo This is temporary to handle form tag conversion.
1876
+ *
1877
+ * @since 3.1.7
1878
+ * @since 3.2.3 Moved to WP_Members class.
1879
+ *
1880
+ * @param string $tag
1881
+ * @return string $tag
1882
+ */
1883
+ function convert_tag( $tag ) {
1884
+ switch ( $tag ) {
1885
+ case 'new':
1886
+ return 'register';
1887
+ break;
1888
+ case 'edit':
1889
+ case 'update':
1890
+ return 'profile';
1891
+ break;
1892
+ case 'wp':
1893
+ case 'wp_validate':
1894
+ case 'wp_finalize':
1895
+ return 'register_wp';
1896
+ break;
1897
+ case 'dashboard_profile':
1898
+ case 'dashboard_profile_update':
1899
+ return 'profile_dashboard';
1900
+ break;
1901
+ case 'admin_profile':
1902
+ case 'admin_profile_update':
1903
+ return 'profile_admin';
1904
+ break;
1905
+ default:
1906
+ return $tag;
1907
+ break;
1908
+ }
1909
+ return $tag;
1910
+ }
1911
+
1912
+ /**
1913
+ * Loads translation files.
1914
+ *
1915
+ * @since 3.0.0
1916
+ * @since 3.2.5 Moved to main object, dropped wpmem_ stem.
1917
+ */
1918
+ function load_textdomain() {
1919
+
1920
+ // @see: https://ulrich.pogson.ch/load-theme-plugin-translations for notes on changes.
1921
+
1922
+ // Plugin textdomain.
1923
+ $domain = 'wp-members';
1924
+
1925
+ // Wordpress locale.
1926
+ /** This filter is documented in wp-includes/l10n.php */
1927
+ $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
1928
+
1929
+ /**
1930
+ * Filter translation file.
1931
+ *
1932
+ * If the translate.wordpress.org language pack is available, it will
1933
+ * be /wp-content/languages/plugins/wp-members-{locale}.mo by default.
1934
+ * You can filter this if you want to load a language pack from a
1935
+ * different location (or different file name).
1936
+ *
1937
+ * @since 3.0.0
1938
+ * @since 3.2.0 Added locale as a parameter.
1939
+ *
1940
+ * @param string $file The translation file to load.
1941
+ * @param string $locale The current locale.
1942
+ */
1943
+ $file = apply_filters( 'wpmem_localization_file', trailingslashit( WP_LANG_DIR ) . 'plugins/' . $domain . '-' . $locale . '.mo', $locale );
1944
+
1945
+ $loaded = load_textdomain( $domain, $file );
1946
+ if ( $loaded ) {
1947
+ return $loaded;
1948
+ } else {
1949
+ /**
1950
+ * Filter translation directory.
1951
+ *
1952
+ * @since 3.0.3
1953
+ * @since 3.2.0 Added locale as a parameter.
1954
+ *
1955
+ * @param string $dir The translation directory.
1956
+ * @param string $locale The current locale.
1957
+ */
1958
+ $dir = apply_filters( 'wpmem_localization_dir', basename( $this->path ) . '/i18n/languages/', $locale );
1959
+ load_plugin_textdomain( $domain, FALSE, $dir );
1960
+ }
1961
+ return;
1962
+ }
1963
+
1964
+ /**
1965
+ * Load default tos template.
1966
+ *
1967
+ * @since 3.2.8
1968
+ */
1969
+ function load_default_tos() {
1970
+ // Check for custom template or load default.
1971
+ $custom_template = get_stylesheet_directory() . '/wp-members/templates/tos.php';
1972
+ if ( file_exists( $custom_template ) ) {
1973
+ require_once( $custom_template );
1974
+ } else {
1975
+ require_once( $this->path . 'templates/tos.php' );
1976
+ }
1977
+ }
1978
+
1979
  } // End of WP_Members class.
includes/legacy/dialogs.php CHANGED
@@ -60,11 +60,12 @@ function wpmem_inc_loginfailed() {
60
  * Filter the login failed dialog arguments.
61
  *
62
  * @since 2.9.0
 
63
  *
64
  * @param array An array of arguments to merge with defaults.
65
  */
66
- $args = apply_filters( 'wpmem_login_failed_args', '' );
67
-
68
  // Merge $args with defaults.
69
  $args = wp_parse_args( $args, $defaults );
70
 
60
  * Filter the login failed dialog arguments.
61
  *
62
  * @since 2.9.0
63
+ * @since 3.3.3 Should pass defaults to filter.
64
  *
65
  * @param array An array of arguments to merge with defaults.
66
  */
67
+ $args = apply_filters( 'wpmem_login_failed_args', $defaults );
68
+
69
  // Merge $args with defaults.
70
  $args = wp_parse_args( $args, $defaults );
71
 
includes/walkers/class-wp-members-walker-nav-menu.php CHANGED
@@ -1,231 +1,231 @@
1
- <?php
2
- /**
3
- * Navigation Menu API: (Modifed) Walker_Nav_Menu_Edit class
4
- *
5
- * Create HTML list of nav menu input items.
6
- *
7
- * @package WP_Members
8
- * @since 3.3.0
9
- * @uses Walker_Nav_Menu
10
- */
11
-
12
- class WP_Members_Walker_Nav_Menu extends Walker_Nav_Menu {
13
- /**
14
- * Starts the list before the elements are added.
15
- *
16
- * @see Walker_Nav_Menu::start_lvl()
17
- *
18
- * @since 3.0.0
19
- *
20
- * @param string $output Passed by reference.
21
- * @param int $depth Depth of menu item. Used for padding.
22
- * @param array $args Not used.
23
- */
24
- public function start_lvl( &$output, $depth = 0, $args = array() ) {}
25
-
26
- /**
27
- * Ends the list of after the elements are added.
28
- *
29
- * @see Walker_Nav_Menu::end_lvl()
30
- *
31
- * @since 3.0.0
32
- *
33
- * @param string $output Passed by reference.
34
- * @param int $depth Depth of menu item. Used for padding.
35
- * @param array $args Not used.
36
- */
37
- public function end_lvl( &$output, $depth = 0, $args = array() ) {}
38
-
39
- /**
40
- * Start the element output.
41
- *
42
- * @see Walker_Nav_Menu::start_el()
43
- * @since 3.0.0
44
- *
45
- * @global int $_wp_nav_menu_max_depth
46
- *
47
- * @param string $output Passed by reference. Used to append additional content.
48
- * @param object $item Menu item data object.
49
- * @param int $depth Depth of menu item. Used for padding.
50
- * @param array $args Not used.
51
- * @param int $id Not used.
52
- */
53
- public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
54
- global $_wp_nav_menu_max_depth;
55
-
56
- $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
57
-
58
- $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
59
-
60
- ob_start();
61
- $item_id = esc_attr( $item->ID );
62
- $removed_args = array(
63
- 'action',
64
- 'customlink-tab',
65
- 'edit-menu-item',
66
- 'menu-item',
67
- 'page-tab',
68
- '_wpnonce',
69
- );
70
-
71
- $original_title = '';
72
- if ( 'taxonomy' == $item->type ) {
73
- $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
74
- if ( is_wp_error( $original_title ) )
75
- $original_title = false;
76
- } elseif ( 'post_type' == $item->type ) {
77
- $original_object = get_post( $item->object_id );
78
- $original_title = $original_object->post_title;
79
- }
80
-
81
- $classes = array(
82
- 'menu-item menu-item-depth-' . $depth,
83
- 'menu-item-' . esc_attr( $item->object ),
84
- 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
85
- );
86
-
87
- $title = $item->title;
88
-
89
- if ( ! empty( $item->_invalid ) ) {
90
- $classes[] = 'menu-item-invalid';
91
- /* translators: %s: title of menu item which is invalid */
92
- $title = sprintf( esc_html__( '%s (Invalid)', 'wp-members' ), $item->title );
93
- } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
94
- $classes[] = 'pending';
95
- /* translators: %s: title of menu item in draft status */
96
- $title = sprintf( esc_html__( '%s (Pending)', 'wp-members'), $item->title );
97
- }
98
-
99
- $title = empty( $item->label ) ? $title : $item->label;
100
-
101
- ?>
102
- <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
103
- <div class="menu-item-bar">
104
- <div class="menu-item-handle ui-sortable-handle">
105
- <span class="item-title">
106
- <span class="menu-item-title"><?php echo esc_html( $title ); ?></span>
107
- <span class="is-submenu" style="display: none;">sub item</span>
108
- </span>
109
- <span class="item-controls">
110
- <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
111
- <span class="item-order hide-if-js">
112
- <a href="<?php
113
- echo wp_nonce_url(
114
- add_query_arg(
115
- array(
116
- 'action' => 'move-up-menu-item',
117
- 'menu-item' => $item_id,
118
- ),
119
- remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
120
- ),
121
- 'move-menu_item'
122
- );
123
- ?>" class="item-move-up" aria-label="<?php esc_attr_e( 'Move up', 'wp-members' ); ?>">&#8593;</a>
124
- |
125
- <a href="<?php
126
- echo wp_nonce_url(
127
- add_query_arg(
128
- array(
129
- 'action' => 'move-down-menu-item',
130
- 'menu-item' => $item_id,
131
- ),
132
- remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
133
- ),
134
- 'move-menu_item'
135
- );
136
- ?>" class="item-move-down" aria-label="<?php esc_attr_e( 'Move down', 'wp-members' ); ?>">&#8595;</a>
137
- </span>
138
- <a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e( 'Edit Menu Item', 'wp-members' ); ?>" href="<?php
139
- echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) );
140
- ?>"><span class="screen-reader-text"><?php esc_html_e( 'Edit', 'wp-members' ); ?></span></a>
141
- </span>
142
- </div>
143
- </div>
144
-
145
- <div class="menu-item-settings wp-clearfix" id="menu-item-settings-<?php echo $item_id; ?>">
146
- <?php if( 'custom' == $item->type ) : ?>
147
- <p class="field-url description description-wide">
148
- <label for="edit-menu-item-url-<?php echo $item_id; ?>">
149
- <?php _e( 'URL' ); ?><br />
150
- <input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->url ); ?>" />
151
- </label>
152
- </p>
153
- <?php endif; ?>
154
- <p class="description description-thin">
155
- <label for="edit-menu-item-title-<?php echo $item_id; ?>">
156
- <?php _e( 'Navigation Label' ); ?><br />
157
- <input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>" />
158
- </label>
159
- </p>
160
- <p class="description description-thin">
161
- <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
162
- <?php _e( 'Title Attribute' ); ?><br />
163
- <input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
164
- </label>
165
- </p>
166
- <p class="field-link-target description">
167
- <label for="edit-menu-item-target-<?php echo $item_id; ?>">
168
- <input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $item->target, '_blank' ); ?> />
169
- <?php _e( 'Open link in a new window/tab' ); ?>
170
- </label>
171
- </p>
172
- <p class="field-css-classes description description-thin">
173
- <label for="edit-menu-item-classes-<?php echo $item_id; ?>">
174
- <?php _e( 'CSS Classes (optional)' ); ?><br />
175
- <input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
176
- </label>
177
- </p>
178
- <p class="field-xfn description description-thin">
179
- <label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
180
- <?php _e( 'Link Relationship (XFN)' ); ?><br />
181
- <input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" />
182
- </label>
183
- </p>
184
- <p class="field-description description description-wide">
185
- <label for="edit-menu-item-description-<?php echo $item_id; ?>">
186
- <?php _e( 'Description' ); ?><br />
187
- <textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); // textarea_escaped ?></textarea>
188
- <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span>
189
- </label>
190
- </p>
191
- <?php
192
- // This is the added section
193
- // do_action( 'wpmem_nav_menu_item_options', $item_id, $item, $depth, $args );
194
- do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
195
- // end added section
196
- ?>
197
- <div class="menu-item-actions description-wide submitbox">
198
- <?php if( 'custom' != $item->type && $original_title !== false ) : ?>
199
- <p class="link-to-original">
200
- <?php printf( esc_html__( 'Original: %s' ), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
201
- </p>
202
- <?php endif; ?>
203
- <a class="item-delete submitdelete deletion" id="delete-<?php echo esc_attr( $item_id ); ?>" href="<?php
204
- echo wp_nonce_url(
205
- add_query_arg(
206
- array(
207
- 'action' => 'delete-menu-item',
208
- 'menu-item' => $item_id,
209
- ),
210
- remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) )
211
- ),
212
- 'delete-menu_item_' . esc_attr( $item_id )
213
- ); ?>"><?php _e('Remove'); ?></a> <span class="meta-sep"> | </span> <a class="item-cancel submitcancel" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array('edit-menu-item' => $item_id, 'cancel' => time()), remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) ) ) );
214
- ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a>
215
- </div>
216
-
217
- <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo esc_attr( $item_id ); ?>]" value="<?php echo $item_id; ?>" />
218
- <input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo esc_attr( $item_id ); ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" />
219
- <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo esc_attr( $item_id ); ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
220
- <input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo esc_attr( $item_id ); ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" />
221
- <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo esc_attr( $item_id ); ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
222
- <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo esc_attr( $item_id ); ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
223
- </div><!-- .menu-item-settings-->
224
- <ul class="menu-item-transport"></ul>
225
- <?php
226
-
227
- $output .= ob_get_clean();
228
-
229
- }
230
-
231
- } // Walker_Nav_Menu_Edit
1
+ <?php
2
+ /**
3
+ * Navigation Menu API: (Modifed) Walker_Nav_Menu_Edit class
4
+ *
5
+ * Create HTML list of nav menu input items.
6
+ *
7
+ * @package WP_Members
8
+ * @since 3.3.0
9
+ * @uses Walker_Nav_Menu
10
+ */
11
+
12
+ class WP_Members_Walker_Nav_Menu extends Walker_Nav_Menu {
13
+ /**
14
+ * Starts the list before the elements are added.
15
+ *
16
+ * @see Walker_Nav_Menu::start_lvl()
17
+ *
18
+ * @since 3.0.0
19
+ *
20
+ * @param string $output Passed by reference.
21
+ * @param int $depth Depth of menu item. Used for padding.
22
+ * @param array $args Not used.
23
+ */
24
+ public function start_lvl( &$output, $depth = 0, $args = array() ) {}
25
+
26
+ /**
27
+ * Ends the list of after the elements are added.
28
+ *
29
+ * @see Walker_Nav_Menu::end_lvl()
30
+ *
31
+ * @since 3.0.0
32
+ *
33
+ * @param string $output Passed by reference.
34
+ * @param int $depth Depth of menu item. Used for padding.
35
+ * @param array $args Not used.
36
+ */
37
+ public function end_lvl( &$output, $depth = 0, $args = array() ) {}
38
+
39
+ /**
40
+ * Start the element output.
41
+ *
42
+ * @see Walker_Nav_Menu::start_el()
43
+ * @since 3.0.0
44
+ *
45
+ * @global int $_wp_nav_menu_max_depth
46
+ *
47
+ * @param string $output Passed by reference. Used to append additional content.
48
+ * @param object $item Menu item data object.
49
+ * @param int $depth Depth of menu item. Used for padding.
50
+ * @param array $args Not used.
51
+ * @param int $id Not used.
52
+ */
53
+ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
54
+ global $_wp_nav_menu_max_depth;
55
+
56
+ $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
57
+
58
+ $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
59
+
60
+ ob_start();
61
+ $item_id = esc_attr( $item->ID );
62
+ $removed_args = array(
63
+ 'action',
64
+ 'customlink-tab',
65
+ 'edit-menu-item',
66
+ 'menu-item',
67
+ 'page-tab',
68
+ '_wpnonce',
69
+ );
70
+
71
+ $original_title = '';
72
+ if ( 'taxonomy' == $item->type ) {
73
+ $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
74
+ if ( is_wp_error( $original_title ) )
75
+ $original_title = false;
76
+ } elseif ( 'post_type' == $item->type ) {
77
+ $original_object = get_post( $item->object_id );
78
+ $original_title = $original_object->post_title;
79
+ }
80
+
81
+ $classes = array(
82
+ 'menu-item menu-item-depth-' . $depth,
83
+ 'menu-item-' . esc_attr( $item->object ),
84
+ 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
85
+ );
86
+
87
+ $title = $item->title;
88
+
89
+ if ( ! empty( $item->_invalid ) ) {
90
+ $classes[] = 'menu-item-invalid';
91
+ /* translators: %s: title of menu item which is invalid */
92
+ $title = sprintf( esc_html__( '%s (Invalid)', 'wp-members' ), $item->title );
93
+ } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
94
+ $classes[] = 'pending';
95
+ /* translators: %s: title of menu item in draft status */
96
+ $title = sprintf( esc_html__( '%s (Pending)', 'wp-members'), $item->title );
97
+ }
98
+
99
+ $title = empty( $item->label ) ? $title : $item->label;
100
+
101
+ ?>
102
+ <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
103
+ <div class="menu-item-bar">
104
+ <div class="menu-item-handle ui-sortable-handle">
105
+ <span class="item-title">
106
+ <span class="menu-item-title"><?php echo esc_html( $title ); ?></span>
107
+ <span class="is-submenu" style="display: none;">sub item</span>
108
+ </span>
109
+ <span class="item-controls">
110
+ <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
111
+ <span class="item-order hide-if-js">
112
+ <a href="<?php
113
+ echo wp_nonce_url(
114
+ add_query_arg(
115
+ array(
116
+ 'action' => 'move-up-menu-item',
117
+ 'menu-item' => $item_id,
118
+ ),
119
+ remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
120
+ ),
121
+ 'move-menu_item'
122
+ );
123
+ ?>" class="item-move-up" aria-label="<?php esc_attr_e( 'Move up', 'wp-members' ); ?>">&#8593;</a>
124
+ |
125
+ <a href="<?php
126
+ echo wp_nonce_url(
127
+ add_query_arg(
128
+ array(
129
+ 'action' => 'move-down-menu-item',
130
+ 'menu-item' => $item_id,
131
+ ),
132
+ remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
133
+ ),
134
+ 'move-menu_item'
135
+ );
136
+ ?>" class="item-move-down" aria-label="<?php esc_attr_e( 'Move down', 'wp-members' ); ?>">&#8595;</a>
137
+ </span>
138
+ <a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e( 'Edit Menu Item', 'wp-members' ); ?>" href="<?php
139
+ echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) );
140
+ ?>"><span class="screen-reader-text"><?php esc_html_e( 'Edit', 'wp-members' ); ?></span></a>
141
+ </span>
142
+ </div>
143
+ </div>
144
+
145
+ <div class="menu-item-settings wp-clearfix" id="menu-item-settings-<?php echo $item_id; ?>">
146
+ <?php if( 'custom' == $item->type ) : ?>
147
+ <p class="field-url description description-wide">
148
+ <label for="edit-menu-item-url-<?php echo $item_id; ?>">
149
+ <?php _e( 'URL' ); ?><br />
150
+ <input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->url ); ?>" />
151
+ </label>
152
+ </p>
153
+ <?php endif; ?>
154
+ <p class="description description-thin">
155
+ <label for="edit-menu-item-title-<?php echo $item_id; ?>">
156
+ <?php _e( 'Navigation Label' ); ?><br />
157
+ <input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>" />
158
+ </label>
159
+ </p>
160
+ <p class="description description-thin">
161
+ <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
162
+ <?php _e( 'Title Attribute' ); ?><br />
163
+ <input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
164
+ </label>
165
+ </p>
166
+ <p class="field-link-target description">
167
+ <label for="edit-menu-item-target-<?php echo $item_id; ?>">
168
+ <input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $item->target, '_blank' ); ?> />
169
+ <?php _e( 'Open link in a new window/tab' ); ?>
170
+ </label>
171
+ </p>
172
+ <p class="field-css-classes description description-thin">
173
+ <label for="edit-menu-item-classes-<?php echo $item_id; ?>">
174
+ <?php _e( 'CSS Classes (optional)' ); ?><br />
175
+ <input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
176
+ </label>
177
+ </p>
178
+ <p class="field-xfn description description-thin">
179
+ <label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
180
+ <?php _e( 'Link Relationship (XFN)' ); ?><br />
181
+ <input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" />
182
+ </label>
183
+ </p>
184
+ <p class="field-description description description-wide">
185
+ <label for="edit-menu-item-description-<?php echo $item_id; ?>">
186
+ <?php _e( 'Description' ); ?><br />
187
+ <textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); // textarea_escaped ?></textarea>
188
+ <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span>
189
+ </label>
190
+ </p>
191
+ <?php
192
+ // This is the added section
193
+ // do_action( 'wpmem_nav_menu_item_options', $item_id, $item, $depth, $args );
194
+ do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args, $id );
195
+ // end added section
196
+ ?>
197
+ <div class="menu-item-actions description-wide submitbox">
198
+ <?php if( 'custom' != $item->type && $original_title !== false ) : ?>
199
+ <p class="link-to-original">
200
+ <?php printf( esc_html__( 'Original: %s' ), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
201
+ </p>
202
+ <?php endif; ?>
203
+ <a class="item-delete submitdelete deletion" id="delete-<?php echo esc_attr( $item_id ); ?>" href="<?php
204
+ echo wp_nonce_url(
205
+ add_query_arg(
206
+ array(
207
+ 'action' => 'delete-menu-item',
208
+ 'menu-item' => $item_id,
209
+ ),
210
+ remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) )
211
+ ),
212
+ 'delete-menu_item_' . esc_attr( $item_id )
213
+ ); ?>"><?php _e('Remove'); ?></a> <span class="meta-sep"> | </span> <a class="item-cancel submitcancel" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array('edit-menu-item' => $item_id, 'cancel' => time()), remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) ) ) );
214
+ ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a>
215
+ </div>
216
+
217
+ <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo esc_attr( $item_id ); ?>]" value="<?php echo $item_id; ?>" />
218
+ <input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo esc_attr( $item_id ); ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" />
219
+ <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo esc_attr( $item_id ); ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
220
+ <input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo esc_attr( $item_id ); ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" />
221
+ <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo esc_attr( $item_id ); ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
222
+ <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo esc_attr( $item_id ); ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
223
+ </div><!-- .menu-item-settings-->
224
+ <ul class="menu-item-transport"></ul>
225
+ <?php
226
+
227
+ $output .= ob_get_clean();
228
+
229
+ }
230
+
231
+ } // Walker_Nav_Menu_Edit
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: cbutlerjr
3
  Tags: access, authentication, content, login, member, membership, password, protect, register, registration, restriction, subscriber
4
  Requires at least: 4.0
5
  Tested up to: 5.4
6
- Stable tag: 3.3.2.2
7
  License: GPLv2
8
 
9
  == Description ==
@@ -100,7 +100,7 @@ The FAQs are maintained at https://rocketgeek.com/plugins/wp-members/docs/faqs/
100
 
101
  == Upgrade Notice ==
102
 
103
- WP-Members 3.3.0 is a major update. WP-Members 3.3.2 is a bug fix release. See changelog for important details. Minimum WP version is 4.0.
104
 
105
 
106
  == Screenshots ==
@@ -124,14 +124,16 @@ WP-Members 3.3.0 is a major update. WP-Members 3.3.2 is a bug fix release. See c
124
 
125
  == Changelog ==
126
 
127
- = 3.3.2.2 =
128
 
129
- * Fixed a bug from 3.3.2 that causes reCAPTCHA v2 to always believe the captcha is not checked.
130
- * Fixed a bug from 3.3.2 that caused posts to not be able to be updated in the block editor.
131
-
132
- = 3.3.2.1 =
133
-
134
- * Fixed a bug that caused post excerpts to not be displayed if auto excerpt is not enabled.
 
 
135
 
136
  = 3.3.2 =
137
 
3
  Tags: access, authentication, content, login, member, membership, password, protect, register, registration, restriction, subscriber
4
  Requires at least: 4.0
5
  Tested up to: 5.4
6
+ Stable tag: 3.3.3
7
  License: GPLv2
8
 
9
  == Description ==
100
 
101
  == Upgrade Notice ==
102
 
103
+ WP-Members 3.3.0 is a major update. WP-Members 3.3.3 is an improvement release. See changelog for important details. Minimum WP version is 4.0.
104
 
105
 
106
  == Screenshots ==
124
 
125
  == Changelog ==
126
 
127
+ = 3.3.3 =
128
 
129
+ * If WooCommerce is active, any standard WC user meta fields are removed from the WP-Members additional fields in the User Profile Edit (since they already display in the WC field blocks).
130
+ * When setting hidden posts, don't include posts from post types not set as handled by WP-Members. This prevents previously hidden posts from being included if the post type is no longer included for WP-Members.
131
+ * Set a default product for publishing posts/pages.
132
+ * Updated activation/deactivation processing so that a (admin) user cannot activate or deactivate themselves. Also, if a user has "edit_users" capability, they can log in without being activated.
133
+ * Load email "from" address with main settings rather than when email is sent. This corrects issues with Advanced Options extension, and also keeps the value loaded for use outside of WP-Members email function.
134
+ * WP 5.4 adds the wp_nav_menu_item_custom_fields action, so now WP-Members only loads its custom walker if WP is 5.3 or lower.
135
+ * Image file field type now shows an immediate preview when the "choose file" button is clicked and an image selected (both profile update and new registration).
136
+ * wpmem_login_failed_args updated to pass $args (similar to other _args filters in the plugin, now parses defaults).
137
 
138
  = 3.3.2 =
139
 
wp-members.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP-Members
4
  Plugin URI: https://rocketgeek.com
5
  Description: WP access restriction and user registration. For more information on plugin features, refer to <a href="https://rocketgeek.com/plugins/wp-members/users-guide/">the online Users Guide</a>. A <a href="https://rocketgeek.com/plugins/wp-members/quick-start-guide/">Quick Start Guide</a> is also available. WP-Members(tm) is a trademark of butlerblog.com.
6
- Version: 3.3.2.2
7
  Author: Chad Butler
8
  Author URI: http://butlerblog.com/
9
  Text Domain: wp-members
@@ -64,7 +64,7 @@ if ( ! defined( 'ABSPATH' ) ) {
64
  }
65
 
66
  // Initialize constants.
67
- define( 'WPMEM_VERSION', '3.3.2.2' );
68
  define( 'WPMEM_DB_VERSION', '2.2.0' );
69
  define( 'WPMEM_PATH', plugin_dir_path( __FILE__ ) );
70
 
3
  Plugin Name: WP-Members
4
  Plugin URI: https://rocketgeek.com
5
  Description: WP access restriction and user registration. For more information on plugin features, refer to <a href="https://rocketgeek.com/plugins/wp-members/users-guide/">the online Users Guide</a>. A <a href="https://rocketgeek.com/plugins/wp-members/quick-start-guide/">Quick Start Guide</a> is also available. WP-Members(tm) is a trademark of butlerblog.com.
6
+ Version: 3.3.3
7
  Author: Chad Butler
8
  Author URI: http://butlerblog.com/
9
  Text Domain: wp-members
64
  }
65
 
66
  // Initialize constants.
67
+ define( 'WPMEM_VERSION', '3.3.3' );
68
  define( 'WPMEM_DB_VERSION', '2.2.0' );
69
  define( 'WPMEM_PATH', plugin_dir_path( __FILE__ ) );
70