PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.0.13
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.0.13
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 / libraries / class-geodirectory-plugin.php

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

1,271 lines 54.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * GeoDirectory plugin related functions
4 *
5 * This class defines all code necessary for GeoDirectory plugin.
6 *
7 * @since 1.0.0
8 * @author GeoDirectory Team <info@wpgeodirectory.com>
9 */
10 class UsersWP_GeoDirectory_Plugin {
11 private static $instance;
12
13 public static function get_instance() {
14 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof UsersWP_GeoDirectory_Plugin ) ) {
15 self::$instance = new UsersWP_GeoDirectory_Plugin;
16 self::$instance->setup_globals();
17 self::$instance->includes();
18 self::$instance->setup_actions();
19 }
20
21 return self::$instance;
22 }
23
24 private function __construct() {
25 self::$instance = $this;
26 }
27
28 private function setup_globals() {
29
30 }
31
32 private function setup_actions() {
33 if ( is_admin() ) {
34 add_filter( 'uwp_display_form_title', array( $this, 'display_form_title' ), 10, 3 );
35 add_action( 'uwp_geodirectory_settings_main_tab_content', array( $this, 'main_tab_content' ), 10, 1 );
36 add_action( 'uwp_admin_sub_menus', array( $this, 'add_admin_gd_sub_menu' ), 10, 1 );
37 add_filter( 'uwp_settings_tabs', array( $this, 'add_gd_tab' ) );
38 add_filter( 'uwp_registered_settings', array( $this, 'add_gd_settings' ) );
39 add_filter( 'uwp_available_tab_items', array( $this, 'available_tab_items' ) );
40 } else {
41 add_filter( 'uwp_profile_tabs', array( $this, 'add_profile_gd_tabs' ), 10, 3 );
42 add_action( 'uwp_profile_listings_tab_content', array( $this, 'add_profile_listings_tab_content' ) );
43 add_action( 'uwp_profile_reviews_tab_content', array( $this, 'add_profile_reviews_tab_content' ) );
44 add_action( 'uwp_profile_favorites_tab_content', array( $this, 'add_profile_favorites_tab_content' ) );
45 add_action( 'uwp_profile_invoices_tab_content', array( $this, 'add_profile_invoices_tab_content' ) );
46 add_action( 'uwp_profile_gd_listings_subtab_content', array( $this, 'gd_get_listings' ), 10, 2 );
47 add_action( 'uwp_profile_gd_reviews_subtab_content', array( $this, 'gd_get_reviews' ), 10, 2 );
48 add_action( 'uwp_profile_gd_favorites_subtab_content', array( $this, 'gd_get_favorites' ), 10, 2 );
49 //add_action( 'geodir_after_edit_post_link_on_listing', array( $this, 'geodir_add_post_status_author_page' ), 11 );
50 }
51 add_filter( 'geodir_login_url', array( $this, 'get_gd_login_url' ), 10, 2 );
52 add_action( 'wp', array( $this, 'geodir_uwp_author_redirect' ) );
53 add_filter( 'geodir_post_status_is_author_page', array( $this, 'geodir_post_status_is_author_page' ) );
54 add_filter( 'gd_login_wid_login_placeholder', array( $this, 'gd_login_wid_login_placeholder' ) );
55 add_filter( 'gd_login_wid_login_name', array( $this, 'gd_login_wid_login_name' ) );
56 add_filter( 'gd_login_wid_login_pwd', array( $this, 'gd_login_wid_login_pwd' ) );
57 add_action( 'login_form', array( $this, 'gd_login_inject_nonce' ) );
58 add_filter( 'uwp_check_redirect_author_page', array( $this, 'check_redirect_author_page' ), 10, 1 );
59 add_filter( 'uwp_use_author_page_content', array( $this, 'skip_uwp_author_page' ), 10, 1 );
60
61 do_action( 'uwp_gd_setup_actions', $this );
62 }
63
64 private function includes() {
65 do_action( 'uwp_gd_include_files' );
66
67 if ( is_admin() ) {
68 do_action( 'uwp_gd_include_admin_files' );
69 }
70 }
71
72 /**
73 * Modifies the settings form title.
74 *
75 * @since 1.0.0
76 * @package userswp
77 *
78 * @param string $title Original title.
79 * @param string $page admin.php?page=uwp_xxx.
80 * @param string $active_tab active tab in that settings page.
81 *
82 * @return string Form title.
83 */
84 public function display_form_title( $title, $page, $active_tab ) {
85 if ( $page == 'uwp_geodirectory' && $active_tab == 'main' ) {
86 $title = __( 'GeoDirectory Settings', 'userswp' );
87 }
88 return $title;
89 }
90
91 /**
92 * Prints the settings form.
93 *
94 * @since 1.0.0
95 * @package userswp
96 *
97 * @param string $form Setting form html.
98 *
99 * @return void
100 */
101 public function main_tab_content( $form ) {
102 echo $form;
103 }
104
105 /**
106 * Adds the current userswp addon settings page menu as submenu.
107 *
108 * @since 1.0.0
109 * @package userswp
110 *
111 * @param callable $settings_page The function to be called to output the content for this page.
112 *
113 * @return void
114 */
115 public function add_admin_gd_sub_menu( $settings_page ) {
116 add_submenu_page(
117 "userswp",
118 __( 'GeoDirectory', 'userswp' ),
119 __( 'GeoDirectory', 'userswp' ),
120 'manage_options',
121 'uwp_geodirectory',
122 $settings_page
123 );
124 }
125
126 /**
127 * Adds settings tabs for the current userswp addon.
128 *
129 * @since 1.0.0
130 * @package userswp
131 *
132 * @param array $tabs Existing tabs array.
133 *
134 * @return array Tabs array.
135 */
136 public function add_gd_tab( $tabs ) {
137 $tabs['uwp_geodirectory'] = array(
138 'main' => __( 'GeoDirectory', 'userswp' ),
139 );
140 return $tabs;
141 }
142
143 /**
144 * Registers form fields for the current userswp addon settings page.
145 *
146 * @since 1.0.0
147 * @package userswp
148 *
149 * @param array $uwp_settings Existing settings array.
150 *
151 * @return array Settings array.
152 */
153 public function add_gd_settings( $uwp_settings ) {
154 $gd_posttypes = $this->get_gd_posttypes();
155
156 $options = array(
157 'gd_settings_info' => array(
158 'id' => 'woo_settings_info',
159 'name' => __( 'Info', 'userswp' ),
160 'desc' => __( 'You can now add Listings, Reviews and Favorites tabs under UsersWP > Profile > Choose the tabs to display in Profile', 'userswp' ),
161 'type' => 'info',
162 'std' => '1',
163 'class' => 'uwp_label_inline',
164 ),
165 'gd_profile_listings' => array(
166 'id' => 'gd_profile_listings',
167 'name' => __( 'CPT listings in Profile', 'userswp' ),
168 'desc' => __( 'Choose the post types to show listings tab in UsersWP Profile', 'userswp' ),
169 'multiple' => true,
170 'chosen' => true,
171 'type' => 'select',
172 'options' => $gd_posttypes,
173 'placeholder' => __( 'Select Post Types', 'userswp' )
174 ),
175 'gd_profile_reviews' => array(
176 'id' => 'gd_profile_reviews',
177 'name' => __( 'CPT reviews in Profile', 'userswp' ),
178 'desc' => __( 'Choose the post types to show reviews tab in UsersWP Profile', 'userswp' ),
179 'multiple' => true,
180 'chosen' => true,
181 'type' => 'select',
182 'options' => $gd_posttypes,
183 'placeholder' => __( 'Select Post Types', 'userswp' )
184 ),
185 'gd_profile_favorites' => array(
186 'id' => 'gd_profile_favorites',
187 'name' => __( 'CPT favorites in Profile', 'userswp' ),
188 'desc' => __( 'Choose the post types to show favorites tab in UsersWP Profile', 'userswp' ),
189 'multiple' => true,
190 'chosen' => true,
191 'type' => 'select',
192 'options' => $gd_posttypes,
193 'placeholder' => __( 'Select Post Types', 'userswp' )
194 ),
195 'geodir_uwp_link_listing' => array(
196 'id' => 'geodir_uwp_link_listing',
197 'name' => __( 'Redirect GD dashboard my listing link to UsersWP profile', 'userswp' ),
198 'desc' => __( 'If this option is selected, the my listing link from GD dashboard will redirect to listings tab of UsersWP profile.', 'userswp' ),
199 'type' => 'checkbox',
200 'std' => '0',
201 'class' => 'uwp_label_inline',
202 ),
203 'geodir_uwp_link_favorite' => array(
204 'id' => 'geodir_uwp_link_favorite',
205 'name' => __( 'Redirect GD dashboard favorite link to UsersWP profile', 'userswp' ),
206 'desc' => __( 'If this option is selected, the favorite link from GD dashboard will redirect to favorites tab of UsersWP profile.', 'userswp' ),
207 'type' => 'checkbox',
208 'std' => '0',
209 'class' => 'uwp_label_inline',
210 ),
211 );
212
213 $uwp_settings['uwp_geodirectory'] = array(
214 'main' => apply_filters( 'uwp_settings_geodirectory', $options ),
215 );
216
217 return $uwp_settings;
218 }
219
220 public function get_gd_posttypes() {
221 $post_type_arr = array();
222 $post_types = geodir_get_posttypes( 'object' );
223
224 foreach ( $post_types as $key => $post_types_obj ) {
225 $post_type_arr[$key] = $post_types_obj->labels->singular_name;
226 }
227 return $post_type_arr;
228 }
229
230 /**
231 * Registers the current addon tab items in "Choose the tabs to display in UsersWP Profile" setting.
232 *
233 * @since 1.0.0
234 * @package userswp
235 *
236 * @param array $tabs_arr Existing tabs array.
237 *
238 * @return array Tabs array.
239 */
240 public function available_tab_items( $tabs_arr ) {
241 $tabs_arr['listings'] = __( 'Listings', 'userswp' );
242 $tabs_arr['reviews'] = __( 'Reviews', 'userswp' );
243 $tabs_arr['favorites'] = __( 'Favorites', 'userswp' );
244
245 if ( class_exists( 'WPInv_Invoice' ) ) {
246 $tabs_arr['invoices'] = __( 'Invoices', 'userswp' );
247 }
248
249 return $tabs_arr;
250 }
251
252 public function geodir_get_reviews_by_user_id($post_type = 'gd_place', $user_id, $count_only = false, $offset = 0, $limit = 20) {
253 global $wpdb;
254
255 if ($count_only) {
256 $results = $wpdb->get_var(
257 $wpdb->prepare(
258 "SELECT COUNT(reviews.overall_rating) FROM " . GEODIR_REVIEW_TABLE . " reviews JOIN " . $wpdb->posts . " posts ON reviews.post_id = posts.id WHERE reviews.user_id = %d AND reviews.post_type = %s AND reviews.status=1 AND reviews.overall_rating>0 AND posts.post_status = 'publish'",
259 array($user_id, $post_type)
260 )
261 );
262 } else {
263 $results = $wpdb->get_results(
264 $wpdb->prepare(
265 "SELECT reviews.* FROM " . GEODIR_REVIEW_TABLE . " reviews JOIN " . $wpdb->posts . " posts ON reviews.post_id = posts.id WHERE reviews.user_id = %d AND reviews.post_type = %s AND reviews.status=1 AND reviews.overall_rating>0 AND posts.post_status = 'publish' LIMIT %d OFFSET %d",
266 array($user_id, $post_type, $limit, $offset )
267 )
268 );
269 }
270
271 if (!empty($results))
272 return $results;
273 else
274 return false;
275 }
276
277 public function geodir_count_favorite( $post_type, $user_id = 0 ) {
278 global $wpdb;
279
280 $post_status = is_super_admin() ? " OR " . $wpdb->posts . ".post_status = 'private'" : '';
281 if ( $user_id && $user_id == get_current_user_id() ) {
282 $post_status .= " OR " . $wpdb->posts . ".post_status = 'draft' OR " . $wpdb->posts . ".post_status = 'private'";
283 }
284
285 $user_fav_posts = geodir_get_user_favourites( (int)$user_id );
286 $user_fav_posts = !empty( $user_fav_posts ) ? implode( "','", $user_fav_posts ) : "-1";
287
288 $count = (int)$wpdb->get_var( "SELECT count( ID ) FROM ".$wpdb->posts." WHERE " . $wpdb->posts . ".ID IN ('" . $user_fav_posts . "') AND post_type='" . $post_type . "' AND ( post_status = 'publish' " . $post_status . " )" );
289
290 return apply_filters( 'uwp_geodir_count_favorite', $count, $user_id );
291 }
292
293 public function get_listings_count($post_type, $user_id = 0) {
294 global $wpdb;
295 if (empty($user_id)) {
296 return 0;
297 }
298
299 $post_status = is_super_admin() ? " OR " . $wpdb->posts . ".post_status = 'private'" : '';
300 if ($user_id && $user_id == get_current_user_id()) {
301 $post_status .= " OR " . $wpdb->posts . ".post_status = 'draft' OR " . $wpdb->posts . ".post_status = 'private'";
302 }
303
304 $count = (int)$wpdb->get_var("SELECT count( ID ) FROM " . $wpdb->prefix . "posts WHERE post_author=" . (int)$user_id . " AND post_type='" . $post_type . "' AND ( post_status = 'publish' " . $post_status . " )");
305
306 return apply_filters('geodir_uwp_count_total', $count, $user_id);
307 }
308
309 public function get_total_listings_count($user_id = 0) {
310 if (empty($user_id)) {
311 return 0;
312 }
313
314 $gd_post_types = geodir_get_posttypes('array');
315
316 if (empty($gd_post_types)) {
317 return 0;
318 }
319
320
321 // allowed post types
322 $listing_post_types = uwp_get_option('gd_profile_listings', array());
323
324 if (!is_array($listing_post_types)) {
325 $listing_post_types = array();
326 }
327
328 $count = 0;
329 $total_count = 0;
330 foreach ($listing_post_types as $post_type) {
331 if (array_key_exists($post_type, $gd_post_types)) {
332
333 // get listing count
334 $listing_count = $this->get_listings_count($post_type, $user_id);
335 $total_count += $listing_count;
336
337 $count++;
338 }
339 }
340
341 return $total_count;
342 }
343
344 public function get_total_reviews_count($user_id = 0) {
345 if (empty($user_id)) {
346 return 0;
347 }
348
349 $gd_post_types = geodir_get_posttypes('array');
350
351 if (empty($gd_post_types)) {
352 return 0;
353 }
354
355 // allowed post types
356 $listing_post_types = uwp_get_option('gd_profile_reviews', array());
357
358 if (!is_array($listing_post_types)) {
359 $listing_post_types = array();
360 }
361
362 $count = 0;
363 $total_count = 0;
364 foreach ($listing_post_types as $post_type) {
365 if (array_key_exists($post_type, $gd_post_types)) {
366
367 // get listing count
368 $listing_count = $this->geodir_get_reviews_by_user_id($post_type, $user_id, true);
369 $total_count += $listing_count;
370
371 $count++;
372 }
373 }
374
375 return $total_count;
376 }
377
378 public function get_total_favorites_count($user_id = 0) {
379 if (empty($user_id)) {
380 return 0;
381 }
382
383 $gd_post_types = geodir_get_posttypes('array');
384
385 if (empty($gd_post_types)) {
386 return 0;
387 }
388
389 // allowed post types
390 $listing_post_types = uwp_get_option('gd_profile_favorites', array());
391
392 if (!is_array($listing_post_types)) {
393 $listing_post_types = array();
394 }
395
396 $count = 0;
397 $total_count = 0;
398 foreach ($listing_post_types as $post_type) {
399 if (array_key_exists($post_type, $gd_post_types)) {
400
401 // get listing count
402 $listing_count = $this->geodir_count_favorite($post_type, $user_id);
403 $total_count += $listing_count;
404
405 $count++;
406 }
407 }
408
409 return $total_count;
410 }
411
412 /**
413 * Adds tab in user profile page.
414 *
415 * @since 1.0.0
416 * @package userswp
417 *
418 * @param array $tabs Existing tabs array.
419 * @param object $user User object.
420 * @param array $allowed_tabs Allowed tabs array.
421 *
422 * @return array Tabs array.
423 */
424 function add_profile_gd_tabs($tabs, $user,$allowed_tabs) {
425 // allowed post types
426 $listing_post_types = uwp_get_option('gd_profile_listings', array());
427 if (!empty($listing_post_types) && in_array('listings', $allowed_tabs)) {
428 $tabs['listings'] = array(
429 'title' => __('Listings', 'userswp'),
430 'count' => $this->get_total_listings_count($user->ID)
431 );
432 }
433
434 $listing_post_types = uwp_get_option('gd_profile_reviews', array());
435 if (!empty($listing_post_types) && in_array('reviews', $allowed_tabs)) {
436 $tabs['reviews'] = array(
437 'title' => __('Reviews', 'userswp'),
438 'count' => $this->get_total_reviews_count($user->ID)
439 );
440 }
441
442 $listing_post_types = uwp_get_option('gd_profile_favorites', array());
443 if (!empty($listing_post_types) && in_array('favorites', $allowed_tabs) && (get_current_user_id() == $user->ID)) {
444 $tabs['favorites'] = array(
445 'title' => __('Favorites', 'userswp'),
446 'count' => $this->get_total_favorites_count($user->ID)
447 );
448 }
449
450 if (class_exists('WPInv_Invoice') && in_array('invoices', $allowed_tabs) && (get_current_user_id() == $user->ID)) {
451 $tabs['invoices'] = array(
452 'title' => __('Invoices', 'userswp'),
453 'count' => $this->invoice_count($user->ID)
454 );
455 }
456
457 return $tabs;
458 }
459
460 /**
461 * Adds GD listings tab content.
462 *
463 * @since 1.0.0
464 * @package userswp
465 *
466 * @param object $user User object.
467 *
468 * @return void
469 */
470 public function add_profile_listings_tab_content($user) {
471 $this->profile_gd_subtabs_content($user, 'listings');
472 }
473
474 /**
475 * Adds GD reviews tab content.
476 *
477 * @since 1.0.0
478 * @package userswp
479 *
480 * @param object $user User object.
481 *
482 * @return void
483 */
484 public function add_profile_reviews_tab_content($user) {
485 $this->profile_gd_subtabs_content($user, 'reviews');
486 }
487
488 /**
489 * Adds GD Favorites tab content.
490 *
491 * @since 1.0.0
492 * @package userswp
493 *
494 * @param object $user User object.
495 *
496 * @return void
497 */
498 public function add_profile_favorites_tab_content($user) {
499 $this->profile_gd_subtabs_content($user, 'favorites');
500 }
501
502 /**
503 * Adds GD Invoices tab content.
504 *
505 * @since 1.0.0
506 * @package userswp
507 *
508 * @param object $user User object.
509 *
510 * @return void
511 */
512 public function add_profile_invoices_tab_content($user) {
513 $this->profile_gd_invoices_content($user);
514 }
515
516 public function profile_gd_subtabs($user, $type = 'listings') {
517 $tabs = array();
518
519 $gd_post_types = geodir_get_posttypes('array');
520
521 if (empty($gd_post_types)) {
522 return $tabs;
523 }
524
525 // allowed post types
526 if ($type == 'listings') {
527 $listing_post_types = uwp_get_option('gd_profile_listings', array());
528 } elseif ($type == 'reviews') {
529 $listing_post_types = uwp_get_option('gd_profile_reviews', array());
530 } elseif ($type == 'favorites') {
531 $listing_post_types = uwp_get_option('gd_profile_favorites', array());
532 } else {
533 $listing_post_types = array();
534 }
535
536 if (!is_array($listing_post_types)) {
537 $listing_post_types = array();
538 }
539
540 foreach ($listing_post_types as $post_type) {
541 if (array_key_exists($post_type, $gd_post_types)) {
542 $post_type_slug = $gd_post_types[$post_type]['has_archive'];
543
544 if ($type == 'listings') {
545 $count = uwp_post_count($user->ID, $post_type);
546 } elseif ($type == 'reviews') {
547 $count = $this->geodir_get_reviews_by_user_id($post_type, $user->ID, true);
548 } elseif ($type == 'favorites') {
549 $count = $this->geodir_count_favorite($post_type, $user->ID);
550 } else {
551 $count = 0;
552 }
553
554 if (empty($count)) {
555 $count = 0;
556 }
557 $tabs[$post_type_slug] = array(
558 'title' => $gd_post_types[$post_type]['labels']['name'],
559 'count' => $count,
560 'ptype' => $post_type
561 );
562 }
563 }
564
565 return apply_filters('uwp_profile_gd_tabs', $tabs, $user, $type);
566 }
567
568 public function profile_gd_subtabs_content($user, $type = 'listings') {
569 $subtab = get_query_var('uwp_subtab');
570 $subtabs = $this->profile_gd_subtabs($user, $type);
571 $active_tab = !empty($subtab) && array_key_exists($subtab, $subtabs) ? $subtab : 'places';
572 if (!empty($subtabs)) {
573 $subtab_keys = array_keys($subtabs);
574 $post_type = $subtabs[$subtab_keys[0]]['ptype'];
575 } else {
576 $post_type = false;
577 }
578 ?>
579 <div class="uwp-profile-subcontent">
580 <div class="uwp-profile-subnav">
581 <?php if ($subtabs) { ?>
582 <ul class="item-list-subtabs-ul">
583 <?php
584 foreach ($this->profile_gd_subtabs($user, $type) as $tab_id => $tab) {
585
586 $tab_url = uwp_build_profile_tab_url($user->ID, $type, $tab_id);
587
588 $active = $active_tab == $tab_id ? ' active' : '';
589 $post_type = $active_tab == $tab_id ? $tab['ptype'] : $post_type;
590 ?>
591 <li id="uwp-profile-gd-<?php echo $tab_id; ?>" class="<?php echo $active; ?>">
592 <a href="<?php echo esc_url($tab_url); ?>">
593 <span class="uwp-profile-tab-label uwp-profile-gd-<?php echo $tab_id; ?>-label "><span
594 class="uwp-profile-tab-sub-ul-count uwp-profile-sub-ul-gd-<?php echo $tab_id; ?>-count"><?php echo $tab['count']; ?></span> <?php echo esc_html($tab['title']); ?></span>
595 </a>
596 </li>
597 <?php
598 }
599 ?>
600 </ul>
601 <?php } ?>
602 </div>
603
604 <div class="uwp-profile-subtab-entries">
605 <?php
606 do_action('uwp_profile_gd_' . $type . '_subtab_content', $user, $post_type);
607 ?>
608 </div>
609 </div>
610 <?php
611 }
612
613 function gd_get_listings($user, $post_type) {
614 $gd_post_types = geodir_get_posttypes('array');
615 ?>
616 <h3><?php echo __($gd_post_types[$post_type]['labels']['name'], 'userswp') ?></h3>
617
618 <div class="uwp-profile-item-block">
619 <?php
620
621 $paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
622
623 $args = array(
624 'post_type' => $post_type,
625 'post_status' => array('publish'),
626 'posts_per_page' => uwp_get_option('profile_no_of_items', 10),
627 'author' => $user->ID,
628 'paged' => $paged,
629 );
630
631 if (get_current_user_id() == $user->ID) {
632 $args['post_status'] = array('publish', 'draft', 'private');
633 }
634 // The Query
635 $the_query = new WP_Query($args);
636
637 do_action('uwp_before_profile_listing_items', $user, $post_type);
638 // The Loop
639 if ($the_query->have_posts()) {
640 echo '<ul class="uwp-profile-item-ul">';
641 while ($the_query->have_posts()) {
642 $the_query->the_post();
643 $post_id = get_the_ID();
644 global $post;
645 $post = geodir_get_post_info($post_id);
646 setup_postdata($post);
647 $post_avgratings = geodir_get_post_rating($post->ID);
648 $post_ratings = geodir_get_rating_stars($post_avgratings, $post->ID);
649 ob_start();
650 geodir_comments_number($post->rating_count);
651 $n_comments = ob_get_contents();
652 ob_end_clean();
653
654 do_action('uwp_before_profile_listing_item', $post_id, $user, $post_type);
655 ?>
656 <li class="uwp-profile-item-li uwp-profile-item-clearfix">
657 <a class="uwp-profile-item-img" href="<?php echo get_the_permalink(); ?>">
658 <?php
659 if (has_post_thumbnail()) {
660 $thumb_url = get_the_post_thumbnail_url(get_the_ID(), array(80, 80));
661 } else {
662 $thumb_url = $thumb_url = plugins_url() . "/userswp/public/assets/images/no_thumb.png";
663 }
664 ?>
665 <img class="uwp-profile-item-alignleft uwp-profile-item-thumb" src="<?php echo $thumb_url; ?>">
666 </a>
667
668 <?php do_action('uwp_before_profile_listing_title', $post_id, $user, $post_type); ?>
669 <h3 class="uwp-profile-item-title">
670 <a href="<?php echo get_the_permalink(); ?>"><?php echo get_the_title(); ?></a>
671 </h3>
672 <?php do_action('uwp_after_profile_listing_title', $post_id, $user, $post_type); ?>
673
674 <div class="uwp-time-ratings-wrap">
675 <?php do_action('uwp_before_profile_listing_ratings', $post_id, $user, $post_type); ?>
676 <time class="uwp-profile-item-time published" datetime="<?php echo get_the_time('c'); ?>">
677 <?php echo get_the_date(); ?>
678 </time>
679 <?php echo '<div class="uwp-ratings">' . $post_ratings . ' <a href="' . get_comments_link() . '" class="uwp-num-comments">' . $n_comments . '</a></div>'; ?>
680 <?php
681 if (!is_user_logged_in()) {
682 do_action( 'geodir_after_favorite_html', $post->ID, 'listing' );
683 }
684 ?>
685 <?php do_action('uwp_after_profile_listing_ratings', $post_id, $user, $post_type); ?>
686 </div>
687 <div class="uwp-item-actions">
688 <?php
689 if (is_user_logged_in()) {
690 do_action( 'geodir_after_favorite_html', $post->ID, 'listing' );
691 }
692 if ($post->post_author == get_current_user_id()) {
693 $addplacelink = get_permalink(geodir_add_listing_page_id());
694 $editlink = geodir_getlink($addplacelink, array('pid' => $post->ID), false);
695
696 $ajaxlink = geodir_get_ajax_url();
697 $deletelink = geodir_getlink($ajaxlink, array('geodir_ajax' => 'add_listing', 'ajax_action' => 'delete', 'pid' => $post->ID), false);
698 ?>
699
700 <span class="geodir-authorlink clearfix">
701
702 <?php do_action('geodir_before_edit_post_link_on_listing', $post_id, $user, $post_type); ?>
703
704 <a href="<?php echo esc_url($editlink); ?>" class="geodir-edit"
705 title="<?php _e('Edit Listing', 'userswp'); ?>">
706 <?php
707 $geodir_listing_edit_icon = apply_filters('geodir_listing_edit_icon', 'fa fa-edit');
708 echo '<i class="' . $geodir_listing_edit_icon . '"></i>';
709 ?>
710 <?php _e('Edit', 'userswp'); ?>
711 </a>
712 <a href="<?php echo esc_url($deletelink); ?>" class="geodir-delete"
713 title="<?php _e('Delete Listing', 'userswp'); ?>">
714 <?php
715 $geodir_listing_delete_icon = apply_filters('geodir_listing_delete_icon', 'fa fa-close', $post_id, $user, $post_type);
716 echo '<i class="' . $geodir_listing_delete_icon . '"></i>';
717 ?>
718 <?php _e('Delete', 'userswp'); ?>
719 </a>
720
721 <?php do_action('geodir_after_edit_post_link_on_listing', $post_id, $user, $post_type); ?>
722
723 </span>
724
725 <?php } ?>
726 </div>
727
728 <div class="uwp-profile-item-summary">
729 <?php
730 do_action('uwp_before_profile_listing_summary', $post_id, $user, $post_type);
731 $excerpt = strip_shortcodes(wp_trim_words(get_the_excerpt(), 15, '...'));
732 echo $excerpt;
733 if ($excerpt) {
734 ?>
735 <a href="<?php echo get_the_permalink(); ?>" class="more-link"><?php echo __( 'Read More »', 'userswp' ); ?></a>
736 <?php
737 }
738 do_action('uwp_after_profile_listing_summary', $post_id, $user, $post_type);
739 ?>
740 </div>
741 </li>
742 <?php
743 do_action('uwp_after_profile_listing_item', $post_id, $user, $post_type);
744 }
745 echo '</ul>';
746 /* Restore original Post Data */
747 wp_reset_postdata();
748 } else {
749 echo sprintf( __( "No %s found", 'userswp' ), $gd_post_types[$post_type]['labels']['name']);
750 }
751 do_action('uwp_after_profile_listing_items', $user, $post_type);
752
753 do_action('uwp_profile_pagination', $the_query->max_num_pages);
754 ?>
755 </div>
756 <?php
757 }
758
759 public function gd_get_reviews($user, $post_type) {
760 $gd_post_types = geodir_get_posttypes('array');
761 ?>
762 <h3><?php echo __($gd_post_types[$post_type]['labels']['name'], 'userswp') ?></h3>
763
764 <div class="uwp-profile-item-block">
765 <?php
766 $paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
767 $limit = uwp_get_option('profile_no_of_items', 10);
768 $offset = ($paged - 1) * $limit;
769
770 $total_reviews = $this->geodir_get_reviews_by_user_id($post_type, $user->ID, true, $offset, $limit);
771 $maximum_pages = ceil($total_reviews / $limit);
772
773 $reviews = $this->geodir_get_reviews_by_user_id($post_type, $user->ID, false, $offset, $limit);
774
775 do_action('uwp_before_profile_reviews_items', $user, $post_type);
776 // The Loop
777 if ($reviews) {
778 echo '<ul class="uwp-profile-item-ul">';
779 foreach ($reviews as $review) {
780 $rating = 0;
781 if (!empty($review))
782 $rating = geodir_get_commentoverall($review->comment_id);
783
784 do_action('uwp_before_profile_reviews_item', $review->comment_id, $user, $post_type);
785 ?>
786 <li class="uwp-profile-item-li uwp-profile-item-clearfix">
787 <a class="uwp-profile-item-img" href="<?php echo get_comment_link($review->comment_id); ?>">
788 <?php
789 $args = array(
790 'size' => 80
791 );
792 $thumb_url = get_avatar_url($review->user_id, 80);
793 echo $thumb_url;
794 ?>
795 </a>
796
797 <?php do_action('uwp_before_profile_reviews_title', $review->comment_id, $user, $post_type); ?>
798 <h3 class="uwp-profile-item-title">
799 <a href="<?php echo get_comment_link($review->comment_id); ?>"><?php echo get_the_title($review->post_id); ?></a>
800 </h3>
801 <?php do_action('uwp_after_profile_reviews_title', $review->comment_id, $user, $post_type); ?>
802
803 <div class="uwp-time-ratings-wrap">
804 <?php do_action('uwp_before_profile_reviews_ratings', $review->comment_id, $user, $post_type); ?>
805 <time class="uwp-profile-item-time published" datetime="<?php echo get_the_time('c'); ?>">
806 <?php echo date_i18n(get_option('date_format'), strtotime(get_comment_date("", $review->comment_id))); ?>
807 </time>
808 <?php echo '<div class="uwp-ratings">' . geodir_get_rating_stars($rating, $review->comment_id) . '</div>'; ?>
809 <?php do_action('uwp_after_profile_reviews_ratings', $review->comment_id, $user, $post_type); ?>
810 </div>
811 <div class="uwp-profile-item-summary">
812 <?php
813 do_action('uwp_before_profile_reviews_summary', $review->comment_id, $user, $post_type);
814 $excerpt = strip_shortcodes(wp_trim_words($review->comment_content, 15, '...'));
815 echo $excerpt;
816 if ($excerpt) {
817 ?>
818 <a href="<?php echo get_comment_link($review->comment_id); ?>" class="more-link">Read More
819 »</a>
820 <?php
821 }
822 do_action('uwp_after_profile_reviews_summary', $review->comment_id, $user, $post_type);
823 ?>
824 </div>
825 </li>
826 <?php
827 do_action('uwp_after_profile_reviews_item', $review->comment_id, $user, $post_type);
828 }
829 echo '</ul>';
830 /* Restore original Post Data */
831 wp_reset_postdata();
832 } else {
833 echo sprintf( __( "No %s found", 'userswp' ), $gd_post_types[$post_type]['labels']['name']);
834 }
835
836 do_action('uwp_after_profile_reviews_items', $user, $post_type);
837
838 do_action('uwp_profile_pagination', $maximum_pages);
839 ?>
840 </div>
841 <?php
842 }
843
844 public function gd_get_favorites($user, $post_type) {
845 $gd_post_types = geodir_get_posttypes('array');
846 ?>
847 <h3><?php echo __($gd_post_types[$post_type]['labels']['name'], 'userswp') ?></h3>
848
849 <div class="uwp-profile-item-block">
850 <?php
851 $paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
852
853 $user_fav_posts = geodir_get_user_favourites($user->ID);
854
855 if ($user_fav_posts) {
856 $args = array(
857 'post_type' => $post_type,
858 'post_status' => array('publish'),
859 'posts_per_page' => uwp_get_option('profile_no_of_items', 10),
860 'post__in' => $user_fav_posts,
861 'paged' => $paged,
862 );
863
864 if (get_current_user_id() == $user->ID) {
865 $args['post_status'] = array('publish', 'draft', 'private');
866 }
867
868 // The Query
869 $the_query = new WP_Query($args);
870
871 do_action('uwp_before_profile_favourite_items', $user, $post_type);
872 // The Loop
873 if ($the_query->have_posts()) {
874 echo '<ul class="uwp-profile-item-ul">';
875 while ($the_query->have_posts()) {
876 $the_query->the_post();
877 $post_id = get_the_ID();
878 global $post;
879 $post = geodir_get_post_info($post_id);
880 setup_postdata($post);
881 $post_avgratings = geodir_get_post_rating($post->ID);
882 $post_ratings = geodir_get_rating_stars($post_avgratings, $post->ID);
883 ob_start();
884 geodir_comments_number($post->rating_count);
885 $n_comments = ob_get_contents();
886 ob_end_clean();
887 do_action('uwp_before_profile_favourite_item', $post_id, $user, $post_type);
888 ?>
889 <li class="uwp-profile-item-li uwp-profile-item-clearfix">
890 <a class="uwp-profile-item-img" href="<?php echo get_the_permalink(); ?>">
891 <?php
892 if (has_post_thumbnail()) {
893 $thumb_url = get_the_post_thumbnail_url(get_the_ID(), array(80, 80));
894 } else {
895 $thumb_url = $thumb_url = plugins_url() . "/userswp/public/assets/images/no_thumb.png";
896 }
897 ?>
898 <img class="uwp-profile-item-alignleft uwp-profile-item-thumb" src="<?php echo $thumb_url; ?>">
899 </a>
900
901 <?php do_action('uwp_before_profile_favourite_title', $post_id, $user, $post_type); ?>
902 <h3 class="uwp-profile-item-title">
903 <a href="<?php echo get_the_permalink(); ?>"><?php echo get_the_title(); ?></a>
904 </h3>
905 <?php do_action('uwp_after_profile_favourite_title', $post_id, $user, $post_type); ?>
906
907 <div class="uwp-time-ratings-wrap">
908 <?php do_action('uwp_before_profile_favourite_ratings', $post_id, $user, $post_type); ?>
909 <time class="uwp-profile-item-time published" datetime="<?php echo get_the_time('c'); ?>">
910 <?php echo get_the_date(); ?>
911 </time>
912 <?php echo '<div class="uwp-ratings">' . $post_ratings . ' <a href="' . get_comments_link() . '" class="uwp-num-comments">' . $n_comments . '</a></div>'; ?>
913 <?php
914 if (!is_user_logged_in()) {
915 do_action( 'geodir_after_favorite_html', $post->ID, 'listing' );
916 }
917 ?>
918 <?php do_action('uwp_after_profile_favourite_ratings', $post_id, $user, $post_type); ?>
919 </div>
920 <div class="uwp-item-actions">
921 <?php
922 if (is_user_logged_in()) {
923 do_action( 'geodir_after_favorite_html', $post->ID, 'listing' );
924 }
925 if ($post->post_author == get_current_user_id()) {
926 $addplacelink = get_permalink(geodir_add_listing_page_id());
927 $editlink = geodir_getlink($addplacelink, array('pid' => $post->ID), false);
928
929 $ajaxlink = geodir_get_ajax_url();
930 $deletelink = geodir_getlink($ajaxlink, array('geodir_ajax' => 'add_listing', 'ajax_action' => 'delete', 'pid' => $post->ID), false);
931 ?>
932
933 <span class="geodir-authorlink clearfix">
934
935 <?php do_action('geodir_before_edit_post_link_on_listing', $post_id, $user, $post_type); ?>
936
937 <a href="<?php echo esc_url($editlink); ?>" class="geodir-edit"
938 title="<?php _e('Edit Listing', 'userswp'); ?>">
939 <?php
940 $geodir_listing_edit_icon = apply_filters('geodir_listing_edit_icon', 'fa fa-edit');
941 echo '<i class="' . $geodir_listing_edit_icon . '"></i>';
942 ?>
943 <?php _e('Edit', 'userswp'); ?>
944 </a>
945 <a href="<?php echo esc_url($deletelink); ?>" class="geodir-delete"
946 title="<?php _e('Delete Listing', 'userswp'); ?>">
947 <?php
948 $geodir_listing_delete_icon = apply_filters('geodir_listing_delete_icon', 'fa fa-close');
949 echo '<i class="' . $geodir_listing_delete_icon . '"></i>';
950 ?>
951 <?php _e('Delete', 'userswp'); ?>
952 </a>
953
954 <?php do_action('geodir_after_edit_post_link_on_listing', $post_id, $user, $post_type); ?>
955
956 </span>
957
958 <?php } ?>
959 </div>
960 <div class="uwp-profile-item-summary">
961 <?php
962 do_action('uwp_before_profile_favourite_summary', $post_id, $user, $post_type);
963 $excerpt = strip_shortcodes(wp_trim_words(get_the_excerpt(), 15, '...'));
964 echo $excerpt;
965 if ($excerpt) {
966 ?>
967 <a href="<?php echo get_the_permalink(); ?>" class="more-link"><?php echo __( 'Read More »', 'userswp' ); ?></a>
968 <?php
969 }
970 do_action('uwp_after_profile_favourite_summary', $post_id, $user, $post_type);
971 ?>
972 </div>
973 </li>
974 <?php
975 do_action('uwp_after_profile_favourite_item', $post_id, $user, $post_type);
976 }
977 echo '</ul>';
978 /* Restore original Post Data */
979 wp_reset_postdata();
980 } else {
981 echo sprintf( __( "No %s found", 'userswp' ), $gd_post_types[$post_type]['labels']['name']);
982 }
983
984 do_action('uwp_after_profile_favourite_items', $user, $post_type);
985
986 do_action('uwp_profile_pagination', $the_query->max_num_pages);
987 } else {
988 echo sprintf( __( "No %s found", 'userswp' ), $gd_post_types[$post_type]['labels']['name']);
989 }
990 ?>
991 </div>
992 <?php
993 }
994
995 public function get_gd_login_url($url, $args) {
996 $register_page = uwp_get_page_id('register_page', false);
997 $login_page = uwp_get_page_id('login_page', false);
998 $forgot_page = uwp_get_page_id('forgot_page', false);
999 $reset_page = uwp_get_page_id('reset_page', false);
1000
1001 if (!empty($args)) {
1002 if (isset($args['signup']) && $args['signup']) {
1003 $page_id = $register_page;
1004 } elseif (isset($args['forgot']) && $args['forgot']) {
1005 $page_id = $forgot_page;
1006 } elseif (isset($args['reset']) && $args['reset']) {
1007 $page_id = $reset_page;
1008 } else {
1009 $page_id = $login_page;
1010 }
1011 } else {
1012 $page_id = $login_page;
1013 }
1014 if ($page_id) {
1015 $uwp_url = get_permalink($page_id);
1016
1017 if (strpos($url, 'redirect_add_listing') !== false) {
1018 $parsed = wp_parse_url($url);
1019 parse_str($parsed['query'], $query);
1020 $uwp_url = add_query_arg( array(
1021 'redirect_to' => $query['redirect_add_listing'],
1022 ), $uwp_url );
1023 }
1024
1025 if(isset($args['redirect_to']) && !empty($args['redirect_to'])){
1026 $uwp_url = add_query_arg( array(
1027 'redirect_to' => $args['redirect_to'],
1028 ), $uwp_url );
1029 }
1030
1031 $url = $uwp_url;
1032 }
1033 return $url;
1034 }
1035
1036 public function geodir_uwp_author_redirect() {
1037 if ( ! empty( $_REQUEST['geodir_dashbord'] ) ) {
1038 $author = get_query_var( 'author_name' ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) );
1039
1040 if ( !empty( $author ) && ! empty( $author->ID ) ) {
1041 $favourite = isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite' ? true : false;
1042 $post_type = isset( $_REQUEST['stype'] ) ? sanitize_text_field( $_REQUEST['stype'] ) : NULL;
1043
1044 $author_id = $author->ID;
1045 $author_link = uwp_build_profile_tab_url( $author_id );
1046 $gd_post_types = geodir_get_posttypes( 'array' );
1047
1048 if ( !empty( $gd_post_types ) && array_key_exists( $post_type, $gd_post_types ) ) {
1049 if ( $favourite ) {
1050 $profile_favorites = uwp_get_option( 'gd_profile_favorites', array() );
1051
1052 if ( uwp_get_option( 'geodir_uwp_link_favorite', '0' ) && ! empty( $profile_favorites ) && in_array( $post_type, $profile_favorites ) ) {
1053 $author_link = uwp_build_profile_tab_url( $author_id, 'favorites', $gd_post_types[ $post_type ]['has_archive'] );
1054 } else {
1055 return; // Do not redirect to dashboard CPT favorites.
1056 }
1057 } else {
1058 $profile_listings = uwp_get_option( 'gd_profile_listings', array() );
1059
1060 if ( uwp_get_option( 'geodir_uwp_link_listing', '0' ) && ! empty( $profile_listings ) && in_array( $post_type, $profile_listings ) ) {
1061 $author_link = uwp_build_profile_tab_url( $author_id, 'listings', $gd_post_types[ $post_type ]['has_archive'] );
1062 } else {
1063 return; // Do not redirect to dashboard CPT listings.
1064 }
1065 }
1066 }
1067
1068 wp_redirect($author_link);
1069 exit;
1070 }
1071 }
1072 return;
1073 }
1074
1075 public function gd_is_listings_tab() {
1076 global $wp_query;
1077 if (is_page() && class_exists('UsersWP')) {
1078 $profile_page = uwp_get_page_id('profile_page', false);
1079 if ($profile_page) {
1080 if (isset($wp_query->query_vars['uwp_profile'])
1081 && isset($wp_query->query_vars['uwp_tab'])
1082 && ($wp_query->query_vars['uwp_tab'] == 'listings' || $wp_query->query_vars['uwp_tab'] == 'favorites')
1083 ) {
1084
1085 return true;
1086
1087 }
1088 }
1089 }
1090 return false;
1091 }
1092
1093 public function geodir_post_status_is_author_page($value) {
1094 return $value || $this->gd_is_listings_tab();
1095 }
1096
1097 public function geodir_add_post_status_author_page() {
1098 global $wpdb, $post;
1099
1100 $html = '';
1101 if (get_current_user_id()) {
1102 if ($this->gd_is_listings_tab() && !empty($post) && isset($post->post_author) && $post->post_author == get_current_user_id()) {
1103
1104 // we need to query real status direct as we dynamically change the status for author on author page so even non author status can view them.
1105 $real_status = $wpdb->get_var("SELECT post_status from $wpdb->posts WHERE ID=$post->ID");
1106 $status = "<strong>(";
1107 $status_icon = '<i class="fa fa-play"></i>';
1108 if ($real_status == 'publish') {
1109 $status .= __('Published', 'userswp');
1110 } else {
1111 $status .= __('Not published', 'userswp');
1112 $status_icon = '<i class="fa fa-pause"></i>';
1113 }
1114 $status .= ")</strong>";
1115
1116 $html = '<span class="geodir-post-status">' . $status_icon . ' <font class="geodir-status-label">' . __('Status: ', 'userswp') . '</font>' . $status . '</span>';
1117 }
1118 }
1119
1120 if ($html != '') {
1121 echo apply_filters('geodir_filter_status_text_on_author_page', $html);
1122 }
1123 }
1124
1125 public function profile_gd_invoices_content($user) {
1126 if (!is_user_logged_in()) {
1127 return;
1128 }
1129
1130 if (get_current_user_id() != $user->ID) {
1131 return;
1132 }
1133 ?>
1134 <h3><?php echo __('Invoices', 'userswp'); ?></h3>
1135
1136 <div class="uwp-profile-item-block">
1137 <?php
1138 $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
1139
1140 $args = array(
1141 'post_type' => 'wpi_invoice',
1142 'post_status' => array_keys(wpinv_get_invoice_statuses()),
1143 'posts_per_page' => uwp_get_option('profile_no_of_items', 10),
1144 'author' => $user->ID,
1145 'paged' => $paged,
1146 );
1147 // The Query
1148 $the_query = new WP_Query($args);
1149
1150 // The Loop
1151 if ($the_query->have_posts()) {
1152 echo '<ul class="uwp-profile-item-ul">';
1153 while ($the_query->have_posts()) {
1154 $the_query->the_post();
1155 $wpi_invoice = new WPInv_Invoice( get_the_ID() );
1156 ?>
1157 <li class="uwp-profile-item-li uwp-profile-item-clearfix">
1158 <h3 class="uwp-profile-item-title">
1159 <a href="<?php echo get_the_permalink(); ?>"><?php _e('Invoice','userswp');?> <?php echo get_the_title(); ?></a>
1160 </h3>
1161 <time class="uwp-profile-item-time published" datetime="<?php echo get_the_time('c'); ?>">
1162 <?php echo get_the_date(); ?>
1163 </time>
1164 <div class="uwp-profile-item-summary">
1165 <div class="uwp-order-status">
1166 <?php
1167 echo __('Invoice Status: ', 'userswp').$wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' );
1168 ?>
1169 </div>
1170 <div class="uwp-order-total">
1171 <?php
1172 echo __('Invoice Total: ', 'userswp'). $wpi_invoice->get_total( true );
1173 ?>
1174 </div
1175 </div>
1176 </li>
1177 <?php
1178 }
1179 echo '</ul>';
1180 /* Restore original Post Data */
1181 wp_reset_postdata();
1182 } else {
1183 // no posts found
1184 echo "<p>".__('No Invoices Found', 'userswp')."</p>";
1185 }
1186 do_action('uwp_profile_pagination', $the_query->max_num_pages);
1187 ?>
1188 </div>
1189 <?php
1190 }
1191
1192 public function invoice_count($user_id) {
1193 global $wpdb;
1194
1195 $post_status_array = array_keys(wpinv_get_invoice_statuses());
1196 $post_status = "'" . implode("','", $post_status_array) . "'";
1197
1198 $count = $wpdb->get_var('
1199 SELECT COUNT(ID)
1200 FROM ' . $wpdb->posts. '
1201 WHERE post_author = "' . $user_id . '"
1202 AND post_status IN ('.$post_status.')
1203 AND post_type = "wpi_invoice"'
1204 );
1205 return $count;
1206 }
1207
1208 public function gd_login_wid_login_placeholder() {
1209 return __( 'Username', 'userswp' );
1210 }
1211
1212 public function gd_login_wid_login_name() {
1213 return "uwp_login_username";
1214 }
1215
1216 public function gd_login_wid_login_pwd() {
1217 return "uwp_login_password";
1218 }
1219
1220 public function gd_login_inject_nonce() {
1221 ?>
1222 <input type="hidden" name="uwp_login_nonce" value="<?php echo wp_create_nonce( 'uwp-login-nonce' ); ?>" />
1223 <?php
1224 }
1225
1226 public function check_redirect_author_page( $redirect = false ) {
1227 if ( $redirect && ! empty( $_REQUEST['geodir_dashbord'] ) ) {
1228 $author = get_query_var( 'author_name' ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) );
1229
1230 if ( !empty( $author ) && ! empty( $author->ID ) ) {
1231 $favourite = isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite' ? true : false;
1232 $post_type = isset( $_REQUEST['stype'] ) ? sanitize_text_field( $_REQUEST['stype'] ) : NULL;
1233
1234 $author_id = $author->ID;
1235 $author_link = uwp_build_profile_tab_url( $author_id );
1236 $gd_post_types = geodir_get_posttypes( 'array' );
1237
1238 if ( !empty( $gd_post_types ) && array_key_exists( $post_type, $gd_post_types ) ) {
1239 if ( $favourite ) {
1240 $profile_favorites = uwp_get_option( 'gd_profile_favorites', array() );
1241
1242 if ( uwp_get_option( 'geodir_uwp_link_favorite', '0' ) && ! empty( $profile_favorites ) && in_array( $post_type, $profile_favorites ) ) {
1243 // Redirect to dashboard CPT favorites.
1244 } else {
1245 $redirect = false; // Do not redirect to dashboard CPT favorites.
1246 }
1247 } else {
1248 $profile_listings = uwp_get_option( 'gd_profile_listings', array() );
1249
1250 if ( uwp_get_option( 'geodir_uwp_link_listing', '0' ) && ! empty( $profile_listings ) && in_array( $post_type, $profile_listings ) ) {
1251 // Redirect to dashboard CPT listings.
1252 } else {
1253 $redirect =false; // Do not redirect to dashboard CPT listings.
1254 }
1255 }
1256 }
1257 }
1258 }
1259
1260 return $redirect;
1261 }
1262
1263 public function skip_uwp_author_page( $uwp_author = true ) {
1264 if ( geodir_is_page( 'author' ) ) {
1265 $uwp_author = false;
1266 }
1267
1268 return $uwp_author;
1269 }
1270 }
1271 $userswp_geodirectory = UsersWP_GeoDirectory_Plugin::get_instance();