PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.74
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.74
1.2.74 1.2.73 1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 All 174 releases
← All changes | includes/class-pages.php +185 -187 1.0.101.2.74 View file →
@@ -19,42 +19,38 @@
19 19 */
20 20 public function is_page($type = false) {
21 21 if (is_page()) {
22 22 global $post;
23 - $current_page_id = $post->ID;
24 - if ($type) {
25 - $uwp_page = uwp_get_option($type, false);
26 - if (uwp_is_wpml()) {
27 - global $sitepress;
28 - $wpml_page_id = uwp_wpml_object_id($post->ID, 'page', true, $sitepress->get_default_language());
29 - if (!empty($wpml_page_id)) {
30 - $current_page_id = $wpml_page_id;
23 + $current_page_id = isset($post->ID) ? absint($post->ID) : '';
24 + if($current_page_id){
25 + if ($type) {
26 + $uwp_page = uwp_get_page_id($type, false);
27 + if ( $uwp_page && ((int) $uwp_page == $current_page_id ) ) {
28 + return true;
29 + } else {
30 + return false;
31 31 }
32 - }
33 - if ( $uwp_page && ((int) $uwp_page == $current_page_id ) ) {
34 - return true;
35 32 } else {
36 - return false;
33 + if ($this->is_register_page() ||
34 + $this->is_login_page() ||
35 + $this->is_forgot_page() ||
36 + $this->is_change_page() ||
37 + $this->is_reset_page() ||
38 + $this->is_account_page() ||
39 + $this->is_profile_page() ||
40 + $this->is_users_page() ||
41 + $this->is_user_item_page()) {
42 + return true;
43 + } else {
44 + return false;
45 + }
37 46 }
38 - } else {
39 - if ($this->is_register_page() ||
40 - $this->is_login_page() ||
41 - $this->is_forgot_page() ||
42 - $this->is_change_page() ||
43 - $this->is_reset_page() ||
44 - $this->is_account_page() ||
45 - $this->is_profile_page() ||
46 - $this->is_users_page() ||
47 - $this->is_multi_register_page()) {
48 - return true;
49 - } else {
50 - return false;
51 - }
52 47 }
53 -
54 48 } else {
55 49 return false;
56 50 }
51 +
52 + return false;
57 53 }
58 54
59 55 /**
60 56 * Checks whether the current page is register page or not.
@@ -144,22 +140,16 @@
144 140 return $this->is_page('users_page');
145 141 }
146 142
147 143 /**
148 - * Checks whether the current page is multi register page or not.
144 + * Checks whether the current page is users page or not.
149 145 *
150 - * @since 1.0.0
146 + * @since 1.1.2
151 147 * @package userswp
152 148 * @return bool
153 149 */
154 - public function is_multi_register_page() {
155 - global $post;
156 - $content = $post->post_content;
157 - if (strpos($content, '[uwp_register role_id') !== false) {
158 - return true;
159 - } else {
160 - return false;
161 - }
150 + public function is_user_item_page() {
151 + return $this->is_page('user_list_item_page');
162 152 }
163 153
164 154 /**
165 155 * Checks whether the current page is logged in user profile page or not.
@@ -194,102 +184,8 @@
194 184 }
195 185 }
196 186
197 187 /**
198 - * Gets the UsersWP page permalink based on page type.
199 - *
200 - * @since 1.0.0
201 - * @package userswp
202 - * @param string|bool $type Page type.
203 - * @return string Page permalink.
204 - */
205 - public function get_page_permalink($type) {
206 - $link = false;
207 - $page_id = uwp_get_option($type, false);
208 - if ($page_id) {
209 - $link = get_permalink($page_id);
210 - }
211 - return $link;
212 - }
213 -
214 - /**
215 - * Gets the UsersWP register page permalink.
216 - *
217 - * @since 1.0.0
218 - * @package userswp
219 - * @return string Page permalink.
220 - */
221 - public function get_register_permalink() {
222 - return $this->get_page_permalink('register_page');
223 - }
224 -
225 - /**
226 - * Gets the UsersWP login page permalink.
227 - *
228 - * @since 1.0.0
229 - * @package userswp
230 - * @return string Page permalink.
231 - */
232 - public function get_login_permalink() {
233 - return $this->get_page_permalink('login_page');
234 - }
235 -
236 - /**
237 - * Gets the UsersWP forgot password page permalink.
238 - *
239 - * @since 1.0.0
240 - * @package userswp
241 - * @return string Page permalink.
242 - */
243 - public function get_forgot_permalink() {
244 - return $this->get_page_permalink('forgot_page');
245 - }
246 -
247 - /**
248 - * Gets the UsersWP reset password page permalink.
249 - *
250 - * @since 1.0.0
251 - * @package userswp
252 - * @return string Page permalink.
253 - */
254 - public function get_reset_permalink() {
255 - return $this->get_page_permalink('reset_page');
256 - }
257 -
258 - /**
259 - * Gets the UsersWP account page permalink.
260 - *
261 - * @since 1.0.0
262 - * @package userswp
263 - * @return string Page permalink.
264 - */
265 - public function get_account_permalink() {
266 - return $this->get_page_permalink('account_page');
267 - }
268 -
269 - /**
270 - * Gets the UsersWP profile page permalink.
271 - *
272 - * @since 1.0.0
273 - * @package userswp
274 - * @return string Page permalink.
275 - */
276 - public function get_profile_permalink() {
277 - return $this->get_page_permalink('profile_page');
278 - }
279 -
280 - /**
281 - * Gets the UsersWP users page permalink.
282 - *
283 - * @since 1.0.0
284 - * @package userswp
285 - * @return string Page permalink.
286 - */
287 - public function get_users_permalink() {
288 - return $this->get_page_permalink('users_page');
289 - }
290 -
291 - /**
292 188 * Returns all available pages as array to use in select dropdown.
293 189 *
294 190 * @since 1.0.0
295 191 * @package userswp
@@ -315,9 +211,9 @@
315 211 * @param string $page_type Page type.
316 212 * @return string Page slug.
317 213 */
318 214 public function get_page_slug($page_type = 'register_page') {
319 - $page_id = uwp_get_option($page_type, 0);
215 + $page_id = uwp_get_page_id($page_type, 0);
320 216 if ($page_id) {
321 217 $slug = get_post_field( 'post_name', get_post($page_id) );
322 218 } else {
323 219 $slug = false;
@@ -336,8 +232,10 @@
336 232 * @param string $page_title The post title. Default empty.
337 233 * @param mixed $page_content The post content. Default empty.
338 234 * @param int $post_parent Set this for the post it belongs to, if any. Default 0.
339 235 * @param string $status The post status. Default 'draft'.
236 + *
237 + * @return int Page ID
340 238 */
341 239 public function create_page($slug, $option, $page_title = '', $page_content = '', $post_parent = 0, $status = 'publish') {
342 240 global $wpdb, $current_user;
343 241
@@ -347,45 +245,72 @@
347 245 } else {
348 246 $option_value = false;
349 247 }
350 248
351 - if ($option_value > 0) :
352 - if (get_post($option_value)) :
353 - // Page exists
354 - return;
355 - endif;
356 - endif;
249 + if ($option_value > 0 && ( $page_object = get_post( $option_value ) )) {
250 + if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) {
251 + // Valid page is already in place
252 + return $page_object->ID;
253 + }
254 + }
357 255
358 - $page_found = $wpdb->get_var(
359 - $wpdb->prepare(
360 - "SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s LIMIT 1;",
361 - array($slug)
362 - )
363 - );
256 + if(!empty($post_parent)){
257 + $page = get_page_by_path($post_parent);
258 + if ($page) {
259 + $post_parent = $page->ID;
260 + } else {
261 + $post_parent = '';
262 + }
263 + }
364 264
365 - if ($page_found) :
366 - // Page exists
367 - if (!$option_value) {
368 - $settings[$option] = $page_found;
265 + if ( strlen( $page_content ) > 0 ) {
266 + // Search for an existing page with the specified page content (typically a shortcode)
267 + $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
268 + $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
269 + } else {
270 + // Search for an existing page with the specified page slug
271 + $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug ) );
272 + $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) );
273 + }
274 +
275 + $valid_page_found = apply_filters( 'uwp_create_page_id', $valid_page_found, $slug, $page_content );
276 +
277 + if ( $valid_page_found ) {
278 + if ( $option ) {
279 + $settings[$option] = $valid_page_found;
369 280 update_option( 'uwp_settings', $settings );
370 281 }
371 - return;
372 - endif;
282 + return $valid_page_found;
283 + }
373 284
374 - $page_data = array(
375 - 'post_status' => $status,
376 - 'post_type' => 'page',
377 - 'post_author' => $current_user->ID,
378 - 'post_name' => $slug,
379 - 'post_title' => $page_title,
380 - 'post_content' => $page_content,
381 - 'post_parent' => $post_parent,
382 - 'comment_status' => 'closed'
383 - );
384 - $page_id = wp_insert_post($page_data);
285 + if ( $trashed_page_found ) {
286 + $page_id = $trashed_page_found;
287 + $page_data = array(
288 + 'ID' => $page_id,
289 + 'post_status' => 'publish',
290 + 'post_parent' => $post_parent,
291 + );
292 + wp_update_post( $page_data );
293 + } else {
294 + $page_data = array(
295 + 'post_status' => 'publish',
296 + 'post_type' => 'page',
297 + 'post_author' => $current_user->ID,
298 + 'post_name' => $slug,
299 + 'post_title' => $page_title,
300 + 'post_content' => $page_content,
301 + 'post_parent' => $post_parent,
302 + 'comment_status' => 'closed',
303 + );
304 + $page_id = wp_insert_post( $page_data );
305 + }
385 306
386 - $settings[$option] = $page_id;
387 - update_option( 'uwp_settings', $settings );
307 + if ( $option ) {
308 + $settings[$option] = $page_id;
309 + update_option('uwp_settings', $settings);
310 + }
311 +
312 + return $page_id;
388 313 }
389 314
390 315 /**
391 316 * Generates default UsersWP pages. Usually called during plugin activation.
@@ -403,9 +328,10 @@
403 328 $this->create_page(esc_sql(_x('reset', 'page_slug', 'userswp')), 'reset_page', __('Reset Password', 'userswp'), '[uwp_reset]');
404 329 $this->create_page(esc_sql(_x('change', 'page_slug', 'userswp')), 'change_page', __('Change Password', 'userswp'), '[uwp_change]');
405 330 $this->create_page(esc_sql(_x('profile', 'page_slug', 'userswp')), 'profile_page', __('Profile', 'userswp'), '[uwp_profile]');
406 331 $this->create_page(esc_sql(_x('users', 'page_slug', 'userswp')), 'users_page', __('Users', 'userswp'), '[uwp_users]');
407 -
332 + $this->create_page(esc_sql(_x('user-list-item', 'page_slug', 'userswp')), 'user_list_item_page', __('Users List Item', 'userswp'), '[uwp_users_item]');
333 +
408 334 }
409 335
410 336
411 337 /**
@@ -414,15 +340,10 @@
414 340 * @since 1.0.0
415 341 * @package userswp
416 342 *
417 343 * @param int $blog_id Blog ID.
418 - * @param int $user_id User ID.
419 - * @param string $domain Site domain.
420 - * @param string $path Site path.
421 - * @param int $site_id Site ID. Only relevant on multi-network installs.
422 - * @param array $meta Meta data. Used to set initial site options.
423 344 */
424 - public function wpmu_generate_default_pages_on_new_site( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
345 + public function wpmu_generate_default_pages_on_new_site( $blog_id ) {
425 346
426 347 if (uwp_get_installation_type() != 'multi_na_all') {
427 348 return;
428 349 }
@@ -438,9 +359,9 @@
438 359
439 360 // Switch to the new blog.
440 361 switch_to_blog( $blog_id );
441 362
442 - uwp_generate_default_pages();
363 + $this->generate_default_pages();
443 364
444 365 // Restore original blog.
445 366 restore_current_blog();
446 367 }
@@ -453,48 +374,47 @@
453 374 * @param string $page Page type.
454 375 * @return string Page permalink.
455 376 */
456 377 public function get_page_link($page) {
457 -
458 378 $link = "";
459 - $page_id = false;
460 -
461 379 switch ($page) {
462 380 case 'register':
463 - $page_id = uwp_get_option('register_page', false);
381 + $page_id = uwp_get_page_id('register_page', false);
464 382 break;
465 383
466 384 case 'login':
467 - $page_id = uwp_get_option('login_page', false);
385 + $page_id = uwp_get_page_id('login_page', false);
468 386 break;
469 387
470 388 case 'forgot':
471 - $page_id = uwp_get_option('forgot_page', false);
389 + $page_id = uwp_get_page_id('forgot_page', false);
472 390 break;
473 391
474 392 case 'account':
475 - $page_id = uwp_get_option('account_page', false);
393 + $page_id = uwp_get_page_id('account_page', false);
476 394 break;
477 395
478 396 case 'profile':
479 - $page_id = uwp_get_option('profile_page', false);
397 + $page_id = uwp_get_page_id('profile_page', false);
480 398 break;
481 399
482 400 case 'users':
483 - $page_id = uwp_get_option('users_page', false);
401 + $page_id = uwp_get_page_id('users_page', false);
484 402 break;
403 +
404 + default:
405 + $page_id = uwp_get_page_id($page, false);
406 + break;
485 407 }
486 408
487 409 if ($page_id) {
488 - if (uwp_is_wpml()) {
489 - $wpml_page_id = uwp_wpml_object_id($page_id, 'page', true, ICL_LANGUAGE_CODE);
490 - if (!empty($wpml_page_id)) {
491 - $page_id = $wpml_page_id;
492 - }
493 - }
494 410 $link = get_permalink($page_id);
495 411 }
496 412
413 + if ( ! empty( $link ) && function_exists( 'PLL' ) ) {
414 + $link = PLL()->links_model->add_language_to_link( $link, PLL()->curlang );
415 + }
416 +
497 417 return $link;
498 418 }
499 419
500 420 /**
@@ -511,9 +431,9 @@
511 431 * @return string Built profile page link.
512 432 */
513 433 public function build_profile_tab_url($user_id, $tab = false, $subtab = false) {
514 434
515 - $link = apply_filters('uwp_profile_link', get_author_posts_url($user_id), $user_id);
435 + $link = apply_filters('uwp_profile_link', get_author_posts_url($user_id), $user_id);
516 436
517 437 if ($link != '') {
518 438 if (isset($_REQUEST['page_id'])) {
519 439 $permalink_structure = 'DEFAULT';
@@ -540,8 +460,86 @@
540 460 }
541 461 }
542 462 }
543 463
464 + return trailingslashit( $link );
465 + }
466 +
467 + /**
468 + * To get the page ID
469 + *
470 + * @param $type
471 + * @param bool $get_link
472 + *
473 + * @return bool|false|int|NULL|string
474 + */
475 + public function get_page_id($type, $get_link = false) {
476 +
477 + $link = false;
478 + $page_id = uwp_get_option($type, false, false);
479 +
480 + if ($page_id && $page_id > 0) {
481 + if (uwp_is_wpml()) {
482 + $wpml_page_id = uwp_wpml_object_id($page_id, 'page', true);
483 + if (!empty($wpml_page_id)) {
484 + $page_id = $wpml_page_id;
485 + }
486 + }
487 + $link = $page_id;
488 +
489 + if($get_link){
490 + $link = get_permalink($page_id);
491 + }
492 + }
493 +
544 494 return $link;
495 + }
496 +
497 + /**
498 + * Add a post display state for special UWP pages in the page list table.
499 + *
500 + * @param array $post_states An array of post display states.
501 + * @param WP_Post $post The current post object.
502 + *
503 + * @return mixed
504 + */
505 + public function add_display_post_states( $post_states, $post ) {
506 + if ( uwp_get_page_id( 'register_page' ) == $post->ID ) {
507 + $post_states['uwp_register_page'] = __( 'UWP Register Page', 'userswp' );
508 + }
509 +
510 + if ( uwp_get_page_id( 'login_page' ) == $post->ID ) {
511 + $post_states['uwp_login_page'] = __( 'UWP Login Page', 'userswp' );
512 + }
513 +
514 + if ( uwp_get_page_id( 'forgot_page' ) == $post->ID ) {
515 + $post_states['uwp_forgot_page'] = __( 'UWP Forgot Password Page', 'userswp' );
516 + }
517 +
518 + if ( uwp_get_page_id( 'reset_page' ) == $post->ID ) {
519 + $post_states['uwp_reset_page'] = __( 'UWP Reset Password Page', 'userswp' );
520 + }
521 +
522 + if ( uwp_get_page_id( 'account_page' ) == $post->ID ) {
523 + $post_states['uwp_account_page'] = __( 'UWP Account Page', 'userswp' );
524 + }
525 +
526 + if ( uwp_get_page_id( 'profile_page' ) == $post->ID ) {
527 + $post_states['uwp_profile_page'] = __( 'UWP Profile Page', 'userswp' );
528 + }
529 +
530 + if ( uwp_get_page_id( 'users_page' ) == $post->ID ) {
531 + $post_states['uwp_users_page'] = __( 'UWP Users Page', 'userswp' );
532 + }
533 +
534 + if ( uwp_get_page_id( 'user_list_item_page' ) == $post->ID ) {
535 + $post_states['uwp_user_list_item_page'] = __( 'UWP User Item Page', 'userswp' );
536 + }
537 +
538 + if ( uwp_get_page_id( 'change_page' ) == $post->ID ) {
539 + $post_states['uwp_change_page'] = __( 'UWP Change Password Page', 'userswp' );
540 + }
541 +
542 + return $post_states;
545 543 }
546 544
547 545 }