| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | /** |
| 3 | 4 | * Template related functions |
| 4 | 5 | * |
| 5 | 6 | * This class defines all code necessary for UsersWP templates like login. register etc. |
| @@ -7,793 +8,1388 @@ | ||
| 7 | 8 | * @since 1.0.0 |
| 8 | 9 | * @author GeoDirectory Team <info@wpgeodirectory.com> |
| 9 | 10 | */ |
| 10 | 11 | class UsersWP_Templates { |
| 11 | - | |
| 12 | - /** | |
| 13 | - * Locates UsersWP templates based on template type. | |
| 14 | - * | |
| 15 | - * @since 1.0.0 | |
| 16 | - * @package userswp | |
| 17 | - * @param string $template Template type. | |
| 18 | - * @return string The template filename if one is located. | |
| 19 | - */ | |
| 20 | - public function uwp_locate_template( $template ) { | |
| 21 | - | |
| 22 | - switch ($template) { | |
| 23 | - case 'register': | |
| 24 | - return $this->uwp_generic_locate_template('register'); | |
| 25 | - break; | |
| 26 | 12 | |
| 27 | - case 'login': | |
| 28 | - return $this->uwp_generic_locate_template('login'); | |
| 29 | - break; | |
| 13 | + /** | |
| 14 | + * The function is use for Retrieve the name of the highest | |
| 15 | + * priority template file that exists. | |
| 16 | + * | |
| 17 | + * @param string $template_name Template files to search for, in order. | |
| 18 | + * @param string $template_path Optional. Template path. Default null. | |
| 19 | + * @param string $default_path Optional. Default path. Default null. | |
| 20 | + * | |
| 21 | + * @return string Template path. | |
| 22 | + */ | |
| 23 | + public static function locate_template( $template_name, $template_path = '', $default_path = '' ) { | |
| 30 | 24 | |
| 31 | - case 'forgot': | |
| 32 | - return $this->uwp_generic_locate_template('forgot'); | |
| 33 | - break; | |
| 25 | + if ( ! $template_path ) { | |
| 26 | + $template_path = uwp_get_theme_template_dir_name(); | |
| 27 | + } | |
| 34 | 28 | |
| 35 | - case 'change': | |
| 36 | - return $this->uwp_generic_locate_template('change'); | |
| 37 | - break; | |
| 29 | + if ( ! $default_path ) { | |
| 30 | + $default_path = uwp_get_templates_dir(); | |
| 31 | + } | |
| 38 | 32 | |
| 39 | - case 'reset': | |
| 40 | - return $this->uwp_generic_locate_template('reset'); | |
| 41 | - break; | |
| 33 | + // Look within passed path within the theme - this is priority. | |
| 34 | + $template = locate_template( | |
| 35 | + array( | |
| 36 | + untrailingslashit( $template_path ) . '/' . $template_name, | |
| 37 | + $template_name, | |
| 38 | + ) | |
| 39 | + ); | |
| 42 | 40 | |
| 43 | - case 'account': | |
| 44 | - return $this->uwp_generic_locate_template('account'); | |
| 45 | - break; | |
| 41 | + // Get default template | |
| 42 | + if ( ! $template ) { | |
| 43 | + $template = untrailingslashit( $default_path ) . '/' . $template_name; | |
| 44 | + } | |
| 46 | 45 | |
| 47 | - case 'profile': | |
| 48 | - return $this->uwp_generic_locate_template('profile'); | |
| 49 | - break; | |
| 46 | + // Return what we found. | |
| 47 | + return apply_filters( 'uwp_locate_template', $template, $template_name, $template_path ); | |
| 48 | + } | |
| 50 | 49 | |
| 51 | - case 'users': | |
| 52 | - return $this->uwp_generic_locate_template('users'); | |
| 53 | - break; | |
| 54 | - | |
| 55 | - case 'dashboard': | |
| 56 | - return $this->uwp_generic_locate_template('dashboard'); | |
| 57 | - break; | |
| 58 | - } | |
| 50 | + /** | |
| 51 | + * | |
| 52 | + * Displays default content for UWP pages | |
| 53 | + * | |
| 54 | + * @param $content | |
| 55 | + * | |
| 56 | + * @return string | |
| 57 | + */ | |
| 58 | + public static function setup_singular_page_content( $content ) { | |
| 59 | + global $post, $wp_query; | |
| 59 | 60 | |
| 60 | - return apply_filters('uwp_locate_template', false, $template); | |
| 61 | - } | |
| 61 | + if ( ! is_uwp_page() ) { | |
| 62 | + return $content; | |
| 63 | + } | |
| 62 | 64 | |
| 63 | - /** | |
| 64 | - * Locates UsersWP templates based on template type. | |
| 65 | - * Fallback to core templates when no custom templates found. | |
| 66 | - * | |
| 67 | - * @since 1.0.0 | |
| 68 | - * @package userswp | |
| 69 | - * @param string $type Template type. | |
| 70 | - * @return string The template filename if one is located. | |
| 71 | - */ | |
| 72 | - public function uwp_generic_locate_template($type = 'register') { | |
| 73 | - | |
| 74 | - $plugin_path = dirname( dirname( __FILE__ ) ); | |
| 75 | - | |
| 76 | - $template = locate_template(array("userswp/".$type.".php")); | |
| 77 | - if (!$template) { | |
| 78 | - $template = $plugin_path . '/templates/'.$type.'.php'; | |
| 79 | - } | |
| 80 | - $template = apply_filters('uwp_template_'.$type, $template); | |
| 81 | - return $template; | |
| 82 | - } | |
| 65 | + if ( ! ( ! empty( $wp_query ) && ! empty( $post ) && ( $post->ID == get_queried_object_id() ) ) ) { | |
| 66 | + return $content; | |
| 67 | + } | |
| 83 | 68 | |
| 84 | - /** | |
| 85 | - * Doing some access checks for UsersWP related pages. | |
| 86 | - * | |
| 87 | - * @since 1.0.0 | |
| 88 | - * @package userswp | |
| 89 | - * @return bool | |
| 90 | - */ | |
| 91 | - public function access_checks() { | |
| 92 | - global $post; | |
| 69 | + /* | |
| 70 | + * Some page builders need to be able to take control here so we add a filter to bypass it on the fly | |
| 71 | + */ | |
| 72 | + if ( apply_filters( 'uwp_bypass_setup_singular_page', false ) ) { | |
| 73 | + return $content; | |
| 74 | + } | |
| 93 | 75 | |
| 94 | - if (!is_page()) { | |
| 95 | - return false; | |
| 96 | - } | |
| 76 | + remove_filter( 'the_content', array( __CLASS__, 'setup_singular_page_content' ) ); | |
| 97 | 77 | |
| 98 | - if(uwp_is_page_builder()){ | |
| 99 | - return false; | |
| 100 | - } | |
| 78 | + if ( in_the_loop() ) { | |
| 101 | 79 | |
| 102 | - $current_page_id = $post->ID; | |
| 103 | - | |
| 104 | - $register_page = uwp_get_page_id('register_page', false); | |
| 105 | - $login_page = uwp_get_page_id('login_page', false); | |
| 106 | - $forgot_page = uwp_get_page_id('forgot_page', false); | |
| 107 | - $reset_page = uwp_get_page_id('reset_page', false); | |
| 80 | + if ( $content == '' ) { | |
| 81 | + if ( is_uwp_profile_page() ) { | |
| 82 | + $content = '[uwp_profile]'; | |
| 83 | + } elseif ( is_uwp_register_page() ) { | |
| 84 | + $content = '[uwp_register]'; | |
| 85 | + } elseif ( is_uwp_login_page() ) { | |
| 86 | + $content = '[uwp_login]'; | |
| 87 | + } elseif ( is_uwp_forgot_page() ) { | |
| 88 | + $content = '[uwp_forgot]'; | |
| 89 | + } elseif ( is_uwp_change_page() ) { | |
| 90 | + $content = '[uwp_change]'; | |
| 91 | + } elseif ( is_uwp_reset_page() ) { | |
| 92 | + $content = '[uwp_reset]'; | |
| 93 | + } elseif ( is_uwp_account_page() ) { | |
| 94 | + $content = '[uwp_account]'; | |
| 95 | + } elseif ( is_uwp_users_page() ) { | |
| 96 | + $content = '[uwp_users]'; | |
| 97 | + } elseif ( is_uwp_users_item_page() ) { | |
| 98 | + $content = UsersWP_Defaults::page_user_list_item_content(); | |
| 99 | + } else { | |
| 100 | + // do nothing | |
| 101 | + } | |
| 108 | 102 | |
| 109 | - $change_page = uwp_get_page_id('change_page', false); | |
| 110 | - $account_page = uwp_get_page_id('account_page', false); | |
| 111 | - | |
| 112 | - if (( $register_page && ((int) $register_page == $current_page_id )) || | |
| 113 | - ( $login_page && ((int) $login_page == $current_page_id ) ) || | |
| 114 | - ( $forgot_page && ((int) $forgot_page == $current_page_id ) ) || | |
| 115 | - ( $reset_page && ((int) $reset_page == $current_page_id ) )) { | |
| 116 | - if (is_user_logged_in()) { | |
| 117 | - $redirect_page_id = uwp_get_page_id('account_page', false); | |
| 118 | - if (empty($redirect_page_id)) { | |
| 119 | - $redirect_to = home_url('/'); | |
| 120 | - } else { | |
| 121 | - $redirect_to = get_permalink($redirect_page_id); | |
| 103 | + // run the shortcodes on the content | |
| 104 | + $content = do_shortcode( $content ); | |
| 105 | + | |
| 106 | + // run block content if its available | |
| 107 | + if ( function_exists( 'do_blocks' ) ) { | |
| 108 | + $content = do_blocks( $content ); | |
| 109 | + } | |
| 110 | + } | |
| 111 | + | |
| 112 | + } | |
| 113 | + | |
| 114 | + // add our filter back | |
| 115 | + add_filter( 'the_content', array( __CLASS__, 'setup_singular_page_content' ) ); | |
| 116 | + | |
| 117 | + | |
| 118 | + return $content; | |
| 119 | + } | |
| 120 | + | |
| 121 | + /** | |
| 122 | + * | |
| 123 | + * Returns content for the users list item template | |
| 124 | + * | |
| 125 | + * @return string | |
| 126 | + */ | |
| 127 | + public static function users_list_item_template_content() { | |
| 128 | + | |
| 129 | + $item_page_id = uwp_get_option( 'user_list_item_page', 0 ); | |
| 130 | + $content = get_post_field( 'post_content', $item_page_id ); | |
| 131 | + | |
| 132 | + /* | |
| 133 | + * Some page builders need to be able to take control here so we add a filter to bypass it on the fly | |
| 134 | + */ | |
| 135 | + $bypass_content = apply_filters( 'uwp_bypass_users_list_item_template_content', '', $content, $item_page_id ); | |
| 136 | + if ( $bypass_content ) { | |
| 137 | + return $bypass_content; | |
| 138 | + } | |
| 139 | + | |
| 140 | + // if the content is blank then we grab the page defaults | |
| 141 | + if ( $content == '' ) { | |
| 142 | + $content = UsersWP_Defaults::page_user_list_item_content(); | |
| 143 | + } | |
| 144 | + | |
| 145 | + // run the shortcodes on the content | |
| 146 | + $content = do_shortcode( $content ); | |
| 147 | + | |
| 148 | + // run block content if its available | |
| 149 | + if ( function_exists( 'do_blocks' ) ) { | |
| 150 | + $content = do_blocks( $content ); | |
| 151 | + } | |
| 152 | + | |
| 153 | + | |
| 154 | + return $content; | |
| 155 | + } | |
| 156 | + | |
| 157 | + /** | |
| 158 | + * Disable our sub templates access from frontend. | |
| 159 | + * | |
| 160 | + * @global object $post WordPress Post object. | |
| 161 | + * | |
| 162 | + * @since 1.2.1.2 | |
| 163 | + */ | |
| 164 | + public static function redirect_templates_sub_pages() { | |
| 165 | + global $post; | |
| 166 | + if ( isset( $post->ID ) && ! current_user_can( 'administrator' ) && ( | |
| 167 | + $post->ID == uwp_get_page_id( 'user_list_item_page' ) | |
| 168 | + ) ) { | |
| 169 | + wp_redirect( home_url(), 301 ); | |
| 170 | + exit; | |
| 171 | + } | |
| 172 | + } | |
| 173 | + | |
| 174 | + /** | |
| 175 | + * Doing some access checks for UsersWP related pages. | |
| 176 | + * | |
| 177 | + * @return bool | |
| 178 | + * @package userswp | |
| 179 | + * @since 1.0.0 | |
| 180 | + */ | |
| 181 | + public function access_checks() { | |
| 182 | + global $post; | |
| 183 | + | |
| 184 | + if ( ! is_page() ) { | |
| 185 | + return false; | |
| 186 | + } | |
| 187 | + | |
| 188 | + if ( uwp_is_page_builder() ) { | |
| 189 | + return false; | |
| 190 | + } | |
| 191 | + | |
| 192 | + $current_page_id = $post->ID; | |
| 193 | + | |
| 194 | + $register_page = uwp_get_page_id( 'register_page', false ); | |
| 195 | + $login_page = uwp_get_page_id( 'login_page', false ); | |
| 196 | + $forgot_page = uwp_get_page_id( 'forgot_page', false ); | |
| 197 | + $reset_page = uwp_get_page_id( 'reset_page', false ); | |
| 198 | + | |
| 199 | + $change_page = uwp_get_page_id( 'change_page', false ); | |
| 200 | + $account_page = uwp_get_page_id( 'account_page', false ); | |
| 201 | + | |
| 202 | + if ( ( $register_page && ( (int) $register_page == $current_page_id ) ) || | |
| 203 | + ( $login_page && ( (int) $login_page == $current_page_id ) ) || | |
| 204 | + ( $forgot_page && ( (int) $forgot_page == $current_page_id ) ) || | |
| 205 | + ( $reset_page && ( (int) $reset_page == $current_page_id ) ) ) { | |
| 206 | + if ( is_user_logged_in() ) { | |
| 207 | + $redirect_page_id = uwp_get_page_id( 'account_page', false ); | |
| 208 | + | |
| 209 | + if ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) { | |
| 210 | + $redirect_to = esc_url_raw( $_REQUEST['redirect_to'] ); | |
| 211 | + } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id > 0 ) { | |
| 212 | + $redirect_to = get_permalink( $redirect_page_id ); | |
| 213 | + } else { | |
| 214 | + $redirect_to = home_url( '/' ); | |
| 122 | 215 | } |
| 123 | - $redirect_to = apply_filters('uwp_logged_in_redirect', $redirect_to); | |
| 124 | - wp_redirect($redirect_to); | |
| 125 | - exit(); | |
| 126 | - } | |
| 127 | - } elseif ( $account_page && ((int) $account_page == $current_page_id ) || | |
| 128 | - ( $change_page && ((int) $change_page == $current_page_id ) )) { | |
| 129 | - if (!is_user_logged_in()) { | |
| 130 | - wp_redirect(get_permalink($login_page)); | |
| 131 | - exit(); | |
| 132 | - } else { | |
| 133 | - $can_user_can_edit_account = apply_filters('uwp_user_can_edit_own_profile', true, get_current_user_id()); | |
| 134 | - if (!$can_user_can_edit_account && ((int) $account_page == $current_page_id )) { | |
| 135 | - wp_redirect(home_url('/')); | |
| 136 | - exit(); | |
| 216 | + | |
| 217 | + $redirect_to = apply_filters( 'uwp_logged_in_redirect', $redirect_to ); | |
| 218 | + wp_safe_redirect( $redirect_to ); | |
| 219 | + exit(); | |
| 220 | + } | |
| 221 | + } elseif ( $account_page && ( (int) $account_page == $current_page_id ) || | |
| 222 | + ( $change_page && ( (int) $change_page == $current_page_id ) ) ) { | |
| 223 | + if ( ! is_user_logged_in() ) { | |
| 224 | + if ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) { | |
| 225 | + $redirect_to = esc_url( $_REQUEST['redirect_to'] ); | |
| 226 | + $login_page = add_query_arg( | |
| 227 | + array( | |
| 228 | + 'redirect_to' => $redirect_to, | |
| 229 | + ), | |
| 230 | + get_permalink($login_page) | |
| 231 | + ); | |
| 232 | + } else { | |
| 233 | + $login_page = get_permalink($login_page); | |
| 137 | 234 | } |
| 138 | - } | |
| 139 | - } else { | |
| 140 | - return false; | |
| 141 | - } | |
| 142 | - | |
| 143 | - return false; | |
| 144 | - } | |
| 145 | 235 | |
| 146 | - /** | |
| 147 | - * If auto generated password, redirects to change password page. | |
| 148 | - * | |
| 149 | - * @since 1.0.0 | |
| 150 | - * @package userswp | |
| 151 | - * @return void | |
| 152 | - */ | |
| 153 | - public function change_default_password_redirect() { | |
| 154 | - if (!is_user_logged_in()) { | |
| 155 | - return; | |
| 156 | - } | |
| 157 | - if(1 == uwp_get_option('change_disable_password_nag')) { | |
| 158 | - return; | |
| 159 | - } | |
| 236 | + wp_safe_redirect( $login_page ); | |
| 237 | + exit(); | |
| 238 | + } else { | |
| 239 | + $can_user_can_edit_account = apply_filters( 'uwp_user_can_edit_own_profile', true, get_current_user_id() ); | |
| 240 | + if ( ! $can_user_can_edit_account && ( (int) $account_page == $current_page_id ) ) { | |
| 241 | + wp_safe_redirect( home_url( '/' ) ); | |
| 242 | + exit(); | |
| 243 | + } | |
| 244 | + } | |
| 245 | + } else { | |
| 246 | + return false; | |
| 247 | + } | |
| 160 | 248 | |
| 161 | - if(uwp_is_page_builder()){ | |
| 162 | - return; | |
| 163 | - } | |
| 249 | + return false; | |
| 250 | + } | |
| 164 | 251 | |
| 165 | - $change_page = uwp_get_page_id('change_page', false); | |
| 166 | - $password_nag = get_user_option('default_password_nag', get_current_user_id()); | |
| 167 | - | |
| 168 | - if ($password_nag) { | |
| 169 | - if (is_page()) { | |
| 170 | - global $post; | |
| 171 | - $current_page_id = $post->ID; | |
| 172 | - if ( $change_page && ((int) $change_page == $current_page_id ) ) { | |
| 173 | - return; | |
| 174 | - } | |
| 175 | - } | |
| 176 | - if ($change_page) { | |
| 177 | - wp_redirect( get_permalink($change_page) ); | |
| 178 | - exit(); | |
| 179 | - } | |
| 180 | - } | |
| 181 | - } | |
| 252 | + /** | |
| 253 | + * If auto generated password, redirects to change password page. | |
| 254 | + * | |
| 255 | + * @return void | |
| 256 | + * @package userswp | |
| 257 | + * @since 1.0.0 | |
| 258 | + */ | |
| 259 | + public function change_default_password_redirect() { | |
| 260 | + if ( ! is_user_logged_in() ) { | |
| 261 | + return; | |
| 262 | + } | |
| 263 | + if ( 1 == uwp_get_option( 'change_disable_password_nag' ) ) { | |
| 264 | + return; | |
| 265 | + } | |
| 182 | 266 | |
| 183 | - /** | |
| 184 | - * Redirects /profile to /profile/{username} for loggedin users. | |
| 185 | - * | |
| 186 | - * @since 1.0.0 | |
| 187 | - * @package userswp | |
| 188 | - * @return void | |
| 189 | - */ | |
| 190 | - public function profile_redirect() { | |
| 191 | - if(uwp_is_page_builder()){ | |
| 192 | - return; | |
| 193 | - } | |
| 267 | + if ( uwp_is_page_builder() ) { | |
| 268 | + return; | |
| 269 | + } | |
| 194 | 270 | |
| 195 | - if (is_page()) { | |
| 196 | - global $wp_query, $post; | |
| 197 | - $current_page_id = $post->ID; | |
| 198 | - $profile_page = uwp_get_page_id('profile_page', false); | |
| 199 | - if ( $profile_page && ((int) $profile_page == $current_page_id ) ) { | |
| 271 | + $change_page = uwp_get_page_id( 'change_page', false ); | |
| 272 | + $password_nag = get_user_option( 'default_password_nag', get_current_user_id() ); | |
| 200 | 273 | |
| 201 | - if (isset($wp_query->query_vars['uwp_profile'])) { | |
| 202 | - //must be profile page | |
| 203 | - $url_type = apply_filters('uwp_profile_url_type', 'slug'); | |
| 204 | - $author_slug = $wp_query->query_vars['uwp_profile']; | |
| 205 | - if ($url_type == 'id') { | |
| 206 | - $user = get_user_by('id', $author_slug); | |
| 207 | - } else { | |
| 208 | - $user = get_user_by('slug', $author_slug); | |
| 209 | - } | |
| 274 | + if ( $password_nag ) { | |
| 275 | + if ( is_page() ) { | |
| 276 | + global $post; | |
| 277 | + $current_page_id = $post->ID; | |
| 278 | + if ( $change_page && ( (int) $change_page == $current_page_id ) ) { | |
| 279 | + return; | |
| 280 | + } | |
| 281 | + } | |
| 282 | + if ( $change_page ) { | |
| 283 | + wp_safe_redirect( get_permalink( $change_page ) ); | |
| 284 | + exit(); | |
| 285 | + } | |
| 286 | + } | |
| 287 | + } | |
| 210 | 288 | |
| 211 | - if (!isset($user->ID)) { | |
| 212 | - global $wp_query; | |
| 213 | - $wp_query->set_404(); | |
| 214 | - status_header( 404 ); | |
| 215 | - get_template_part( 404 ); exit(); | |
| 216 | - } | |
| 289 | + /** | |
| 290 | + * Redirects /profile to /profile/{username} for loggedin users. | |
| 291 | + * | |
| 292 | + * @return void | |
| 293 | + * @package userswp | |
| 294 | + * @since 1.0.0 | |
| 295 | + */ | |
| 296 | + public function profile_redirect() { | |
| 297 | + if ( uwp_is_page_builder() ) { | |
| 298 | + return; | |
| 299 | + } | |
| 217 | 300 | |
| 218 | - } else { | |
| 219 | - if (is_user_logged_in()) { | |
| 220 | - $user_id = get_current_user_id(); | |
| 221 | - $profile_url = uwp_build_profile_tab_url($user_id); | |
| 222 | - wp_redirect( $profile_url ); | |
| 223 | - exit(); | |
| 224 | - } else { | |
| 225 | - wp_redirect( home_url('/') ); | |
| 226 | - exit(); | |
| 227 | - } | |
| 301 | + if ( is_page() ) { | |
| 302 | + global $wp_query, $post; | |
| 303 | + $current_page_id = $post->ID; | |
| 304 | + $profile_page = uwp_get_page_id( 'profile_page', false ); | |
| 305 | + if ( $profile_page && ( (int) $profile_page == $current_page_id ) ) { | |
| 228 | 306 | |
| 229 | - } | |
| 307 | + if ( isset( $wp_query->query_vars['uwp_profile'] ) ) { | |
| 308 | + //must be profile page | |
| 309 | + $url_type = apply_filters( 'uwp_profile_url_type', 'slug' ); | |
| 310 | + $author_slug = $wp_query->query_vars['uwp_profile']; | |
| 311 | + if ( $url_type == 'id' ) { | |
| 312 | + $user = get_user_by( 'id', $author_slug ); | |
| 313 | + } else { | |
| 314 | + $user = get_user_by( 'slug', $author_slug ); | |
| 315 | + } | |
| 230 | 316 | |
| 231 | - } | |
| 232 | - } | |
| 233 | - } | |
| 317 | + if ( ! isset( $user->ID ) ) { | |
| 318 | + global $wp_query; | |
| 319 | + $wp_query->set_404(); | |
| 320 | + status_header( 404 ); | |
| 321 | + } | |
| 234 | 322 | |
| 235 | - /** | |
| 236 | - * Redirects user to a predefined page after logging out. | |
| 237 | - * | |
| 238 | - * @since 1.0.0 | |
| 239 | - * @package userswp | |
| 240 | - * @return void | |
| 241 | - */ | |
| 242 | - public function logout_redirect() { | |
| 243 | - $redirect_page_id = uwp_get_option('logout_redirect_to', ''); | |
| 244 | - if(isset( $_REQUEST['redirect_to'] )){ | |
| 245 | - $redirect_to = esc_url($_REQUEST['redirect_to']); | |
| 246 | - } elseif ( isset($redirect_page_id) && (int)$redirect_page_id > 0) { | |
| 247 | - $redirect_to = get_permalink($redirect_page_id); | |
| 248 | - } else { | |
| 249 | - $redirect_to = home_url('/'); | |
| 250 | - } | |
| 251 | - $redirect_to = apply_filters('uwp_logout_redirect', $redirect_to); | |
| 252 | - wp_redirect( $redirect_to ); | |
| 253 | - exit(); | |
| 254 | - } | |
| 323 | + } else { | |
| 324 | + if ( is_user_logged_in() ) { | |
| 325 | + $user_id = get_current_user_id(); | |
| 326 | + $obj = new UsersWP_Profile(); | |
| 327 | + $profile_url = $obj->get_profile_link( get_author_posts_url( $user_id ), $user_id ); | |
| 328 | + wp_safe_redirect( $profile_url ); | |
| 329 | + exit(); | |
| 330 | + } else { | |
| 331 | + $redirect_to = apply_filters( 'uwp_no_login_profile_redirect', uwp_get_page_link('login') ); | |
| 332 | + $redirect_to = add_query_arg('redirect_to', urlencode(get_permalink($profile_page)), $redirect_to); | |
| 333 | + wp_safe_redirect( $redirect_to ); | |
| 334 | + exit(); | |
| 335 | + } | |
| 255 | 336 | |
| 337 | + } | |
| 256 | 338 | |
| 257 | - /** | |
| 258 | - * Redirects wp-login.php to UsersWP login page. | |
| 259 | - * | |
| 260 | - * @since 1.0.0 | |
| 261 | - * @package userswp | |
| 262 | - * @return void | |
| 263 | - */ | |
| 264 | - public function wp_login_redirect() { | |
| 265 | - $login_page_id = uwp_get_page_id('login_page', false); | |
| 266 | - $block_wp_login = uwp_get_option('block_wp_login', ''); | |
| 267 | - if ($login_page_id && $block_wp_login == '1') { | |
| 268 | - global $pagenow; | |
| 269 | - if( 'wp-login.php' == $pagenow && !isset($_REQUEST['action']) ) { | |
| 270 | - $redirect_to = get_permalink($login_page_id); | |
| 271 | - wp_redirect( $redirect_to ); | |
| 272 | - exit(); | |
| 273 | - } | |
| 274 | - } | |
| 275 | - } | |
| 339 | + } | |
| 340 | + } | |
| 341 | + } | |
| 276 | 342 | |
| 277 | - /** | |
| 278 | - * Changes the login url to the UWP login page. | |
| 279 | - * | |
| 280 | - * @param $login_url string The URL for login. | |
| 281 | - * @param $redirect string The URL to redirect back to upon successful login. | |
| 282 | - * @param $force_reauth bool Whether to force reauthorization, even if a cookie is present. | |
| 283 | - * @since 1.0.12 | |
| 284 | - * @package userswp | |
| 285 | - * | |
| 286 | - * @return string The login url. | |
| 287 | - */ | |
| 288 | - public function wp_login_url($login_url, $redirect, $force_reauth) { | |
| 289 | - $login_page_id = uwp_get_page_id('login_page', false); | |
| 290 | - $redirect_page_id = uwp_get_option('login_redirect_to', -1); | |
| 291 | - if (!is_admin() && $login_page_id) { | |
| 292 | - $login_page = get_permalink($login_page_id); | |
| 293 | - if($redirect){ | |
| 294 | - $login_url = add_query_arg( 'redirect_to', $redirect, $login_page ); | |
| 295 | - }elseif(isset($redirect_page_id) && (int)$redirect_page_id == -1 && wp_get_referer()) { | |
| 296 | - $redirect_to = esc_url(wp_get_referer()); | |
| 297 | - $login_url = add_query_arg( 'redirect_to', $redirect_to, $login_page ); | |
| 298 | - }elseif($redirect_page_id){ | |
| 299 | - $redirect_to = get_permalink($redirect_page_id); | |
| 300 | - $login_url = add_query_arg( 'redirect_to', $redirect_to, $login_page ); | |
| 301 | - }else{ | |
| 302 | - $login_url = $login_page; | |
| 303 | - } | |
| 304 | - } | |
| 343 | + /** | |
| 344 | + * Redirects user to a predefined page after logging out. | |
| 345 | + * | |
| 346 | + * @return void | |
| 347 | + * @package userswp | |
| 348 | + * @since 1.0.0 | |
| 349 | + */ | |
| 350 | + public function logout_redirect() { | |
| 351 | + $redirect_page_id = uwp_get_page_id( 'logout_redirect_to' ); | |
| 352 | + if ( isset( $_REQUEST['redirect_to'] ) ) { | |
| 353 | + $redirect_to = esc_url( $_REQUEST['redirect_to'] ); | |
| 354 | + } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id > 0 ) { | |
| 355 | + $redirect_to = get_permalink( $redirect_page_id ); | |
| 356 | + } else { | |
| 357 | + $redirect_to = home_url( '/' ); | |
| 358 | + } | |
| 359 | + $redirect_to = apply_filters( 'uwp_logout_redirect', $redirect_to ); | |
| 360 | + wp_safe_redirect( $redirect_to ); | |
| 361 | + exit(); | |
| 362 | + } | |
| 305 | 363 | |
| 306 | - return $login_url; | |
| 307 | - } | |
| 364 | + /** | |
| 365 | + * Redirects wp-login.php to UsersWP login page. | |
| 366 | + * | |
| 367 | + * @return void | |
| 368 | + * @package userswp | |
| 369 | + * @since 1.0.0 | |
| 370 | + */ | |
| 371 | + public function wp_login_redirect() { | |
| 372 | + global $pagenow; | |
| 373 | + if ( 'wp-login.php' == $pagenow && ! isset( $_REQUEST['action'] ) ) { | |
| 374 | + $login_page_id = uwp_get_page_id( 'login_page', false ); | |
| 375 | + $block_wp_login = uwp_get_option( 'block_wp_login', '' ); | |
| 376 | + if ( $login_page_id && $block_wp_login == '1' ) { | |
| 377 | + $redirect_to = get_permalink( $login_page_id ); | |
| 378 | + if ( $redirect_to ) { | |
| 379 | + $redirect_to = add_query_arg( 'redirect_to', admin_url(), $redirect_to ); | |
| 380 | + } | |
| 381 | + wp_safe_redirect( $redirect_to ); | |
| 382 | + exit(); | |
| 383 | + } | |
| 384 | + } | |
| 385 | + } | |
| 308 | 386 | |
| 309 | - /** | |
| 310 | - * Changes the register url with the UWP register page. | |
| 311 | - * | |
| 312 | - * @param $register_url string The URL for register. | |
| 313 | - * @since 1.0.22 | |
| 314 | - * | |
| 315 | - * @return string The register url. | |
| 316 | - */ | |
| 317 | - public function wp_register_url($register_url) { | |
| 318 | - $register_page_id = uwp_get_page_id('register_page', false); | |
| 319 | - $redirect_page_id = uwp_get_option('register_redirect_to', -1); | |
| 320 | - $redirect_disabled = uwp_get_option('wp_register_redirect'); | |
| 387 | + /** | |
| 388 | + * Redirects wp-login.php?action=register to UsersWP registration page. | |
| 389 | + * | |
| 390 | + * @return void | |
| 391 | + * @package userswp | |
| 392 | + * @since 1.0.0 | |
| 393 | + */ | |
| 394 | + public function wp_register_redirect() { | |
| 321 | 395 | |
| 322 | - $redirect = isset($_REQUEST['redirect_to']) ? esc_url($_REQUEST['redirect_to']) : ''; | |
| 323 | - if ($register_page_id && 1 != $redirect_disabled) { | |
| 324 | - $register_page = get_permalink($register_page_id); | |
| 325 | - if($register_url && isset($redirect) && !empty($redirect)){ | |
| 326 | - $register_url = add_query_arg( 'redirect_to', $redirect, $register_page ); | |
| 327 | - }elseif((int)$redirect_page_id > 0){ | |
| 328 | - $redirect_to = get_permalink($redirect_page_id); | |
| 329 | - $register_url = add_query_arg( 'redirect_to', $redirect_to, $register_page ); | |
| 330 | - }else{ | |
| 331 | - $register_url = $register_page; | |
| 332 | - } | |
| 333 | - } | |
| 396 | + global $pagenow; | |
| 397 | + if ( 'wp-login.php' == $pagenow && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'register' ) { | |
| 398 | + $reg_page_id = uwp_get_page_id( 'register_page' ); | |
| 399 | + $block_wp_reg = uwp_get_option( 'wp_register_redirect' ); | |
| 400 | + if ( $reg_page_id && $block_wp_reg == '1' ) { | |
| 334 | 401 | |
| 335 | - return $register_url; | |
| 336 | - } | |
| 402 | + $redirect = isset( $_REQUEST['redirect_to'] ) ? esc_url( $_REQUEST['redirect_to'] ) : ''; | |
| 403 | + $redirect_to = get_permalink( $reg_page_id ); | |
| 404 | + if ( $redirect ) { | |
| 405 | + $redirect_to = add_query_arg( 'redirect_to', $redirect, $redirect_to ); | |
| 406 | + } | |
| 407 | + wp_safe_redirect( $redirect_to ); | |
| 408 | + exit(); | |
| 409 | + } | |
| 410 | + } | |
| 411 | + } | |
| 337 | 412 | |
| 338 | - /** | |
| 339 | - * Prints html for form fields of that particular form. | |
| 340 | - * | |
| 341 | - * @since 1.0.0 | |
| 342 | - * @package userswp | |
| 343 | - * @param string $form_type Form type. | |
| 344 | - * @return void | |
| 345 | - */ | |
| 346 | - public function uwp_template_fields($form_type) { | |
| 413 | + /** | |
| 414 | + * Changes the login url to the UWP login page. | |
| 415 | + * | |
| 416 | + * @param $login_url string The URL for login. | |
| 417 | + * @param $redirect string The URL to redirect back to upon successful login. | |
| 418 | + * @param $force_reauth bool Whether to force reauthorization, even if a cookie is present. | |
| 419 | + * | |
| 420 | + * @return string The login url. | |
| 421 | + * @package userswp | |
| 422 | + * | |
| 423 | + * @since 1.0.12 | |
| 424 | + */ | |
| 425 | + public function wp_login_url( $login_url, $redirect, $force_reauth ) { | |
| 426 | + global $pagenow; | |
| 347 | 427 | |
| 348 | - global $wpdb; | |
| 349 | - $table_name = uwp_get_table_prefix() . 'uwp_form_fields'; | |
| 350 | - $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras'; | |
| 428 | + if ( class_exists( 'Jetpack' ) && 'wp-login.php' == $pagenow && Jetpack::is_module_active( 'sso' ) ) { | |
| 429 | + return $login_url; // Do not change the URL for Jetpack SSO | |
| 430 | + } | |
| 351 | 431 | |
| 352 | - if ($form_type == 'register') { | |
| 353 | - $fields = get_register_form_fields(); | |
| 354 | - } elseif ($form_type == 'account') { | |
| 355 | - $fields = get_account_form_fields(); | |
| 356 | - } elseif ($form_type == 'change') { | |
| 357 | - $fields = get_change_form_fields(); | |
| 358 | - } else { | |
| 359 | - $fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $table_name . " WHERE form_type = %s AND is_active = '1' AND for_admin_use != '1' ORDER BY sort_order ASC", array($form_type))); | |
| 360 | - } | |
| 361 | - | |
| 362 | - if (!empty($fields)) { | |
| 363 | - foreach ($fields as $field) { | |
| 432 | + if( did_action('init') === 0 ){ | |
| 433 | + return $login_url; // Some plugin calls login link very early. | |
| 434 | + } | |
| 364 | 435 | |
| 365 | - if ($form_type == 'account') { | |
| 366 | - if ($field->htmlvar_name == 'uwp_account_display_name') { | |
| 367 | - if ($field->is_active != '1') { | |
| 368 | - continue; | |
| 369 | - } | |
| 370 | - } | |
| 371 | - if ($field->htmlvar_name == 'uwp_account_bio') { | |
| 372 | - if ($field->is_active != '1') { | |
| 373 | - continue; | |
| 374 | - } | |
| 375 | - } | |
| 436 | + $login_page_id = uwp_get_page_id( 'login_page', false ); | |
| 437 | + $redirect_page_id = uwp_get_page_id( 'login_redirect_to' ); | |
| 438 | + if ( ( ! is_admin() || wp_doing_ajax() ) && $login_page_id ) { | |
| 439 | + $login_page = get_permalink( $login_page_id ); | |
| 440 | + if ( $redirect ) { | |
| 441 | + $login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $login_page ); | |
| 442 | + } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id == - 1 && wp_get_referer() ) { | |
| 443 | + $redirect_to = esc_url( wp_get_referer() ); | |
| 444 | + $login_url = add_query_arg( 'redirect_to', $redirect_to, $login_page ); | |
| 445 | + } elseif ( isset( $redirect_page_id ) && $redirect_page_id > 0 ) { | |
| 446 | + $redirect_to = get_permalink( $redirect_page_id ); | |
| 447 | + $login_url = add_query_arg( 'redirect_to', $redirect_to, $login_page ); | |
| 448 | + } else { | |
| 449 | + $login_url = $login_page; | |
| 450 | + } | |
| 451 | + } | |
| 452 | + | |
| 453 | + return $login_url; | |
| 454 | + } | |
| 455 | + | |
| 456 | + /** | |
| 457 | + * Changes the register url with the UWP register page. | |
| 458 | + * | |
| 459 | + * @param $register_url string The URL for register. | |
| 460 | + * | |
| 461 | + * @return string The register url. | |
| 462 | + * @since 1.0.22 | |
| 463 | + * | |
| 464 | + */ | |
| 465 | + public function wp_register_url( $register_url ) { | |
| 466 | + $register_page_id = uwp_get_page_id( 'register_page' ); | |
| 467 | + $redirect_page_id = uwp_get_page_id( 'register_redirect_to' ); | |
| 468 | + | |
| 469 | + $redirect = isset( $_REQUEST['redirect_to'] ) ? esc_url( $_REQUEST['redirect_to'] ) : ''; | |
| 470 | + if ( isset( $register_page_id ) && $register_page_id > 0 ) { | |
| 471 | + $register_page = get_permalink( $register_page_id ); | |
| 472 | + if ( $register_url && isset( $redirect ) && ! empty( $redirect ) ) { | |
| 473 | + $register_url = add_query_arg( 'redirect_to', $redirect, $register_page ); | |
| 474 | + } elseif ( (int) $redirect_page_id > 0 ) { | |
| 475 | + $redirect_to = get_permalink( $redirect_page_id ); | |
| 476 | + $register_url = add_query_arg( 'redirect_to', $redirect_to, $register_page ); | |
| 477 | + } else { | |
| 478 | + $register_url = $register_page; | |
| 479 | + } | |
| 480 | + } | |
| 481 | + | |
| 482 | + return $register_url; | |
| 483 | + } | |
| 484 | + | |
| 485 | + /** | |
| 486 | + * Changes the lost password url with the UWP page. | |
| 487 | + * | |
| 488 | + * @param $lostpassword_url string The URL for lost password. | |
| 489 | + * | |
| 490 | + * @return string The lost password page url. | |
| 491 | + */ | |
| 492 | + public function wp_lostpassword_url( $lostpassword_url ) { | |
| 493 | + $forgot_page_url = uwp_get_forgot_page_url(); | |
| 494 | + | |
| 495 | + if ( is_multisite() && isset( $_GET['redirect_to'] ) && false !== strpos( wp_unslash( $_GET['redirect_to'] ), network_admin_url() ) ) { | |
| 496 | + return $lostpassword_url; | |
| 497 | + } | |
| 498 | + | |
| 499 | + $redirect = isset( $_REQUEST['redirect_to'] ) ? esc_url( $_REQUEST['redirect_to'] ) : ''; | |
| 500 | + if ( $forgot_page_url ) { | |
| 501 | + if ( $forgot_page_url && isset( $redirect ) && ! empty( $redirect ) ) { | |
| 502 | + $lostpassword_url = add_query_arg( 'redirect_to', $redirect, $forgot_page_url ); | |
| 503 | + } else { | |
| 504 | + $lostpassword_url = $forgot_page_url; | |
| 505 | + } | |
| 506 | + } | |
| 507 | + | |
| 508 | + return $lostpassword_url; | |
| 509 | + } | |
| 510 | + | |
| 511 | + /** | |
| 512 | + * Prints html for form fields of that particular form. | |
| 513 | + * | |
| 514 | + * @param string $form_type Form type. | |
| 515 | + * | |
| 516 | + * @return void | |
| 517 | + * @since 1.0.0 | |
| 518 | + * @package userswp | |
| 519 | + */ | |
| 520 | + public function template_fields( $form_type, $args = array() ) { | |
| 521 | + | |
| 522 | + global $wpdb, $aui_bs5; | |
| 523 | + $table_name = uwp_get_table_prefix() . 'uwp_form_fields'; | |
| 524 | + $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras'; | |
| 525 | + | |
| 526 | + $form_id = ! empty( $args['id'] ) ? (int) $args['id'] : uwp_get_option('register_modal_form', 1); | |
| 527 | + if ( $form_type == 'register' ) { | |
| 528 | + $fields = get_register_form_fields($form_id); | |
| 529 | + // Use limit from args, otherwise fall back to the register_modal_form setting. | |
| 530 | + $form_limit = ! empty( $args['limit'] ) ? $args['limit'] : uwp_get_option('register_modal_form', ''); | |
| 531 | + if(isset($form_limit) && !is_array($form_limit)){ | |
| 532 | + $form_limit = explode(',', $form_limit); | |
| 533 | + } | |
| 534 | + | |
| 535 | + if(isset($form_limit) && !empty($form_limit) && count($form_limit) > 1){ | |
| 536 | + | |
| 537 | + $form_limit = array_map('uwp_clean', $form_limit); | |
| 538 | + $form_limit = array_map('trim', $form_limit); | |
| 539 | + $options = uwp_get_register_forms_dropdown_options($form_limit); | |
| 540 | + $selector_id = wp_doing_ajax() ? "uwp-form-select-ajax" : 'uwp-form-select'; | |
| 541 | + $display_style = uwp_get_option('register_form_display_style', 'buttons'); | |
| 542 | + | |
| 543 | + if ( $display_style === 'select' ) { | |
| 544 | + // Render as select dropdown. | |
| 545 | + $selector_label = apply_filters( 'uwp_account_type_selector_label', __('Account Type', 'userswp'), $form_type, $args ); | |
| 546 | + ?> | |
| 547 | + <div class="form-group mb-3" id="<?php echo esc_attr( $selector_id ); ?>"> | |
| 548 | + <label for="uwp-form-type-select" class="form-label"><?php echo esc_html( $selector_label ); ?></label> | |
| 549 | + <select id="uwp-form-type-select" class="form-select aui-select2 w-100" data-form-selector="select"> | |
| 550 | + <?php | |
| 551 | + foreach ( $options as $option_id => $option_label ) { | |
| 552 | + $selected = $form_id == $option_id ? 'selected' : ''; | |
| 553 | + ?> | |
| 554 | + <option value="<?php echo esc_attr( $option_id ); ?>" <?php echo esc_attr( $selected ); ?> data-form_id="<?php echo esc_attr( $option_id ); ?>"> | |
| 555 | + <?php echo esc_html( $option_label ); ?> | |
| 556 | + </option> | |
| 557 | + <?php | |
| 558 | + } | |
| 559 | + ?> | |
| 560 | + </select> | |
| 561 | + </div> | |
| 562 | + <?php | |
| 563 | + } else { | |
| 564 | + // Render as button groups (default) | |
| 565 | + ?> | |
| 566 | + <div class="btn-group btn-group-sm d-flex mb-3" role="group" id="<?php echo esc_attr( $selector_id ); ?>"> | |
| 567 | + <?php | |
| 568 | + $options = array_chunk( $options, 5, true ); | |
| 569 | + $current_url = uwp_current_page_url(); | |
| 570 | + if ( isset( $options[0] ) && ! empty( $options[0] ) && count( $options[0] ) > 1 ) { | |
| 571 | + foreach ( $options[0] as $id => $val ) { | |
| 572 | + $active = $form_id == $id ? 'active' : ''; | |
| 573 | + $url = esc_url_raw( add_query_arg( array( 'uwp_form_id' => $id ), $current_url ) ); | |
| 574 | + echo aui()->button( array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 575 | + 'type' => 'a', | |
| 576 | + 'href' => '#', | |
| 577 | + 'class' => 'btn btn-outline-primary '. esc_attr( $active ), | |
| 578 | + 'content' => esc_attr( $val ), | |
| 579 | + 'extra_attributes' => array('data-form_id'=> esc_attr( $id ) ) | |
| 580 | + ) ); | |
| 581 | + } | |
| 582 | + }elseif(count( $options[0] ) == 1){ | |
| 583 | + $form_id = key($options[0]); | |
| 584 | + } | |
| 585 | + | |
| 586 | + if ( isset( $options[1] ) && ! empty( $options[1] ) && count( $options[1] ) > 0 ) { | |
| 587 | + foreach ( $options[1] as $id => $val ) { | |
| 588 | + $active = $form_id == $id ? 'active' : ''; | |
| 589 | + $url = esc_url_raw( add_query_arg( array( 'uwp_form_id' => $id ), $current_url ) ); | |
| 590 | + ?> | |
| 591 | + <div class="btn-group" role="group"> | |
| 592 | + <button id="uwp-form-select-dropdown" type="button" class="btn btn-secondary dropdown-toggle" data-<?php echo ( $aui_bs5 ? 'bs-' : '' ); ?>toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | |
| 593 | + <?php esc_attr_e('More', 'userswp'); ?> | |
| 594 | + </button> | |
| 595 | + <div class="dropdown-menu mt-3" aria-labelledby="uwp-form-select"> | |
| 596 | + <?php | |
| 597 | + echo aui()->button( array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 598 | + 'type' => 'a', | |
| 599 | + 'href' => esc_url( $url ), | |
| 600 | + 'class' => 'dropdown-item ' . esc_attr( $active ), | |
| 601 | + 'content' => esc_attr( $val ), | |
| 602 | + 'extra_attributes' => array('data-form_id'=> esc_attr( $id ) ) | |
| 603 | + ) ); | |
| 604 | + ?> | |
| 605 | + </div> | |
| 606 | + </div> | |
| 607 | + <?php | |
| 608 | + } | |
| 609 | + } | |
| 610 | + ?> | |
| 611 | + </div> | |
| 612 | + <?php | |
| 613 | + } | |
| 614 | + } | |
| 615 | + } elseif ( $form_type == 'account' ) { | |
| 616 | + $fields = get_account_form_fields(); | |
| 617 | + } elseif ( $form_type == 'change' ) { | |
| 618 | + $fields = get_change_form_fields(); | |
| 619 | + } else { | |
| 620 | + $fields = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $table_name . " WHERE form_type = %s AND is_active = '1' AND for_admin_use != '1' ORDER BY sort_order ASC", array( $form_type ) ) ); | |
| 621 | + } | |
| 622 | + | |
| 623 | + if ( ! empty( $fields ) ) { | |
| 624 | + foreach ( $fields as $field ) { | |
| 625 | + | |
| 626 | + if ( $form_type == 'account' ) { | |
| 627 | + if ( $field->htmlvar_name == 'display_name' ) { | |
| 628 | + if ( $field->is_active != '1' ) { | |
| 629 | + continue; | |
| 630 | + } | |
| 631 | + } | |
| 632 | + if ( $field->htmlvar_name == 'bio' ) { | |
| 633 | + if ( $field->is_active != '1' ) { | |
| 634 | + continue; | |
| 635 | + } | |
| 636 | + } | |
| 637 | + } | |
| 638 | + | |
| 639 | + if ( $form_type == 'register' ) { | |
| 640 | + if ( $field->is_active != '1' ) { | |
| 641 | + continue; | |
| 642 | + } | |
| 643 | + $count = $wpdb->get_var( $wpdb->prepare( "select count(*) from " . $extras_table_name . " where site_htmlvar_name=%s AND form_type = %s AND form_id=%d", array( | |
| 644 | + $field->htmlvar_name, | |
| 645 | + $form_type, | |
| 646 | + $form_id | |
| 647 | + ) ) ); | |
| 648 | + if ( $count == 1 ) { | |
| 649 | + $this->template_fields_html( $field, $form_type ); | |
| 650 | + } | |
| 651 | + } else { | |
| 652 | + $this->template_fields_html( $field, $form_type ); | |
| 653 | + } | |
| 654 | + } | |
| 655 | + } | |
| 656 | + } | |
| 657 | + | |
| 658 | + /** | |
| 659 | + * Prints field html based on field type. | |
| 660 | + * | |
| 661 | + * @param object $field Field info. | |
| 662 | + * @param string $form_type Form type. | |
| 663 | + * @param int|bool $user_id User ID. | |
| 664 | + * | |
| 665 | + * @return void | |
| 666 | + * @since 1.0.0 | |
| 667 | + * @package userswp | |
| 668 | + */ | |
| 669 | + public function template_fields_html( $field, $form_type, $user_id = false ) { | |
| 670 | + if ( ! $user_id ) { | |
| 671 | + $user_id = get_current_user_id(); | |
| 672 | + } | |
| 673 | + | |
| 674 | + $value = $this->get_default_form_value( $field ); | |
| 675 | + if ( $form_type == 'account' ) { | |
| 676 | + $user_data = get_userdata( $user_id ); | |
| 677 | + | |
| 678 | + if ( $field->htmlvar_name == 'email' ) { | |
| 679 | + if(!empty($user_data)) { | |
| 680 | + $value = $user_data->user_email; | |
| 681 | + }else{ | |
| 682 | + $value = ''; | |
| 683 | + } | |
| 684 | + } elseif ( $field->htmlvar_name == 'password' ) { | |
| 685 | + $value = ''; | |
| 686 | + $field->is_required = 0; | |
| 687 | + } elseif ( $field->htmlvar_name == 'confirm_password' ) { | |
| 688 | + $value = ''; | |
| 689 | + $field->is_required = 0; | |
| 690 | + } else { | |
| 691 | + $value = uwp_get_usermeta( $user_id, $field->htmlvar_name, false ); | |
| 692 | + if ( $value != '0' && ! $value ) { | |
| 693 | + $value = $this->get_default_form_value( $field ); | |
| 694 | + } | |
| 695 | + } | |
| 696 | + | |
| 697 | + } | |
| 698 | + | |
| 699 | + if ( ! isset( $value ) ) { | |
| 700 | + $value = ""; | |
| 701 | + } | |
| 702 | + | |
| 703 | + if ( isset( $_POST[ $field->htmlvar_name ] ) && $field->field_type != 'password' ) { | |
| 704 | + $value = isset( $_POST[ $field->htmlvar_name ] ) ? $_POST[ $field->htmlvar_name ] : ''; //@todo: Used to pre fill form when validation fails, need to find better solution | |
| 705 | + } | |
| 706 | + | |
| 707 | + if ( 'checkbox' == $field->field_type ) { | |
| 708 | + if ( in_array( $value, array( 'true', 'on', 1 ) ) ) { | |
| 709 | + $value = 1; | |
| 710 | + } else { | |
| 711 | + $value = 0; | |
| 712 | + } | |
| 713 | + } | |
| 714 | + | |
| 715 | + $field = apply_filters( "uwp_form_input_field_{$field->field_type}", $field, $value, $form_type ); | |
| 716 | + | |
| 717 | + $html = apply_filters( "uwp_form_input_html_{$field->field_type}", "", $field, $value, $form_type ); | |
| 718 | + | |
| 719 | + if ( empty( $html ) ) { | |
| 720 | + | |
| 721 | + $design_style = uwp_get_option( "design_style", "bootstrap" ); | |
| 722 | + $bs_form_group = $design_style ? "form-group mb-3" : ""; | |
| 723 | + $bs_sr_only = $design_style ? "sr-only" : ""; | |
| 724 | + $bs_form_control = $design_style ? "form-control" : ""; | |
| 725 | + | |
| 726 | + ?> | |
| 727 | + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" | |
| 728 | + class="<?php if ( $field->is_required ) { | |
| 729 | + echo 'required_field'; | |
| 730 | + } ?> uwp_form_row clearfix uwp_clear <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 731 | + <?php | |
| 732 | + | |
| 733 | + $label = $site_title = uwp_get_form_label( $field ); | |
| 734 | + if ( ! is_admin() ) { ?> | |
| 735 | + <label class="<?php echo esc_attr( $bs_sr_only ); ?>"> | |
| 736 | + <?php echo ( trim( $site_title ) ) ? esc_attr( $site_title ) : ' '; ?> | |
| 737 | + <?php if ( $field->is_required ) { | |
| 738 | + echo '<span>*</span>'; | |
| 739 | + } ?> | |
| 740 | + </label> | |
| 741 | + <?php } ?> | |
| 742 | + | |
| 743 | + <input name="<?php echo esc_attr($field->htmlvar_name); ?>" | |
| 744 | + class="<?php echo esc_attr($field->css_class); ?> <?php echo esc_attr( $bs_form_control ); ?>" | |
| 745 | + placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>" | |
| 746 | + title="<?php echo esc_attr($label); ?>" | |
| 747 | + <?php if ( $field->for_admin_use == 1 ) { | |
| 748 | + echo 'readonly="readonly"'; | |
| 749 | + } ?> | |
| 750 | + <?php if ( $field->is_required == 1 ) { | |
| 751 | + echo 'required="required"'; | |
| 752 | + } ?> | |
| 753 | + type="<?php echo esc_attr($field->field_type); ?>" | |
| 754 | + value="<?php echo esc_html( $value ); ?>"> | |
| 755 | + | |
| 756 | + </div> | |
| 757 | + <?php | |
| 758 | + } else { | |
| 759 | + echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 760 | + } | |
| 761 | + } | |
| 762 | + | |
| 763 | + /** | |
| 764 | + * Returns default value based on field type. | |
| 765 | + * | |
| 766 | + * @param object $field Field info. | |
| 767 | + * | |
| 768 | + * @return string Field default value. | |
| 769 | + * @since 1.0.0 | |
| 770 | + * @package userswp | |
| 771 | + */ | |
| 772 | + public function get_default_form_value( $field ) { | |
| 773 | + if ( $field->field_type == 'url' ) { | |
| 774 | + if ( substr( $field->default_value, 0, 4 ) === "http" ) { | |
| 775 | + $value = $field->default_value; | |
| 776 | + } else { | |
| 777 | + $value = ""; | |
| 778 | + } | |
| 779 | + } else { | |
| 780 | + $value = $field->default_value; | |
| 781 | + } | |
| 782 | + | |
| 783 | + return $value; | |
| 784 | + } | |
| 785 | + | |
| 786 | + /** | |
| 787 | + * Display redirect to input of that particular form. | |
| 788 | + * | |
| 789 | + * @param string $form_type Form type. | |
| 790 | + * | |
| 791 | + * @return void | |
| 792 | + * @since 1.0.21 | |
| 793 | + * @package userswp | |
| 794 | + */ | |
| 795 | + public function template_extra_fields( $form_type, $args = array() ) { | |
| 796 | + if ( $form_type == 'login' ) { | |
| 797 | + $redirect_to = ''; | |
| 798 | + if ( isset( $args['redirect_to'] ) && ! empty( $args['redirect_to'] ) ) { | |
| 799 | + $redirect_to = $args['redirect_to']; | |
| 800 | + } elseif ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) { | |
| 801 | + $redirect_to = esc_url( urldecode( $_REQUEST['redirect_to'] ) ); | |
| 802 | + } else { | |
| 803 | + if ( - 1 == uwp_get_option( 'login_redirect_to', - 1 ) ) { | |
| 804 | + $referer = wp_get_referer(); | |
| 805 | + if ( isset( $referer ) && ! empty( $referer ) ) { | |
| 806 | + $redirect_to = $referer; | |
| 807 | + } else { | |
| 808 | + $redirect_to = home_url(); | |
| 809 | + } | |
| 810 | + } | |
| 811 | + } | |
| 812 | + | |
| 813 | + $redirect_to = apply_filters('uwp_login_redirect_to', $redirect_to, $args); | |
| 814 | + | |
| 815 | + if ( $redirect_to ) { | |
| 816 | + echo '<input type="hidden" name="redirect_to" value="' . esc_url( $redirect_to ) . '"/>'; | |
| 817 | + } | |
| 818 | + | |
| 819 | + echo '<input type="hidden" name="uwp_login_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-login-nonce' ) ) . '" />'; | |
| 820 | + } elseif ( $form_type == 'register' ) { | |
| 821 | + $redirect_to = ''; | |
| 822 | + $form_id = ! empty( $args['id'] ) ? $args['id'] : 1; | |
| 823 | + if ( isset( $args['redirect_to'] ) && ! empty( $args['redirect_to'] ) ) { | |
| 824 | + $redirect_to = $args['redirect_to']; | |
| 825 | + } else { | |
| 826 | + $redirect_to_value = uwp_get_register_form_by( $form_id, 'redirect_to'); | |
| 827 | + if(!$redirect_to_value){ | |
| 828 | + $redirect_to_value = uwp_get_option( 'register_redirect_to', - 1 ); | |
| 376 | 829 | } |
| 377 | 830 | |
| 378 | - if ($form_type == 'register') { | |
| 379 | - if ($field->is_active != '1') { | |
| 380 | - continue; | |
| 381 | - } | |
| 382 | - $count = $wpdb->get_var($wpdb->prepare("select count(*) from ".$extras_table_name." where site_htmlvar_name=%s AND form_type = %s", array($field->htmlvar_name, $form_type))); | |
| 383 | - if ($count == 1) { | |
| 384 | - $this->uwp_template_fields_html($field, $form_type); | |
| 385 | - } | |
| 386 | - } else { | |
| 387 | - $this->uwp_template_fields_html($field, $form_type); | |
| 388 | - } | |
| 389 | - } | |
| 390 | - } | |
| 391 | - } | |
| 831 | + if ( - 1 == $redirect_to_value) { | |
| 832 | + $referer = wp_get_referer(); | |
| 833 | + if ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) { | |
| 834 | + $redirect_to = esc_url( urldecode( $_REQUEST['redirect_to'] ) ); | |
| 835 | + } else if ( isset( $referer ) && ! empty( $referer ) ) { | |
| 836 | + $redirect_to = $referer; | |
| 837 | + } else { | |
| 838 | + $redirect_to = home_url(); | |
| 839 | + } | |
| 840 | + } | |
| 841 | + } | |
| 392 | 842 | |
| 393 | - /** | |
| 394 | - * Display redirect to input of that particular form. | |
| 395 | - * | |
| 396 | - * @since 1.0.21 | |
| 397 | - * @package userswp | |
| 398 | - * @param string $form_type Form type. | |
| 399 | - * @return void | |
| 400 | - */ | |
| 401 | - public function uwp_template_extra_fields($form_type){ | |
| 402 | - if ($form_type == 'login') { | |
| 403 | - if (-1 == uwp_get_option('login_redirect_to', -1)) { | |
| 404 | - $referer = wp_get_referer(); | |
| 405 | - if (isset($_REQUEST['redirect_to']) && !empty($_REQUEST['redirect_to'])) { | |
| 406 | - $redirect_to = esc_url($_REQUEST['redirect_to']); | |
| 407 | - } else if(isset($referer) && !empty($referer)){ | |
| 408 | - $redirect_to = $referer; | |
| 409 | - } else { | |
| 410 | - $redirect_to = home_url(); | |
| 411 | - } | |
| 412 | - echo '<input type="hidden" name="redirect_to" value="'.$redirect_to.'"/>'; | |
| 413 | - } | |
| 414 | - echo '<input type="hidden" name="uwp_login_nonce" value="'. wp_create_nonce( 'uwp-login-nonce' ) .'" />'; | |
| 415 | - } elseif ($form_type == 'register') { | |
| 416 | - if (-1 == uwp_get_option('register_redirect_to', -1)) { | |
| 417 | - $referer = wp_get_referer(); | |
| 418 | - if (isset($_REQUEST['redirect_to']) && !empty($_REQUEST['redirect_to'])) { | |
| 419 | - $redirect_to = esc_url($_REQUEST['redirect_to']); | |
| 420 | - } else if(isset($referer) && !empty($referer)){ | |
| 421 | - $redirect_to = $referer; | |
| 422 | - } else { | |
| 423 | - $redirect_to = home_url(); | |
| 424 | - } | |
| 425 | - echo '<input type="hidden" name="redirect_to" value="'.$redirect_to.'"/>'; | |
| 426 | - } | |
| 427 | - echo '<input type="hidden" name="uwp_register_nonce" value="'. wp_create_nonce( 'uwp-register-nonce' ) .'" />'; | |
| 428 | - } elseif ($form_type == 'change') { | |
| 429 | - echo '<input type="hidden" name="uwp_change_nonce" value="'. wp_create_nonce( 'uwp-change-nonce' ) .'" />'; | |
| 430 | - } elseif ($form_type == 'forgot') { | |
| 431 | - echo '<input type="hidden" name="uwp_forgot_nonce" value="'. wp_create_nonce( 'uwp-forgot-nonce' ) .'" />'; | |
| 432 | - } elseif ($form_type == 'reset') { | |
| 433 | - if (isset($_GET['key']) && isset($_GET['login'])) { | |
| 434 | - echo '<input type="hidden" name="uwp_reset_username" value="' . sanitize_text_field($_GET['login']) . '" />'; | |
| 435 | - echo '<input type="hidden" name="uwp_reset_key" value="' . sanitize_text_field($_GET['key']) . '" />'; | |
| 436 | - } | |
| 437 | - echo '<input type="hidden" name="uwp_reset_nonce" value="' . wp_create_nonce('uwp-reset-nonce') . '" />'; | |
| 438 | - } | |
| 439 | - } | |
| 843 | + $redirect_to = apply_filters('uwp_register_redirect_to', $redirect_to, $args); | |
| 440 | 844 | |
| 441 | - /** | |
| 442 | - * Adds "Edit Account" form on account page. | |
| 443 | - * | |
| 444 | - * @since 1.0.0 | |
| 445 | - * @package userswp | |
| 446 | - * @param string $type Template type. | |
| 447 | - * @return void | |
| 448 | - */ | |
| 449 | - public function uwp_account_edit_form_display($type) { | |
| 450 | - if ($type == 'account') { | |
| 451 | - ?> | |
| 452 | - <form class="uwp-account-form uwp_form" method="post" enctype="multipart/form-data"> | |
| 453 | - <?php do_action('uwp_template_fields', 'account'); ?> | |
| 454 | - <input type="hidden" name="uwp_account_nonce" value="<?php echo wp_create_nonce( 'uwp-account-nonce' ); ?>" /> | |
| 455 | - <input name="uwp_account_submit" value="<?php echo __( 'Update Account', 'userswp' ); ?>" type="submit"> | |
| 456 | - </form> | |
| 457 | - <?php } | |
| 458 | - } | |
| 845 | + if ( $redirect_to ) { | |
| 846 | + echo '<input type="hidden" name="redirect_to" value="' . esc_url( $redirect_to ) . '"/>'; | |
| 847 | + } | |
| 459 | 848 | |
| 460 | - /** | |
| 461 | - * Prints field html based on field type. | |
| 462 | - * | |
| 463 | - * @since 1.0.0 | |
| 464 | - * @package userswp | |
| 465 | - * @param object $field Field info. | |
| 466 | - * @param string $form_type Form type. | |
| 467 | - * @param int|bool $user_id User ID. | |
| 468 | - * @return void | |
| 469 | - */ | |
| 470 | - public function uwp_template_fields_html($field, $form_type, $user_id = false) { | |
| 471 | - if (!$user_id) { | |
| 472 | - $user_id = get_current_user_id(); | |
| 473 | - } | |
| 849 | + $hash = substr( hash( 'SHA256', AUTH_KEY . site_url() ), 0, 25 ); | |
| 850 | + echo '<input type="hidden" name="uwp_register_hash" value="' . esc_html( $hash ) . '" style="display:none !important; visibility:hidden !important;" />'; | |
| 851 | + echo '<input type="hidden" name="uwp_register_hp" value="" style="display:none !important; visibility:hidden !important;" size="25" autocomplete="off" />'; | |
| 852 | + echo '<input type="hidden" name="uwp_register_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-register-nonce-'. $form_id ) ) . '" />'; | |
| 853 | + echo '<input type="hidden" name="uwp_register_form_id" value="' . absint($form_id) . '">'; | |
| 854 | + } elseif ( $form_type == 'change' ) { | |
| 855 | + echo '<input type="hidden" name="uwp_change_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-change-nonce' ) ) . '" />'; | |
| 856 | + } elseif ( $form_type == 'forgot' ) { | |
| 857 | + echo '<input type="hidden" name="uwp_forgot_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-forgot-nonce' ) ) . '" />'; | |
| 858 | + } elseif ( $form_type == 'reset' ) { | |
| 859 | + if ( isset( $_GET['key'] ) && isset( $_GET['login'] ) ) { | |
| 860 | + echo '<input type="hidden" name="uwp_reset_username" value="' . esc_attr( $_GET['login'] ) . '" />'; | |
| 861 | + echo '<input type="hidden" name="uwp_reset_key" value="' . esc_attr( $_GET['key'] ) . '" />'; | |
| 862 | + } | |
| 863 | + echo '<input type="hidden" name="uwp_reset_hp" value="" style="display:none !important; visibility:hidden !important;" size="25" autocomplete="off" />'; | |
| 864 | + echo '<input type="hidden" name="uwp_reset_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-reset-nonce' ) ) . '" />'; | |
| 865 | + } | |
| 866 | + } | |
| 474 | 867 | |
| 475 | - $value = $this->uwp_get_default_form_value($field); | |
| 476 | - if ($form_type == 'account') { | |
| 477 | - $user_data = get_userdata($user_id); | |
| 868 | + /** | |
| 869 | + * Modifies the author page content with UsersWP profile content. | |
| 870 | + * | |
| 871 | + * @param string $content Original page content. | |
| 872 | + * | |
| 873 | + * @return string Modified page content. | |
| 874 | + * @since 1.0.0 | |
| 875 | + * @package userswp | |
| 876 | + */ | |
| 877 | + public function author_page_content( $content ) { | |
| 878 | + if ( is_author() && 1 != uwp_get_option( 'uwp_disable_author_link' ) && apply_filters( 'uwp_use_author_page_content', true ) ) { | |
| 879 | + return do_shortcode( '[uwp_profile]' ); | |
| 880 | + } else { | |
| 881 | + return $content; | |
| 882 | + } | |
| 478 | 883 | |
| 479 | - if ($field->htmlvar_name == 'uwp_account_email') { | |
| 480 | - $value = $user_data->user_email; | |
| 481 | - } elseif ($field->htmlvar_name == 'uwp_account_password') { | |
| 482 | - $value = ''; | |
| 483 | - $field->is_required = 0; | |
| 484 | - } elseif ($field->htmlvar_name == 'uwp_account_confirm_password') { | |
| 485 | - $value = ''; | |
| 486 | - $field->is_required = 0; | |
| 487 | - } else { | |
| 488 | - $value = uwp_get_usermeta($user_id, $field->htmlvar_name, false); | |
| 489 | - if ($value != '0' && !$value) { | |
| 490 | - $value = $this->uwp_get_default_form_value($field); | |
| 491 | - } | |
| 492 | - } | |
| 884 | + } | |
| 493 | 885 | |
| 494 | - } | |
| 886 | + /** | |
| 887 | + * Modifies the menu item visibility based on UsersWP page type. | |
| 888 | + * | |
| 889 | + * @param object $menu_item Menu item info. | |
| 890 | + * | |
| 891 | + * @return object Modified menu item. | |
| 892 | + * @since 1.0.0 | |
| 893 | + * @package userswp | |
| 894 | + */ | |
| 895 | + public function setup_nav_menu_item( $menu_item ) { | |
| 495 | 896 | |
| 496 | - if (empty($value)) { | |
| 497 | - $value = ""; | |
| 498 | - } | |
| 897 | + if ( is_admin() ) { | |
| 898 | + return $menu_item; | |
| 899 | + } | |
| 499 | 900 | |
| 500 | - if (isset($_POST[$field->htmlvar_name]) && $field->field_type != 'password') { | |
| 501 | - $value = $_POST[$field->htmlvar_name]; | |
| 502 | - } | |
| 901 | + // Prevent a notice error when using the customizer | |
| 902 | + $menu_classes = $menu_item->classes; | |
| 503 | 903 | |
| 504 | - $field = apply_filters("uwp_form_input_field_{$field->field_type}", $field, $value, $form_type); | |
| 505 | - | |
| 506 | - $html = apply_filters("uwp_form_input_html_{$field->field_type}", "", $field, $value, $form_type); | |
| 904 | + if ( is_array( $menu_classes ) ) { | |
| 905 | + $menu_classes = implode( ' ', $menu_item->classes ); | |
| 906 | + $str = 'users-wp-menu '; | |
| 907 | + if ( strpos( $menu_classes, 'users-wp-menu ' ) !== false ) { | |
| 908 | + $menu_classes = str_replace( $str, '', $menu_classes ); | |
| 909 | + } | |
| 507 | 910 | |
| 508 | - if (empty($html)) { | |
| 509 | - $label = $site_title = uwp_get_form_label($field); | |
| 510 | - if (!is_admin()) { ?> | |
| 511 | - <label> | |
| 512 | - <?php echo (trim($label)) ? $label : ' '; ?> | |
| 513 | - <?php if ($field->is_required == 1) echo '<span>*</span>';?> | |
| 514 | - </label> | |
| 515 | - <?php } | |
| 516 | - ?> | |
| 517 | - <input name="<?php echo $field->htmlvar_name; ?>" | |
| 518 | - class="<?php echo $field->css_class; ?>" | |
| 519 | - placeholder="<?php echo $label; ?>" | |
| 520 | - title="<?php echo $label; ?>" | |
| 521 | - <?php if ($field->for_admin_use == 1) { echo 'readonly="readonly"'; } ?> | |
| 522 | - <?php if ($field->is_required == 1) { echo 'required="required"'; } ?> | |
| 523 | - type="<?php echo $field->field_type; ?>" | |
| 524 | - value="<?php echo esc_html($value); ?>"> | |
| 525 | - <?php | |
| 526 | - } else { | |
| 527 | - echo $html; | |
| 528 | - } | |
| 529 | - } | |
| 911 | + $menu_classes = explode( " ", $menu_classes ); | |
| 912 | + } | |
| 530 | 913 | |
| 531 | - /** | |
| 532 | - * Returns default value based on field type. | |
| 533 | - * | |
| 534 | - * @since 1.0.0 | |
| 535 | - * @package userswp | |
| 536 | - * @param object $field Field info. | |
| 537 | - * @return string Field default value. | |
| 538 | - */ | |
| 539 | - public function uwp_get_default_form_value($field) { | |
| 540 | - if ($field->field_type == 'url') { | |
| 541 | - if (substr( $field->default_value, 0, 4 ) === "http") { | |
| 542 | - $value = $field->default_value; | |
| 543 | - } else { | |
| 544 | - $value = ""; | |
| 545 | - } | |
| 546 | - } else { | |
| 547 | - $value = $field->default_value; | |
| 548 | - } | |
| 914 | + $register_slug = uwp_get_page_slug( 'register_page' ); | |
| 915 | + $login_slug = uwp_get_page_slug( 'login_page' ); | |
| 916 | + $change_slug = uwp_get_page_slug( 'change_page' ); | |
| 917 | + $account_slug = uwp_get_page_slug( 'account_page' ); | |
| 918 | + $profile_slug = uwp_get_page_slug( 'profile_page' ); | |
| 919 | + $forgot_slug = uwp_get_page_slug( 'forgot_page' ); | |
| 920 | + $logout_slug = "logout"; | |
| 549 | 921 | |
| 550 | - return $value; | |
| 551 | - } | |
| 922 | + $register_class = "users-wp-{$register_slug}-nav"; | |
| 923 | + $login_class = "users-wp-{$login_slug}-nav"; | |
| 924 | + $change_class = "users-wp-{$change_slug}-nav"; | |
| 925 | + $account_class = "users-wp-{$account_slug}-nav"; | |
| 926 | + $profile_class = "users-wp-{$profile_slug}-nav"; | |
| 927 | + $forgot_class = "users-wp-{$forgot_slug}-nav"; | |
| 928 | + $logout_class = "users-wp-{$logout_slug}-nav"; | |
| 552 | 929 | |
| 553 | - /** | |
| 554 | - * Modifies the author page content with UsersWP profile content. | |
| 555 | - * | |
| 556 | - * @since 1.0.0 | |
| 557 | - * @package userswp | |
| 558 | - * @param string $content Original page content. | |
| 559 | - * @return string Modified page content. | |
| 560 | - */ | |
| 561 | - public function uwp_author_page_content($content) { | |
| 562 | - if (is_author() && apply_filters( 'uwp_use_author_page_content', true ) ) { | |
| 563 | - return do_shortcode('[uwp_profile]'); | |
| 564 | - } else { | |
| 565 | - return $content; | |
| 566 | - } | |
| 930 | + if ( ! empty( $menu_classes ) ) { | |
| 931 | + foreach ( $menu_classes as $menu_class ) { | |
| 932 | + switch ( $menu_class ) { | |
| 933 | + case $register_class: | |
| 934 | + if ( is_user_logged_in() ) { | |
| 935 | + $menu_item->_invalid = true; | |
| 936 | + } else { | |
| 937 | + $menu_item->url = uwp_get_page_id( 'register_page', true ); | |
| 938 | + } | |
| 939 | + break; | |
| 940 | + case $login_class: | |
| 941 | + if ( is_user_logged_in() ) { | |
| 942 | + $menu_item->_invalid = true; | |
| 943 | + } else { | |
| 944 | + $menu_item->url = uwp_get_page_id( 'login_page', true ); | |
| 945 | + } | |
| 946 | + break; | |
| 947 | + case $account_class: | |
| 948 | + if ( ! is_user_logged_in() ) { | |
| 949 | + $menu_item->_invalid = true; | |
| 950 | + } else { | |
| 951 | + $menu_item->url = uwp_get_page_id( 'account_page', true ); | |
| 952 | + } | |
| 953 | + break; | |
| 954 | + case $profile_class: | |
| 955 | + if ( ! is_user_logged_in() ) { | |
| 956 | + $menu_item->_invalid = true; | |
| 957 | + } else { | |
| 958 | + $menu_item->url = uwp_get_page_id( 'profile_page', true ); | |
| 959 | + } | |
| 960 | + break; | |
| 961 | + case $change_class: | |
| 962 | + if ( ! is_user_logged_in() ) { | |
| 963 | + $menu_item->_invalid = true; | |
| 964 | + } else { | |
| 965 | + $menu_item->url = uwp_get_page_id( 'change_page', true ); | |
| 966 | + } | |
| 967 | + break; | |
| 968 | + case $forgot_class: | |
| 969 | + if ( is_user_logged_in() ) { | |
| 970 | + $menu_item->_invalid = true; | |
| 971 | + } else { | |
| 972 | + $menu_item->url = uwp_get_page_id( 'forgot_page', true ); | |
| 973 | + } | |
| 974 | + break; | |
| 975 | + case $logout_class: | |
| 976 | + if ( ! is_user_logged_in() ) { | |
| 977 | + $menu_item->_invalid = true; | |
| 978 | + } else { | |
| 979 | + $menu_item->url = $this->uwp_logout_url(); | |
| 980 | + } | |
| 981 | + break; | |
| 982 | + } | |
| 983 | + } | |
| 984 | + } | |
| 567 | 985 | |
| 568 | - } | |
| 986 | + $menu_item = apply_filters( 'uwp_setup_nav_menu_item', $menu_item, $menu_classes ); | |
| 569 | 987 | |
| 570 | - /** | |
| 571 | - * Modifies the menu item visibility based on UsersWP page type. | |
| 572 | - * | |
| 573 | - * @since 1.0.0 | |
| 574 | - * @package userswp | |
| 575 | - * @param object $menu_item Menu item info. | |
| 576 | - * @return object Modified menu item. | |
| 577 | - */ | |
| 578 | - public function uwp_setup_nav_menu_item( $menu_item ) { | |
| 988 | + return $menu_item; | |
| 579 | 989 | |
| 580 | - if ( is_admin() ) { | |
| 581 | - return $menu_item; | |
| 582 | - } | |
| 990 | + } | |
| 583 | 991 | |
| 584 | - // Prevent a notice error when using the customizer | |
| 585 | - $menu_classes = $menu_item->classes; | |
| 992 | + /** | |
| 993 | + * Returns the logout url by adding redirect page link. | |
| 994 | + * | |
| 995 | + * @param null $custom_redirect Redirect page link. | |
| 996 | + * | |
| 997 | + * @return string Logout url. | |
| 998 | + * @since 1.0.0 | |
| 999 | + * @package userswp | |
| 1000 | + */ | |
| 1001 | + public function uwp_logout_url( $custom_redirect = null ) { | |
| 586 | 1002 | |
| 587 | - if ( is_array( $menu_classes ) ) { | |
| 588 | - $menu_classes = implode( ' ', $menu_item->classes ); | |
| 589 | - $str = 'users-wp-menu '; | |
| 590 | - if (strpos($menu_classes, 'users-wp-menu ') !== false) { | |
| 591 | - $menu_classes = str_replace($str, '', $menu_classes); | |
| 592 | - } | |
| 593 | - } | |
| 1003 | + $redirect = null; | |
| 594 | 1004 | |
| 595 | - $register_slug = uwp_get_page_slug('register_page'); | |
| 596 | - $login_slug = uwp_get_page_slug('login_page'); | |
| 597 | - $change_slug = uwp_get_page_slug('change_page'); | |
| 598 | - $account_slug = uwp_get_page_slug('account_page'); | |
| 599 | - $profile_slug = uwp_get_page_slug('profile_page'); | |
| 600 | - $forgot_slug = uwp_get_page_slug('forgot_page'); | |
| 601 | - $logout_slug = "logout"; | |
| 1005 | + $user = get_userdata(get_current_user_id()); | |
| 1006 | + if($user && isset($user->roles[0])){ | |
| 1007 | + $user_role = $user->roles[0]; | |
| 1008 | + $redirect_page_id = uwp_get_option( 'logout_redirect_to_'.$user_role ); | |
| 1009 | + } | |
| 602 | 1010 | |
| 603 | - $register_class = "users-wp-{$register_slug}-nav"; | |
| 604 | - $login_class = "users-wp-{$login_slug}-nav"; | |
| 605 | - $change_class = "users-wp-{$change_slug}-nav"; | |
| 606 | - $account_class = "users-wp-{$account_slug}-nav"; | |
| 607 | - $profile_class = "users-wp-{$profile_slug}-nav"; | |
| 608 | - $forgot_class = "users-wp-{$forgot_slug}-nav"; | |
| 609 | - $logout_class = "users-wp-{$logout_slug}-nav"; | |
| 1011 | + if ( ! empty( $custom_redirect ) ) { | |
| 1012 | + $redirect = esc_url( $custom_redirect ); | |
| 1013 | + } else if ( isset($redirect_page_id) && !empty($redirect_page_id) ) { | |
| 1014 | + if ( uwp_is_wpml() ) { | |
| 1015 | + $wpml_page_id = uwp_wpml_object_id( $redirect_page_id, 'page', true, ICL_LANGUAGE_CODE ); | |
| 1016 | + if ( ! empty( $wpml_page_id ) ) { | |
| 1017 | + $redirect_page_id = $wpml_page_id; | |
| 1018 | + } | |
| 1019 | + } | |
| 1020 | + $redirect = get_permalink( $redirect_page_id ); | |
| 1021 | + } | |
| 610 | 1022 | |
| 611 | - switch ( $menu_classes ) { | |
| 612 | - case $register_class: | |
| 613 | - if ( is_user_logged_in() ) { | |
| 614 | - $menu_item->_invalid = true; | |
| 615 | - } else { | |
| 616 | - $menu_item->url = uwp_get_page_id('register_page', true); | |
| 617 | - } | |
| 618 | - break; | |
| 619 | - case $login_class: | |
| 620 | - if ( is_user_logged_in() ) { | |
| 621 | - $menu_item->_invalid = true; | |
| 622 | - } else { | |
| 623 | - $menu_item->url = uwp_get_page_id('login_page', true); | |
| 624 | - } | |
| 625 | - break; | |
| 626 | - case $account_class: | |
| 627 | - if ( ! is_user_logged_in() ) { | |
| 628 | - $menu_item->_invalid = true; | |
| 629 | - } else { | |
| 630 | - $menu_item->url = uwp_get_page_id('account_page', true); | |
| 631 | - } | |
| 632 | - break; | |
| 633 | - case $profile_class: | |
| 634 | - if ( ! is_user_logged_in() ) { | |
| 635 | - $menu_item->_invalid = true; | |
| 636 | - } else { | |
| 637 | - $menu_item->url = uwp_get_page_id('profile_page', true); | |
| 638 | - } | |
| 639 | - break; | |
| 640 | - case $change_class: | |
| 641 | - if ( ! is_user_logged_in() ) { | |
| 642 | - $menu_item->_invalid = true; | |
| 643 | - } else { | |
| 644 | - $menu_item->url = uwp_get_page_id('change_page', true); | |
| 645 | - } | |
| 646 | - break; | |
| 647 | - case $forgot_class: | |
| 648 | - if ( is_user_logged_in() ) { | |
| 649 | - $menu_item->_invalid = true; | |
| 650 | - } else { | |
| 651 | - $menu_item->url = uwp_get_page_id('forgot_page', true); | |
| 652 | - } | |
| 653 | - break; | |
| 654 | - case $logout_class: | |
| 655 | - if ( ! is_user_logged_in() ) { | |
| 656 | - $menu_item->_invalid = true; | |
| 657 | - } else { | |
| 658 | - $menu_item->url = $this->uwp_logout_url(); | |
| 659 | - } | |
| 660 | - break; | |
| 1023 | + return wp_logout_url( apply_filters( 'uwp_logout_url', $redirect, $custom_redirect ) ); | |
| 1024 | + | |
| 1025 | + } | |
| 1026 | + | |
| 1027 | + /** | |
| 1028 | + * Adds the UsersWP body class to body tag. | |
| 1029 | + * | |
| 1030 | + * @param array $classes Existing class array. | |
| 1031 | + * | |
| 1032 | + * @return array Modified class array. | |
| 1033 | + * @since 1.0.0 | |
| 1034 | + * @package userswp | |
| 1035 | + */ | |
| 1036 | + public function add_body_class( $classes ) { | |
| 1037 | + | |
| 1038 | + if ( is_uwp_page() ) { | |
| 1039 | + $classes[] = 'uwp_page'; | |
| 1040 | + | |
| 1041 | + if ( is_uwp_page( 'register_page' ) ) { | |
| 1042 | + $classes[] = 'uwp_register_page'; | |
| 1043 | + } elseif ( is_uwp_page( 'login_page' ) ) { | |
| 1044 | + $classes[] = 'uwp_login_page'; | |
| 1045 | + } elseif ( is_uwp_page( 'forgot_page' ) ) { | |
| 1046 | + $classes[] = 'uwp_forgot_page'; | |
| 1047 | + } elseif ( is_uwp_page( 'change_page' ) ) { | |
| 1048 | + $classes[] = 'uwp_change_page'; | |
| 1049 | + } elseif ( is_uwp_page( 'reset_page' ) ) { | |
| 1050 | + $classes[] = 'uwp_reset_page'; | |
| 1051 | + } elseif ( is_uwp_page( 'account_page' ) ) { | |
| 1052 | + $classes[] = 'uwp_account_page'; | |
| 1053 | + } elseif ( is_uwp_page( 'profile_page' ) ) { | |
| 1054 | + $classes[] = 'uwp_profile_page'; | |
| 1055 | + } elseif ( is_uwp_page( 'users_page' ) ) { | |
| 1056 | + $classes[] = 'uwp_users_page'; | |
| 1057 | + } | |
| 1058 | + } | |
| 1059 | + | |
| 1060 | + if(is_user_logged_in()){ | |
| 1061 | + $classes[] = 'uwp-user-type-'.uwp_get_register_form_id( get_current_user_id() ); | |
| 661 | 1062 | } |
| 662 | 1063 | |
| 663 | - $menu_item = apply_filters('uwp_setup_nav_menu_item', $menu_item, $menu_classes); | |
| 1064 | + return $classes; | |
| 1065 | + } | |
| 664 | 1066 | |
| 665 | - return $menu_item; | |
| 1067 | + /** | |
| 1068 | + * | |
| 1069 | + * Returns content for author box | |
| 1070 | + * | |
| 1071 | + * @param $content | |
| 1072 | + * | |
| 1073 | + * @return string | |
| 1074 | + */ | |
| 1075 | + public function author_box_page_content( $content ) { | |
| 666 | 1076 | |
| 667 | - } | |
| 1077 | + global $post; | |
| 668 | 1078 | |
| 669 | - /** | |
| 670 | - * Returns the logout url by adding redirect page link. | |
| 671 | - * | |
| 672 | - * @since 1.0.0 | |
| 673 | - * @package userswp | |
| 674 | - * @param null $custom_redirect Redirect page link. | |
| 675 | - * @return string Logout url. | |
| 676 | - */ | |
| 677 | - public function uwp_logout_url( $custom_redirect = null ) { | |
| 1079 | + if ( is_single() ) { | |
| 678 | 1080 | |
| 679 | - $redirect = null; | |
| 1081 | + $author_box_enable_disable = uwp_get_option( 'author_box_enable_disable', 1 ); | |
| 680 | 1082 | |
| 681 | - if ( !empty( $custom_redirect ) ) { | |
| 682 | - $redirect = esc_url( $custom_redirect ); | |
| 683 | - } else if ( uwp_get_option('logout_redirect_to', false) ) { | |
| 684 | - $redirect = esc_url( get_permalink( uwp_get_option('logout_redirect_to', 0) ) ); | |
| 685 | - } | |
| 1083 | + if ( 1 == $author_box_enable_disable ) { | |
| 686 | 1084 | |
| 687 | - return wp_logout_url( apply_filters( 'uwp_logout_url', $redirect, $custom_redirect ) ); | |
| 1085 | + $author_box_display_post_types = uwp_get_option( 'author_box_display_post_types' ); | |
| 688 | 1086 | |
| 689 | - } | |
| 1087 | + if ( ! empty( $post->post_type ) && in_array( $post->post_type, (array) $author_box_display_post_types ) ) { | |
| 690 | 1088 | |
| 691 | - /** | |
| 692 | - * Redirects to UsersWP info page after plugin activation. | |
| 693 | - * | |
| 694 | - * @since 1.0.0 | |
| 695 | - * @package userswp | |
| 696 | - * @return void | |
| 697 | - */ | |
| 698 | - public function uwp_activation_redirect() { | |
| 1089 | + $author_box_display_content = uwp_get_option( 'author_box_display_content' ); | |
| 699 | 1090 | |
| 700 | - if (get_option('uwp_activation_redirect', false)) { | |
| 701 | - delete_option('uwp_activation_redirect'); | |
| 702 | - wp_redirect(admin_url('admin.php?page=userswp&tab=main&subtab=info')); | |
| 703 | - exit; | |
| 1091 | + if ( ! empty( $author_box_display_content ) && 'above_content' === $author_box_display_content ) { | |
| 1092 | + $content = do_shortcode( '[uwp_author_box]' ) . $content; | |
| 1093 | + } else { | |
| 1094 | + $content = $content . do_shortcode( '[uwp_author_box]' ); | |
| 1095 | + } | |
| 704 | 1096 | |
| 705 | - } | |
| 1097 | + // run block content if its available | |
| 1098 | + if ( function_exists( 'do_blocks' ) ) { | |
| 1099 | + $content = do_blocks( $content ); | |
| 1100 | + } | |
| 1101 | + } | |
| 706 | 1102 | |
| 707 | - if ( ! empty( $_GET['force_sync_data'] ) ) { | |
| 708 | - $blog_id = get_current_blog_id(); | |
| 709 | - do_action( 'wp_' . $blog_id . '_uwp_updater_cron' ); | |
| 710 | - wp_safe_redirect( admin_url( 'admin.php?page=userswp' ) ); | |
| 711 | - exit; | |
| 712 | - } | |
| 1103 | + } | |
| 713 | 1104 | |
| 714 | - } | |
| 1105 | + } | |
| 715 | 1106 | |
| 716 | - /** | |
| 717 | - * Prints UsersWP fields in WP-Admin Users Edit page. | |
| 718 | - * | |
| 719 | - * @since 1.0.0 | |
| 720 | - * @package userswp | |
| 721 | - * @param object $user User Object. | |
| 722 | - */ | |
| 723 | - public function get_profile_extra_admin_edit($user) { | |
| 724 | - echo $this->get_profile_extra_edit($user); | |
| 725 | - } | |
| 1107 | + return $content; | |
| 1108 | + } | |
| 726 | 1109 | |
| 727 | - /** | |
| 728 | - * Gets UsersWP fields in WP-Admin Users Edit page. | |
| 729 | - * | |
| 730 | - * @since 1.0.0 | |
| 731 | - * @package userswp | |
| 732 | - * @param object $user User Object. | |
| 733 | - * @return string HTML string. | |
| 734 | - */ | |
| 735 | - public function get_profile_extra_edit($user) { | |
| 736 | - ob_start(); | |
| 737 | - global $wpdb; | |
| 738 | - $table_name = uwp_get_table_prefix() . 'uwp_form_fields'; | |
| 739 | - $excluded_fields = apply_filters('uwp_exclude_edit_profile_fields', array()); | |
| 740 | - $query = "SELECT * FROM " . $table_name . " WHERE form_type = 'account' AND is_default = '0'"; | |
| 741 | - if(is_array($excluded_fields) && count($excluded_fields) > 0){ | |
| 742 | - $query .= 'AND htmlvar_name NOT IN ('.implode(',', $excluded_fields).')'; | |
| 743 | - } | |
| 744 | - $query .= ' ORDER BY sort_order ASC'; | |
| 745 | - $fields = $wpdb->get_results($query); | |
| 746 | - if ($fields) { | |
| 747 | - ?> | |
| 1110 | + /** | |
| 1111 | + * Adds form html for privacy fields in account page. | |
| 1112 | + * | |
| 1113 | + * @param string $type Form type. | |
| 1114 | + * | |
| 1115 | + * @return void | |
| 1116 | + * @since 1.0.0 | |
| 1117 | + * @package userswp | |
| 1118 | + * | |
| 1119 | + */ | |
| 1120 | + public function privacy_edit_form_display( $type ) { | |
| 1121 | + if ( $type == 'privacy' ) { | |
| 1122 | + $make_profile_private = uwp_can_make_profile_private(); | |
| 1123 | + echo '<div class="uwp-account-form">'; | |
| 1124 | + $extra_where = "AND is_public='2'"; | |
| 1125 | + $fields = get_account_form_fields( $extra_where ); | |
| 1126 | + $fields = apply_filters( 'uwp_account_privacy_fields', $fields ); | |
| 1127 | + $user_id = get_current_user_id(); | |
| 1128 | + $form_id = uwp_get_register_form_id( $user_id ); | |
| 1129 | + $design_style = uwp_get_option( "design_style", "bootstrap" ); | |
| 1130 | + $bs_form_group = $design_style ? "form-group mb-3 row" : ""; | |
| 1131 | + $bs_form_control = $design_style ? "form-control" : ""; | |
| 1132 | + $bs_btn_class = $design_style ? "btn btn-primary btn-block text-uppercase" : ""; | |
| 1133 | + ?> | |
| 748 | 1134 | <div class="uwp-profile-extra"> |
| 749 | - <table class="uwp-profile-extra-table form-table"> | |
| 750 | - <?php | |
| 751 | - foreach ($fields as $field) { | |
| 1135 | + <div class="uwp-profile-extra-div form-table"> | |
| 1136 | + <form class="uwp-account-form uwp_form" method="post"> | |
| 1137 | + <?php if ( $fields ) { ?> | |
| 1138 | + <div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 1139 | + <div class="uwp-profile-extra-key col" style="font-weight: bold;"> | |
| 1140 | + <?php esc_attr_e( "Field", "userswp" ) ?> | |
| 1141 | + </div> | |
| 1142 | + <div class="uwp-profile-extra-value col" style="font-weight: bold;"> | |
| 1143 | + <?php esc_attr_e( "Is Public?", "userswp" ) ?> | |
| 1144 | + </div> | |
| 1145 | + </div> | |
| 1146 | + <?php foreach ( $fields as $field ) { ?> | |
| 1147 | + <div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 1148 | + <div class="uwp-profile-extra-key col"><?php echo esc_attr( $field->site_title ); ?> | |
| 1149 | + <span class="uwp-profile-extra-sep">:</span></div> | |
| 1150 | + <div class="uwp-profile-extra-value col"> | |
| 1151 | + <?php | |
| 1152 | + $field_name = $field->htmlvar_name . '_privacy'; | |
| 1153 | + $value = uwp_get_usermeta( $user_id, $field_name, false ); | |
| 1154 | + if ( $value === false ) { | |
| 1155 | + $value = 'yes'; | |
| 1156 | + } | |
| 1157 | + ?> | |
| 1158 | + <select name="<?php echo esc_attr( $field_name ); ?>" | |
| 1159 | + class="uwp_privacy_field aui-select2 <?php echo esc_attr( $bs_form_control ); ?>" | |
| 1160 | + style="margin: 0;"> | |
| 1161 | + <option value="no" <?php selected( $value, "no" ); ?>><?php esc_attr_e( "No", "userswp" ) ?></option> | |
| 1162 | + <option value="yes" <?php selected( $value, "yes" ); ?>><?php esc_attr_e( "Yes", "userswp" ) ?></option> | |
| 1163 | + </select> | |
| 1164 | + </div> | |
| 1165 | + </div> | |
| 1166 | + <?php } | |
| 1167 | + } | |
| 752 | 1168 | |
| 753 | - // Icon | |
| 754 | - $icon = uwp_get_field_icon( $field->field_icon ); | |
| 1169 | + global $wpdb; | |
| 1170 | + $tabs_table_name = uwp_get_table_prefix() . 'uwp_profile_tabs'; | |
| 1171 | + $tabs = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $tabs_table_name . " WHERE form_type = %s AND user_decided = 1 AND form_id = %s ORDER BY sort_order ASC", array('profile-tabs', $form_id) ) ); | |
| 755 | 1172 | |
| 756 | - if ($field->field_type == 'fieldset') { | |
| 757 | - ?> | |
| 758 | - <tr style="margin: 0; padding: 0"> | |
| 759 | - <th class="uwp-profile-extra-key" style="margin: 0; padding: 0"><h3 style="margin: 10px 0;"><?php echo $icon.$field->site_title; ?></h3></th> | |
| 760 | - <td></td> | |
| 761 | - </tr> | |
| 762 | - <?php | |
| 763 | - } else { ?> | |
| 764 | - <tr> | |
| 765 | - <th class="uwp-profile-extra-key"><?php echo $icon.$field->site_title; ?></th> | |
| 766 | - <td class="uwp-profile-extra-value"> | |
| 767 | - <?php $this->uwp_template_fields_html($field, 'account', $user->ID); ?> | |
| 768 | - </td> | |
| 769 | - </tr> | |
| 770 | - <?php | |
| 771 | - } | |
| 772 | - } | |
| 773 | - ?> | |
| 774 | - </table> | |
| 1173 | + if ( $tabs ) { ?> | |
| 1174 | + <div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 1175 | + <div class="uwp-profile-extra-key col" style="font-weight: bold;"> | |
| 1176 | + <?php esc_attr_e( "Tab Name", "userswp" ) ?> | |
| 1177 | + </div> | |
| 1178 | + <div class="uwp-profile-extra-value col" style="font-weight: bold;"> | |
| 1179 | + <?php esc_attr_e( "Privacy", "userswp" ) ?> | |
| 1180 | + </div> | |
| 1181 | + </div> | |
| 1182 | + <?php } | |
| 1183 | + | |
| 1184 | + foreach ( $tabs as $tab ) { ?> | |
| 1185 | + <div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>"> | |
| 1186 | + <div class="uwp-profile-extra-key col"><?php esc_attr_e( $tab->tab_name, 'userswp' ); ?> | |
| 1187 | + <span class="uwp-profile-extra-sep">:</span></div> | |
| 1188 | + <div class="uwp-profile-extra-value col"> | |
| 1189 | + <?php | |
| 1190 | + $field_name = $tab->tab_key . '_tab_privacy'; | |
| 1191 | + $value = uwp_get_usermeta( $user_id, $field_name, '' ); | |
| 1192 | + | |
| 1193 | + $privacy_options = array( | |
| 1194 | + 0 => __( "Anyone", "userswp" ), | |
| 1195 | + 1 => __( "Logged in", "userswp" ), | |
| 1196 | + 2 => __( "Author only", "userswp" ), | |
| 1197 | + ); | |
| 1198 | + | |
| 1199 | + // Admin default | |
| 1200 | + $admin_privacy = isset( $tab->tab_privacy ) ? absint( $tab->tab_privacy ) : 0; | |
| 1201 | + $privacy_options = apply_filters( 'uwp_tab_privacy_options', $privacy_options, $tab ); | |
| 1202 | + | |
| 1203 | + if ( empty( $value ) ) { | |
| 1204 | + $value = $admin_privacy; | |
| 1205 | + } | |
| 1206 | + ?> | |
| 1207 | + <select name="<?php echo esc_attr( $field_name ); ?>" | |
| 1208 | + class="uwp_tab_privacy_field aui-select2 <?php echo esc_attr( $bs_form_control ); ?>" | |
| 1209 | + style="margin: 0;"> | |
| 1210 | + <?php | |
| 1211 | + foreach ( $privacy_options as $key => $val ) { | |
| 1212 | + | |
| 1213 | + $default = ''; | |
| 1214 | + if ( $admin_privacy == $key ) { | |
| 1215 | + $default = __( ' (Default)', 'userswp' ); | |
| 1216 | + } | |
| 1217 | + echo '<option value="' . esc_attr( $key ) . '"' . selected( $value, $key, false ) . '>' . esc_attr( $val . $default ) . '</option>'; | |
| 1218 | + } | |
| 1219 | + ?> | |
| 1220 | + </select> | |
| 1221 | + </div> | |
| 1222 | + </div> | |
| 1223 | + <?php } | |
| 1224 | + | |
| 1225 | + $value = get_user_meta( $user_id, 'uwp_hide_from_listing', true ); ?> | |
| 1226 | + <div class="uwp-profile-extra-wrap"> | |
| 1227 | + <div id="uwp_hide_from_listing" class="uwp_hide_from_listing"> | |
| 1228 | + <input name="uwp_hide_from_listing" class="" <?php checked( $value, "1", true ); ?> | |
| 1229 | + type="checkbox" | |
| 1230 | + value="1"><?php esc_attr_e( 'Hide profile from the users listing page.', 'userswp' ); ?> | |
| 1231 | + </div> | |
| 1232 | + </div> | |
| 1233 | + <?php | |
| 1234 | + do_action( 'uwp_after_privacy_form_fields', $fields ); | |
| 1235 | + if ( $make_profile_private ) { | |
| 1236 | + $field_name = 'uwp_make_profile_private'; | |
| 1237 | + $value = get_user_meta( $user_id, $field_name, true ); | |
| 1238 | + if ( $value === false ) { | |
| 1239 | + $value = '0'; | |
| 1240 | + } | |
| 1241 | + ?> | |
| 1242 | + <div id="uwp_make_profile_private" class=" uwp_make_profile_private_row"> | |
| 1243 | + <input type="hidden" name="uwp_make_profile_private" value="0"> | |
| 1244 | + <input name="uwp_make_profile_private" class="" <?php checked( $value, "1", true ); ?> | |
| 1245 | + type="checkbox" value="1"> | |
| 1246 | + <?php esc_attr_e( 'Make the whole profile private', 'userswp' ); ?> | |
| 1247 | + </div> | |
| 1248 | + <?php | |
| 1249 | + } | |
| 1250 | + ?> | |
| 1251 | + <input type="hidden" name="uwp_privacy_nonce" | |
| 1252 | + value="<?php echo esc_attr( wp_create_nonce( 'uwp-privacy-nonce' ) ); ?>"/> | |
| 1253 | + <input name="uwp_privacy_submit" class="<?php echo esc_attr( $bs_btn_class ); ?>" | |
| 1254 | + value="<?php esc_attr_e( 'Submit', 'userswp' ); ?>" type="submit"> | |
| 1255 | + </form> | |
| 1256 | + </div> | |
| 775 | 1257 | </div> |
| 776 | - <?php | |
| 777 | - } | |
| 778 | - $output = ob_get_contents(); | |
| 779 | - ob_end_clean(); | |
| 780 | - return trim($output); | |
| 781 | - } | |
| 1258 | + <?php | |
| 1259 | + echo '</div>'; | |
| 1260 | + } | |
| 1261 | + } | |
| 782 | 1262 | |
| 783 | - /** | |
| 784 | - * Adds the UsersWP body class to body tag. | |
| 785 | - * | |
| 786 | - * @since 1.0.0 | |
| 787 | - * @package userswp | |
| 788 | - * @param array $classes Existing class array. | |
| 789 | - * @return array Modified class array. | |
| 790 | - */ | |
| 791 | - public function uwp_add_body_class( $classes ) { | |
| 1263 | + /** | |
| 1264 | + * Redirects the user to login page when email not confirmed. | |
| 1265 | + * | |
| 1266 | + * @param string $username Username. | |
| 1267 | + * @param object $user User object. | |
| 1268 | + * | |
| 1269 | + * @return void | |
| 1270 | + * @package userswp | |
| 1271 | + * | |
| 1272 | + * @since 1.0.0 | |
| 1273 | + */ | |
| 1274 | + public function unconfirmed_login_redirect( $username, $user ) { | |
| 1275 | + if ( ! is_wp_error( $user ) ) { | |
| 1276 | + $mod_value = get_user_meta( $user->ID, 'uwp_mod', true ); | |
| 1277 | + if ( $mod_value == 'email_unconfirmed' ) { | |
| 1278 | + if ( ! in_array( 'administrator', $user->roles ) ) { | |
| 1279 | + $login_page = uwp_get_page_id( 'login_page', false ); | |
| 1280 | + if ( $login_page ) { | |
| 1281 | + $redirect_to = add_query_arg( array( | |
| 1282 | + 'uwp_err' => 'act_pending', | |
| 1283 | + 'user_id' => $user->ID | |
| 1284 | + ), get_permalink( $login_page ) ); | |
| 1285 | + wp_destroy_current_session(); | |
| 1286 | + wp_clear_auth_cookie(); | |
| 1287 | + if ( wp_doing_ajax() ) { | |
| 1288 | + global $userswp; | |
| 1289 | + $message = $userswp->notices->form_notice_by_key( 'act_pending', false, $user->ID ); | |
| 1290 | + wp_send_json_error( $message ); | |
| 1291 | + } else { | |
| 1292 | + wp_redirect( $redirect_to ); | |
| 1293 | + } | |
| 1294 | + exit(); | |
| 1295 | + } | |
| 1296 | + } | |
| 1297 | + } | |
| 1298 | + } | |
| 1299 | + } | |
| 792 | 1300 | |
| 793 | - if ( is_uwp_page() ) { | |
| 794 | - $classes[] = 'uwp_page'; | |
| 795 | - } | |
| 1301 | + /** | |
| 1302 | + * Oxygen override theme template. | |
| 1303 | + * | |
| 1304 | + * @since 1.2.2.15 | |
| 1305 | + * | |
| 1306 | + * @param string $located Located template. | |
| 1307 | + * @param string $template_name Template name. | |
| 1308 | + * @param array $located Template args. | |
| 1309 | + * @param string $template_path Template path. | |
| 1310 | + * @param string $default_path Template default path. | |
| 1311 | + * @return string Located template. | |
| 1312 | + */ | |
| 1313 | + public function oxygen_override_template( $located, $template_name, $args, $template_path, $default_path ) { | |
| 1314 | + if ( $_located = $this->oxygen_locate_template( $template_name ) ) { | |
| 1315 | + $located = $_located; | |
| 1316 | + } | |
| 796 | 1317 | |
| 797 | - return $classes; | |
| 798 | - } | |
| 1318 | + return $located; | |
| 1319 | + } | |
| 1320 | + | |
| 1321 | + /** | |
| 1322 | + * Oxygen locate theme template. | |
| 1323 | + * | |
| 1324 | + * @since 1.2.2.15 | |
| 1325 | + * | |
| 1326 | + * @param string $template The template. | |
| 1327 | + * @return string The theme template. | |
| 1328 | + */ | |
| 1329 | + public function oxygen_locate_template( $template ) { | |
| 1330 | + $located = ''; | |
| 1331 | + | |
| 1332 | + if ( ! $template ) { | |
| 1333 | + return $located; | |
| 1334 | + } | |
| 1335 | + | |
| 1336 | + $has_filter = has_filter( 'template', 'ct_oxygen_template_name' ); | |
| 1337 | + | |
| 1338 | + // Remove template filter | |
| 1339 | + if ( $has_filter ) { | |
| 1340 | + remove_filter( 'template', 'ct_oxygen_template_name' ); | |
| 1341 | + } | |
| 1342 | + | |
| 1343 | + $_located = $this->get_theme_template_path() . '/' . $template; | |
| 1344 | + | |
| 1345 | + if ( file_exists( $_located ) ) { | |
| 1346 | + $located = $_located; | |
| 1347 | + } | |
| 1348 | + | |
| 1349 | + // Add template filter | |
| 1350 | + if ( $has_filter ) { | |
| 1351 | + add_filter( 'template', 'ct_oxygen_template_name' ); | |
| 1352 | + } | |
| 1353 | + | |
| 1354 | + return $located; | |
| 1355 | + } | |
| 1356 | + | |
| 1357 | + /** | |
| 1358 | + * Get the UsersWP templates theme path. | |
| 1359 | + * | |
| 1360 | + * @since 1.2.2.15 | |
| 1361 | + * | |
| 1362 | + * @return string Template path. | |
| 1363 | + */ | |
| 1364 | + public static function get_theme_template_path() { | |
| 1365 | + $template = get_template(); | |
| 1366 | + $theme_root = get_theme_root( $template ); | |
| 1367 | + | |
| 1368 | + $theme_template_path = $theme_root . '/' . $template . '/' . untrailingslashit( uwp_get_theme_template_dir_name() ); | |
| 1369 | + | |
| 1370 | + return $theme_template_path; | |
| 1371 | + } | |
| 1372 | + | |
| 1373 | + /** | |
| 1374 | + * Check & unset the_content hook. | |
| 1375 | + * | |
| 1376 | + * @since 1.2.13 | |
| 1377 | + * | |
| 1378 | + * @param string $content The content. | |
| 1379 | + * @return string The post content. | |
| 1380 | + */ | |
| 1381 | + public function set_the_content_hook( $content ) { | |
| 1382 | + global $wp_query, $post, $uwp_set_wpautop; | |
| 1383 | + | |
| 1384 | + // Prevent empty p tags on block theme. | |
| 1385 | + if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() && ! empty( $wp_query ) && ! empty( $post ) && $post->ID == get_queried_object_id() && is_uwp_page() ) { | |
| 1386 | + if ( $has_filter = has_filter( 'the_content', 'wpautop' ) ) { | |
| 1387 | + $uwp_set_wpautop = $has_filter; | |
| 1388 | + | |
| 1389 | + remove_filter( 'the_content', 'wpautop' ); | |
| 1390 | + } | |
| 1391 | + } | |
| 1392 | + | |
| 1393 | + return $content; | |
| 1394 | + } | |
| 799 | 1395 | } |