PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.0.21
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.0.21
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 1.0.22 All 173 releases
userswp / includes / class-pages.php

class-pages.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.0.21, at includes/class-pages.php

557 lines 16.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * UsersWP Page related functions
4 *
5 * All UsersWP page related functions can be found here.
6 *
7 * @since 1.0.0
8 * @author GeoDirectory Team <info@wpgeodirectory.com>
9 */
10 class UsersWP_Pages {
11
12 /**
13 * Checks whether the current page is of given page type or not.
14 *
15 * @since 1.0.0
16 * @package userswp
17 * @param string|bool $type Page type.
18 * @return bool
19 */
20 public function is_page($type = false) {
21 if (is_page()) {
22 global $post;
23 $current_page_id = $post->ID;
24 if ($type) {
25 $uwp_page = uwp_get_page_id($type, false);
26 if ( $uwp_page && ((int) $uwp_page == $current_page_id ) ) {
27 return true;
28 } else {
29 return false;
30 }
31 } else {
32 if ($this->is_register_page() ||
33 $this->is_login_page() ||
34 $this->is_forgot_page() ||
35 $this->is_change_page() ||
36 $this->is_reset_page() ||
37 $this->is_account_page() ||
38 $this->is_profile_page() ||
39 $this->is_users_page() ||
40 $this->is_multi_register_page()) {
41 return true;
42 } else {
43 return false;
44 }
45 }
46
47 } else {
48 return false;
49 }
50 }
51
52 /**
53 * Checks whether the current page is register page or not.
54 *
55 * @since 1.0.0
56 * @package userswp
57 * @return bool
58 */
59 public function is_register_page() {
60 return $this->is_page('register_page');
61 }
62
63 /**
64 * Checks whether the current page is login page or not.
65 *
66 * @since 1.0.0
67 * @package userswp
68 * @return bool
69 */
70 public function is_login_page() {
71 return $this->is_page('login_page');
72 }
73
74 /**
75 * Checks whether the current page is forgot password page or not.
76 *
77 * @since 1.0.0
78 * @package userswp
79 * @return bool
80 */
81 public function is_forgot_page() {
82 return $this->is_page('forgot_page');
83 }
84
85 /**
86 * Checks whether the current page is change password page or not.
87 *
88 * @since 1.0.0
89 * @package userswp
90 * @return bool
91 */
92 public function is_change_page() {
93 return $this->is_page('change_page');
94 }
95
96 /**
97 * Checks whether the current page is reset password page or not.
98 *
99 * @since 1.0.0
100 * @package userswp
101 * @return bool
102 */
103 public function is_reset_page() {
104 return $this->is_page('reset_page');
105 }
106
107 /**
108 * Checks whether the current page is account page or not.
109 *
110 * @since 1.0.0
111 * @package userswp
112 * @return bool
113 */
114 public function is_account_page() {
115 return $this->is_page('account_page');
116 }
117
118 /**
119 * Checks whether the current page is profile page or not.
120 *
121 * @since 1.0.0
122 * @package userswp
123 * @return bool
124 */
125 public function is_profile_page() {
126 return $this->is_page('profile_page');
127 }
128
129 /**
130 * Checks whether the current page is users page or not.
131 *
132 * @since 1.0.0
133 * @package userswp
134 * @return bool
135 */
136 public function is_users_page() {
137 return $this->is_page('users_page');
138 }
139
140 /**
141 * Checks whether the current page is multi register page or not.
142 *
143 * @since 1.0.0
144 * @package userswp
145 * @return bool
146 */
147 public function is_multi_register_page() {
148 global $post;
149 $content = $post->post_content;
150 if (strpos($content, '[uwp_register role_id') !== false) {
151 return true;
152 } else {
153 return false;
154 }
155 }
156
157 /**
158 * Checks whether the current page is logged in user profile page or not.
159 *
160 * @since 1.0.0
161 * @package userswp
162 * @return bool
163 */
164 public function is_current_user_profile_page() {
165 if (is_user_logged_in() &&
166 $this->is_profile_page()
167 ) {
168 $author_slug = get_query_var('uwp_profile');
169 if ($author_slug) {
170 $url_type = apply_filters('uwp_profile_url_type', 'slug');
171 if ($url_type == 'id') {
172 $user = get_user_by('id', $author_slug);
173 } else {
174 $user = get_user_by('slug', $author_slug);
175 }
176
177 if ($user && $user->ID == get_current_user_id()) {
178 return true;
179 } else {
180 return false;
181 }
182 } else {
183 return false;
184 }
185 } else {
186 return false;
187 }
188 }
189
190 /**
191 * Gets the UsersWP page permalink based on page type.
192 *
193 * @since 1.0.0
194 * @package userswp
195 * @param string|bool $type Page type.
196 * @return string Page permalink.
197 */
198 public function get_page_permalink($type) {
199 $link = false;
200 $page_id = uwp_get_page_id($type, false);
201 if ($page_id) {
202 $link = get_permalink($page_id);
203 }
204 return $link;
205 }
206
207 /**
208 * Gets the UsersWP register page permalink.
209 *
210 * @since 1.0.0
211 * @package userswp
212 * @return string Page permalink.
213 */
214 public function get_register_permalink() {
215 return $this->get_page_permalink('register_page');
216 }
217
218 /**
219 * Gets the UsersWP login page permalink.
220 *
221 * @since 1.0.0
222 * @package userswp
223 * @return string Page permalink.
224 */
225 public function get_login_permalink() {
226 return $this->get_page_permalink('login_page');
227 }
228
229 /**
230 * Gets the UsersWP forgot password page permalink.
231 *
232 * @since 1.0.0
233 * @package userswp
234 * @return string Page permalink.
235 */
236 public function get_forgot_permalink() {
237 return $this->get_page_permalink('forgot_page');
238 }
239
240 /**
241 * Gets the UsersWP reset password page permalink.
242 *
243 * @since 1.0.0
244 * @package userswp
245 * @return string Page permalink.
246 */
247 public function get_reset_permalink() {
248 return $this->get_page_permalink('reset_page');
249 }
250
251 /**
252 * Gets the UsersWP account page permalink.
253 *
254 * @since 1.0.0
255 * @package userswp
256 * @return string Page permalink.
257 */
258 public function get_account_permalink() {
259 return $this->get_page_permalink('account_page');
260 }
261
262 /**
263 * Gets the UsersWP profile page permalink.
264 *
265 * @since 1.0.0
266 * @package userswp
267 * @return string Page permalink.
268 */
269 public function get_profile_permalink() {
270 return $this->get_page_permalink('profile_page');
271 }
272
273 /**
274 * Gets the UsersWP users page permalink.
275 *
276 * @since 1.0.0
277 * @package userswp
278 * @return string Page permalink.
279 */
280 public function get_users_permalink() {
281 return $this->get_page_permalink('users_page');
282 }
283
284 /**
285 * Returns all available pages as array to use in select dropdown.
286 *
287 * @since 1.0.0
288 * @package userswp
289 * @return array Page array.
290 */
291 public function get_pages() {
292 $pages_options = array( '' => __( 'Select a Page', 'userswp' ) ); // Blank option
293
294 $pages = get_pages();
295 if ( $pages ) {
296 foreach ( $pages as $page ) {
297 $pages_options[ $page->ID ] = $page->post_title;
298 }
299 }
300 return $pages_options;
301 }
302
303 /**
304 * Gets the page slug using the given page type.
305 *
306 * @since 1.0.0
307 * @package userswp
308 * @param string $page_type Page type.
309 * @return string Page slug.
310 */
311 public function get_page_slug($page_type = 'register_page') {
312 $page_id = uwp_get_page_id($page_type, 0);
313 if ($page_id) {
314 $slug = get_post_field( 'post_name', get_post($page_id) );
315 } else {
316 $slug = false;
317 }
318 return $slug;
319
320 }
321
322 /**
323 * Creates UsersWP page if not exists.
324 *
325 * @since 1.0.0
326 * @package userswp
327 * @param string $slug Page slug.
328 * @param string $option Page setting key.
329 * @param string $page_title The post title. Default empty.
330 * @param mixed $page_content The post content. Default empty.
331 * @param int $post_parent Set this for the post it belongs to, if any. Default 0.
332 * @param string $status The post status. Default 'draft'.
333 */
334 public function create_page($slug, $option, $page_title = '', $page_content = '', $post_parent = 0, $status = 'publish') {
335 global $wpdb, $current_user;
336
337 $settings = get_option( 'uwp_settings', array());
338 if (isset($settings[$option])) {
339 $option_value = $settings[$option];
340 } else {
341 $option_value = false;
342 }
343
344 if ($option_value > 0) :
345 if (get_post($option_value)) :
346 // Page exists
347 return;
348 endif;
349 endif;
350
351 $page_found = $wpdb->get_var(
352 $wpdb->prepare(
353 "SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s LIMIT 1;",
354 array($slug)
355 )
356 );
357
358 if ($page_found) :
359 // Page exists
360 if (!$option_value) {
361 $settings[$option] = $page_found;
362 update_option( 'uwp_settings', $settings );
363 }
364 return;
365 endif;
366
367 $page_data = array(
368 'post_status' => $status,
369 'post_type' => 'page',
370 'post_author' => $current_user->ID,
371 'post_name' => $slug,
372 'post_title' => $page_title,
373 'post_content' => $page_content,
374 'post_parent' => $post_parent,
375 'comment_status' => 'closed'
376 );
377 $page_id = wp_insert_post($page_data);
378
379 $settings[$option] = $page_id;
380 update_option( 'uwp_settings', $settings );
381 }
382
383 /**
384 * Generates default UsersWP pages. Usually called during plugin activation.
385 *
386 * @since 1.0.0
387 * @package userswp
388 * @return void
389 */
390 public function generate_default_pages() {
391
392 $this->create_page(esc_sql(_x('register', 'page_slug', 'userswp')), 'register_page', __('Register', 'userswp'), '[uwp_register]');
393 $this->create_page(esc_sql(_x('login', 'page_slug', 'userswp')), 'login_page', __('Login', 'userswp'), '[uwp_login]');
394 $this->create_page(esc_sql(_x('account', 'page_slug', 'userswp')), 'account_page', __('Account', 'userswp'), '[uwp_account]');
395 $this->create_page(esc_sql(_x('forgot', 'page_slug', 'userswp')), 'forgot_page', __('Forgot Password?', 'userswp'), '[uwp_forgot]');
396 $this->create_page(esc_sql(_x('reset', 'page_slug', 'userswp')), 'reset_page', __('Reset Password', 'userswp'), '[uwp_reset]');
397 $this->create_page(esc_sql(_x('change', 'page_slug', 'userswp')), 'change_page', __('Change Password', 'userswp'), '[uwp_change]');
398 $this->create_page(esc_sql(_x('profile', 'page_slug', 'userswp')), 'profile_page', __('Profile', 'userswp'), '[uwp_profile]');
399 $this->create_page(esc_sql(_x('users', 'page_slug', 'userswp')), 'users_page', __('Users', 'userswp'), '[uwp_users]');
400
401 }
402
403
404 /**
405 * Generates default UsersWP pages on new wpmu blog creation.
406 *
407 * @since 1.0.0
408 * @package userswp
409 *
410 * @param int $blog_id Blog ID.
411 * @param int $user_id User ID.
412 * @param string $domain Site domain.
413 * @param string $path Site path.
414 * @param int $site_id Site ID. Only relevant on multi-network installs.
415 * @param array $meta Meta data. Used to set initial site options.
416 */
417 public function wpmu_generate_default_pages_on_new_site( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
418
419 if (uwp_get_installation_type() != 'multi_na_all') {
420 return;
421 }
422
423 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
424 require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
425 }
426
427 // Bail if plugin is not network activated.
428 if ( ! is_plugin_active_for_network( 'userswp/userswp.php' ) ) {
429 return;
430 }
431
432 // Switch to the new blog.
433 switch_to_blog( $blog_id );
434
435 uwp_generate_default_pages();
436
437 // Restore original blog.
438 restore_current_blog();
439 }
440
441 /**
442 * Gets the UsersWP page permalink based on page type.
443 *
444 * @since 1.0.0
445 * @package userswp
446 * @param string $page Page type.
447 * @return string Page permalink.
448 */
449 public function get_page_link($page) {
450
451 $link = "";
452 $page_id = false;
453
454 switch ($page) {
455 case 'register':
456 $page_id = uwp_get_page_id('register_page', false);
457 break;
458
459 case 'login':
460 $page_id = uwp_get_page_id('login_page', false);
461 break;
462
463 case 'forgot':
464 $page_id = uwp_get_page_id('forgot_page', false);
465 break;
466
467 case 'account':
468 $page_id = uwp_get_page_id('account_page', false);
469 break;
470
471 case 'profile':
472 $page_id = uwp_get_page_id('profile_page', false);
473 break;
474
475 case 'users':
476 $page_id = uwp_get_page_id('users_page', false);
477 break;
478 }
479
480 if ($page_id) {
481 $link = get_permalink($page_id);
482 }
483
484 return $link;
485 }
486
487 /**
488 * Builds the profile page url based on the tab and sub tab given
489 * yoursite.com/profile/username
490 * yoursite.com/profile/username/tab
491 * yoursite.com/profile/username/tab/subtab
492 *
493 * @since 1.0.0
494 * @package userswp
495 * @param int $user_id User ID.
496 * @param string|bool $tab Optional. Main tab
497 * @param string|bool $subtab Optional. Sub tab.
498 * @return string Built profile page link.
499 */
500 public function build_profile_tab_url($user_id, $tab = false, $subtab = false) {
501
502 $link = apply_filters('uwp_profile_link', get_author_posts_url($user_id), $user_id);
503
504 if ($link != '') {
505 if (isset($_REQUEST['page_id'])) {
506 $permalink_structure = 'DEFAULT';
507 } else {
508 $permalink_structure = 'CUSTOM';
509 $link = rtrim($link, '/') . '/';
510 }
511
512 if ('DEFAULT' == $permalink_structure) {
513 $link = add_query_arg(
514 array(
515 'uwp_tab' => $tab,
516 'uwp_subtab' => $subtab
517 ),
518 $link
519 );
520 } else {
521 if ($tab) {
522 $link = $link . $tab;
523 }
524
525 if ($subtab) {
526 $link = $link .'/'.$subtab;
527 }
528 }
529 }
530
531 return $link;
532 }
533
534
535 public function get_page_id($type, $get_link = false) {
536
537 $link = false;
538 $page_id = uwp_get_option($type, false, false);
539
540 if ($page_id) {
541 if (uwp_is_wpml()) {
542 $wpml_page_id = uwp_wpml_object_id($page_id, 'page', true, ICL_LANGUAGE_CODE);
543 if (!empty($wpml_page_id)) {
544 $page_id = $wpml_page_id;
545 }
546 }
547 $link = $page_id;
548
549 if($get_link){
550 $link = get_permalink($page_id);
551 }
552 }
553
554 return $link;
555 }
556
557 }