PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.0.23
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.0.23
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 1.0.23 All 172 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.23, at includes/class-pages.php

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