| 1 |
<?php |
| 2 |
/** |
| 3 |
* Shortcode related functions |
| 4 |
* |
| 5 |
* This class defines all code necessary for UsersWP shortcodes. |
| 6 |
* |
| 7 |
* @since 1.0.0 |
| 8 |
* @author GeoDirectory Team <info@wpgeodirectory.com> |
| 9 |
*/ |
| 10 |
class UsersWP_Shortcodes { |
| 11 |
|
| 12 |
private $templates; |
| 13 |
|
| 14 |
public function __construct($templates) { |
| 15 |
$this->templates = $templates; |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Returns the UsersWP register page template content. |
| 20 |
* |
| 21 |
* @since 1.0.0 |
| 22 |
* @package userswp |
| 23 |
* @return string UsersWP template content. |
| 24 |
*/ |
| 25 |
public function register($atts) { |
| 26 |
if (is_user_logged_in()) { |
| 27 |
return ""; |
| 28 |
} |
| 29 |
$args = shortcode_atts( |
| 30 |
array( |
| 31 |
'role_id' => '0', |
| 32 |
), |
| 33 |
$atts |
| 34 |
); |
| 35 |
global $uwp_register_role_id; |
| 36 |
$uwp_register_role_id = (int) $args['role_id']; |
| 37 |
return $this->uwp_generate_shortcode('register'); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Returns the UsersWP login page template content. |
| 42 |
* |
| 43 |
* @since 1.0.0 |
| 44 |
* @package userswp |
| 45 |
* @return string UsersWP template content. |
| 46 |
*/ |
| 47 |
public function login() { |
| 48 |
if (is_user_logged_in()) { |
| 49 |
return ""; |
| 50 |
} |
| 51 |
return $this->uwp_generate_shortcode('login'); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Returns the UsersWP forgot password page template content. |
| 56 |
* |
| 57 |
* @since 1.0.0 |
| 58 |
* @package userswp |
| 59 |
* @return string UsersWP template content. |
| 60 |
*/ |
| 61 |
public function forgot() { |
| 62 |
return $this->uwp_generate_shortcode('forgot'); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Returns the UsersWP change password page template content. |
| 67 |
* |
| 68 |
* @since 1.0.0 |
| 69 |
* @package userswp |
| 70 |
* @return string UsersWP template content. |
| 71 |
*/ |
| 72 |
public function change() { |
| 73 |
return $this->uwp_generate_shortcode('change'); |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Returns the UsersWP reset password page template content. |
| 78 |
* |
| 79 |
* @since 1.0.0 |
| 80 |
* @package userswp |
| 81 |
* @return string UsersWP template content. |
| 82 |
*/ |
| 83 |
public function reset() { |
| 84 |
return $this->uwp_generate_shortcode('reset'); |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Returns the UsersWP account page template content. |
| 89 |
* |
| 90 |
* @since 1.0.0 |
| 91 |
* @package userswp |
| 92 |
* @return string UsersWP template content. |
| 93 |
*/ |
| 94 |
public function account() { |
| 95 |
return $this->uwp_generate_shortcode('account'); |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Returns the UsersWP profile page template content. |
| 100 |
* |
| 101 |
* @since 1.0.0 |
| 102 |
* @package userswp |
| 103 |
* @return string UsersWP template content. |
| 104 |
*/ |
| 105 |
public function profile() { |
| 106 |
return $this->uwp_generate_shortcode('profile'); |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Returns the UsersWP users page template content. |
| 111 |
* |
| 112 |
* @since 1.0.0 |
| 113 |
* @package userswp |
| 114 |
* @return string UsersWP template content. |
| 115 |
*/ |
| 116 |
public function users() { |
| 117 |
return $this->uwp_generate_shortcode('users'); |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Returns the UsersWP template content based on type. |
| 122 |
* |
| 123 |
* @since 1.0.0 |
| 124 |
* @package userswp |
| 125 |
* @param string $type Template type. |
| 126 |
* @return string UsersWP template content. |
| 127 |
*/ |
| 128 |
public function uwp_generate_shortcode($type = 'register') { |
| 129 |
|
| 130 |
$template = $this->templates->uwp_locate_template($type); |
| 131 |
|
| 132 |
ob_start(); |
| 133 |
if ($template) { |
| 134 |
include($template); |
| 135 |
} |
| 136 |
$output = ob_get_contents(); |
| 137 |
ob_end_clean(); |
| 138 |
|
| 139 |
return trim($output); |
| 140 |
} |
| 141 |
|
| 142 |
} |