PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.43
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.43
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 / helpers / permalinks.php

permalinks.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.43, at includes/helpers/permalinks.php

385 lines 11.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Gets the UsersWP page permalink based on page type.
4 *
5 * @since 1.0.0
6 * @package userswp
7 * @param string $page_type Page type.
8 * @return string Page permalink.
9 */
10 function uwp_get_page_link($page_type) {
11 $page = new UsersWP_Pages();
12 return $page->get_page_link($page_type);
13 }
14
15 /**
16 * Builds the profile page url based on the tab and sub tab given
17 * yoursite.com/profile/username
18 * yoursite.com/profile/username/tab
19 * yoursite.com/profile/username/tab/subtab
20 *
21 * @since 1.0.0
22 * @package userswp
23 * @param int $user_id User ID.
24 * @param string|bool $tab Optional. Main tab
25 * @param string|bool $subtab Optional. Sub tab.
26 * @return string Built profile page link.
27 */
28 function uwp_build_profile_tab_url($user_id, $tab = false, $subtab = false) {
29 $page = new UsersWP_Pages();
30 return $page->build_profile_tab_url($user_id, $tab, $subtab);
31 }
32
33 /**
34 * Returns the page link for register page.
35 *
36 * @since 1.0.0
37 * @package userswp
38 *
39 * @return array|bool|mixed Page link.
40 */
41 function uwp_get_register_page_url() {
42 $register_url = uwp_get_page_link('register');
43 if (isset($_REQUEST['redirect_to']) && !empty($_REQUEST['redirect_to'])) {
44 $redirect_to = esc_url($_REQUEST['redirect_to']);
45 $register_url = add_query_arg('redirect_to', $redirect_to, $register_url);
46 }
47 return $register_url;
48 }
49
50 /**
51 * Returns the page link for login page.
52 *
53 * @since 1.0.0
54 * @package userswp
55 *
56 * @return array|bool|mixed Page link.
57 */
58 function uwp_get_login_page_url() {
59 $login_url = uwp_get_page_link('login');
60 if (isset($_REQUEST['redirect_to']) && !empty($_REQUEST['redirect_to'])) {
61 $redirect_to = esc_url($_REQUEST['redirect_to']);
62 $login_url = add_query_arg('redirect_to', $redirect_to, $login_url);
63 }
64 return $login_url;
65 }
66
67 /**
68 * Returns the page link for forgot password page.
69 *
70 * @since 1.0.0
71 * @package userswp
72 *
73 * @return array|bool|mixed Page link.
74 */
75 function uwp_get_forgot_page_url() {
76 return uwp_get_page_link('forgot');
77 }
78
79 /**
80 * Returns the page link for change password page.
81 *
82 * @since 1.0.0
83 * @package userswp
84 *
85 * @return array|bool|mixed Page link.
86 */
87 function uwp_get_change_page_url() {
88 return uwp_get_page_url_data('change_page');
89 }
90
91 /**
92 * Returns the page link for reset password page.
93 *
94 * @since 1.0.0
95 * @package userswp
96 *
97 * @return array|bool|mixed Page link.
98 */
99 function uwp_get_reset_page_url() {
100 return uwp_get_page_url_data('reset_page');
101 }
102
103 /**
104 * Returns the page link for account page.
105 *
106 * @since 1.0.0
107 * @package userswp
108 *
109 * @return array|bool|mixed Page link.
110 */
111 function uwp_get_account_page_url() {
112 return uwp_get_page_url_data('account_page');
113 }
114
115 /**
116 * Returns the page link for profile page.
117 *
118 * @since 1.0.0
119 * @package userswp
120 *
121 * @return array|bool|mixed Page link.
122 */
123 function uwp_get_profile_page_url() {
124 return uwp_get_page_url_data('profile_page');
125 }
126
127 /**
128 * Returns the page link for users page.
129 *
130 * @since 1.0.0
131 * @package userswp
132 *
133 * @return array|bool|mixed Page link.
134 */
135 function uwp_get_users_page_url() {
136 return uwp_get_page_url_data('users_page');
137 }
138
139 /**
140 * Returns the page info like page title, slug and link.
141 * If output type is "link", then only the link is returned.
142 *
143 * @since 1.0.0
144 * @package userswp
145 *
146 * @param string $page_type Page type.
147 * @param string $output_type Link or Array?
148 *
149 * @return array|bool|mixed Page info or link.
150 */
151 function uwp_get_page_url_data($page_type, $output_type = 'link') {
152
153 $install_type = uwp_get_installation_type();
154
155 $page_data = array();
156 switch ($install_type) {
157 case "single":
158 $page_data = uwp_get_page_url_page_data($page_data, $page_type);
159 break;
160 case "multi_na_all":
161 $page_data = uwp_get_page_url_page_data($page_data, $page_type);
162 break;
163 case "multi_na_site_id":
164 if (defined('UWP_ROOT_PAGES')) {
165 $blog_id = UWP_ROOT_PAGES;
166 } else {
167 $blog_id = (int) get_network()->site_id;
168 }
169 $current_blog_id = get_current_blog_id();
170 if (!is_int($blog_id)) {
171 $page_data = array();
172 } else {
173 if ($blog_id == $current_blog_id) {
174 $page_data = uwp_get_page_url_page_data($page_data, $page_type);
175 } else {
176 // Switch to the new blog.
177 switch_to_blog( $blog_id );
178 $page_data = uwp_get_page_url_page_data($page_data, $page_type);
179 // Restore original blog.
180 restore_current_blog();
181 }
182 }
183 break;
184 case "multi_na_default":
185 $is_main_site = is_main_site();
186 if ($is_main_site) {
187 $page_data = uwp_get_page_url_page_data($page_data, $page_type);
188 } else {
189 $main_blog_id = (int) get_network()->site_id;
190 // Switch to the new blog.
191 switch_to_blog( $main_blog_id );
192 $page_data = uwp_get_page_url_page_data($page_data, $page_type);
193 // Restore original blog.
194 restore_current_blog();
195 }
196 break;
197 case "multi_not_na":
198 $page_data = uwp_get_page_url_page_data($page_data, $page_type);
199 break;
200 default:
201 $page_data = array();
202
203 }
204
205 if ($output_type == 'link') {
206 if (empty($page_data)) {
207 return false;
208 } else {
209 return $page_data['link'];
210 }
211 } else {
212 return $page_data;
213 }
214 }
215
216 /**
217 * Returns the page info like page title, slug and link.
218 *
219 * @since 1.0.0
220 * @package userswp
221 *
222 * @param array $page_data Page data array.
223 * @param string $page_type Page type.
224 *
225 * @return array Page data array.
226 */
227 function uwp_get_page_url_page_data($page_data, $page_type) {
228 $page_id = uwp_get_page_id($page_type, false);
229 if ($page_id) {
230 $page = get_post($page_id);
231 $page_data = array(
232 'name' => $page->post_title,
233 'slug' => $page->post_name,
234 'link' => get_permalink( $page->ID ),
235 );
236 }
237 return apply_filters('uwp_page_url_data', $page_data);
238 }
239
240 add_action('init', 'uwp_process_activation_link');
241
242 /**
243 * Handles the activation request coming via email activation link.
244 *
245 * @since 1.0.0
246 * @package userswp
247 *
248 * @return void
249 */
250 function uwp_process_activation_link() {
251 if (isset($_GET['uwp_activate']) && $_GET['uwp_activate'] == 'yes') {
252 if(!defined('DONOTCACHEPAGE')){
253 define( 'DONOTCACHEPAGE', true );
254 }
255 $key = strip_tags(esc_sql($_GET['key']));
256 $login = strip_tags(esc_sql($_GET['login']));
257 $login_page = uwp_get_page_id('login_page', false);
258 $user = get_user_by('login', $login);
259 if (!$user){
260 $redirect_to = add_query_arg(array('uwp_err' => 'act_wrong'), get_permalink($login_page));
261 wp_redirect($redirect_to);
262 exit();
263 }
264
265 clean_user_cache($user);
266
267 $result = check_password_reset_key($key, $login);
268
269 if (is_wp_error($result)) {
270 if ($login_page) {
271 $redirect_to = add_query_arg(array('uwp_err' => 'act_wrong'), get_permalink($login_page));
272 wp_safe_redirect($redirect_to);
273 exit();
274 }
275 } else {
276 if (!$result) {
277 if ($login_page) {
278 $redirect_to = add_query_arg(array('uwp_err' => 'act_error'), get_permalink($login_page));
279 wp_safe_redirect($redirect_to);
280 exit();
281 }
282 } else {
283 if ($login_page) {
284 $user_data = get_user_by('login', $login);
285 update_user_meta( $user_data->ID, 'uwp_mod', '0' );
286 $redirect_to = add_query_arg(array('uwp_err' => 'act_success'), get_permalink($login_page));
287 do_action('uwp_email_activation_success', $user_data->ID);
288 wp_safe_redirect($redirect_to);
289 exit();
290 }
291 }
292 }
293 }
294 }
295
296 add_action('template_redirect', 'uwp_process_new_email_activation_link');
297 /**
298 * Handles the new email activation request coming via email activation link.
299 *
300 * @since 1.0.0
301 * @package userswp
302 *
303 * @return void
304 */
305 function uwp_process_new_email_activation_link() {
306 if (isset($_GET['uwp_new_email']) && $_GET['uwp_new_email'] == 'yes') {
307 if(!defined('DONOTCACHEPAGE')){
308 define( 'DONOTCACHEPAGE', true );
309 }
310 $key = strip_tags(esc_sql($_GET['key']));
311 $login = strip_tags(esc_sql($_GET['login']));
312 $account_page = uwp_get_page_id('account_page', false);
313 $user = get_user_by('login', $login);
314 if (!$user){
315 return;
316 }
317
318 if ( ! is_user_logged_in()) {
319 $login_page = uwp_get_page_id( 'login_page', false );
320 $redirect_to = add_query_arg(array('redirect_to' => urlencode(uwp_current_page_url())), get_permalink($login_page));
321 wp_safe_redirect($redirect_to);
322 exit();
323 }
324
325 clean_user_cache($user);
326
327 $hash = get_user_meta($user->ID, 'uwp_update_email_hash', true);
328
329 if ( $user && isset($hash) && hash_equals( $hash['hash'], $key ) && ! empty( $hash['newemail'] ) ) {
330 $args = array(
331 'ID' => $user->ID,
332 'user_email' => $hash['newemail'],
333 );
334 $user_id = wp_update_user( $args );
335 delete_user_meta($user_id, 'uwp_update_email_hash', true);
336
337 $redirect_to = add_query_arg(array('uwp_err' => 'act_email_success'), get_permalink($account_page));
338 do_action('uwp_new_email_activation_success', $user->ID);
339 wp_safe_redirect($redirect_to);
340 exit();
341 }
342 }
343 }
344
345 function uwp_current_page_url() {
346 $pageURL = 'http';
347 if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) == 'on')) {
348 $pageURL .= "s";
349 }
350 $pageURL .= "://";
351
352 /*
353 * Since we are assigning the URI from the server variables, we first need
354 * to determine if we are running on apache or IIS. If PHP_SELF and REQUEST_URI
355 * are present, we will assume we are running on apache.
356 */
357 if (!empty($_SERVER['PHP_SELF']) && !empty($_SERVER['REQUEST_URI'])) {
358 // To build the entire URI we need to prepend the protocol, and the http host
359 // to the URI string.
360 $pageURL .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
361 } else {
362 /*
363 * Since we do not have REQUEST_URI to work with, we will assume we are
364 * running on IIS and will therefore need to work some magic with the SCRIPT_NAME and
365 * QUERY_STRING environment variables.
366 *
367 * IIS uses the SCRIPT_NAME variable instead of a REQUEST_URI variable... thanks, MS
368 */
369 $pageURL .= $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'];
370
371 // If the query string exists append it to the URI string
372 if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
373 $pageURL .= '?' . $_SERVER['QUERY_STRING'];
374 }
375 }
376
377 /**
378 * Filter the current page URL returned by function uwp_current_page_url().
379 *
380 * @since 1.4.1
381 *
382 * @param string $pageURL The URL of the current page.
383 */
384 return apply_filters( 'uwp_current_page_url', $pageURL );
385 }