diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index 05910f04..4168dda6 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -4,6 +4,7 @@ on: push: branches: - master + - development/2.6.3 jobs: hookdocs: diff --git a/includes/core/class-account.php b/includes/core/class-account.php index 446a5cb2..f8bea1b5 100644 --- a/includes/core/class-account.php +++ b/includes/core/class-account.php @@ -472,7 +472,7 @@ if ( ! class_exists( 'um\core\Account' ) ) { */ function tab_link( $id ) { - if ( get_option( 'permalink_structure' ) ) { + if ( UM()->is_permalinks ) { $url = trailingslashit( untrailingslashit( um_get_core_page( 'account' ) ) ); $url = $url . $id . '/'; diff --git a/includes/core/class-external-integrations.php b/includes/core/class-external-integrations.php index 73cdaee1..dc9b716f 100644 --- a/includes/core/class-external-integrations.php +++ b/includes/core/class-external-integrations.php @@ -31,7 +31,8 @@ if ( ! class_exists( 'um\core\External_Integrations' ) ) { add_action( 'um_access_fix_external_post_content', array( &$this, 'forumwp_fix' ), 11 ); add_action( 'um_access_fix_external_post_content', array( &$this, 'woocommerce_fix' ), 12 ); - add_filter( 'um_permalinks_profile_url', array( &$this, 'um_localize_profile_url' ), 10, 3 ); + add_filter( 'um_external_profile_url', array( &$this, 'um_localize_profile_url' ), 10, 2 ); + add_filter( 'um_get_current_page_url', array( &$this, 'um_localize_profile_nav_url' ), 10, 2 ); add_filter( 'icl_ls_languages', array( &$this, 'um_core_page_wpml_permalink' ), 10, 1 ); // Integration for the "Transposh Translation Filter" plugin @@ -175,47 +176,70 @@ if ( ! class_exists( 'um\core\External_Integrations' ) ) { return $single_template; } - /** * Change user profile URL for WPML compatibility. * - * @hook um_permalinks_profile_url - * @see um\core\Permalinks::profile_permalink() + * @hook um_external_profile_url + * @see \um\core\Permalinks::profile_permalink() * - * @param string $profile_url Profile URL. - * @param int $page_id Profile Page ID. - * @param string $slug Profile slug + * @param bool|string $profile_url Profile URL. + * @param string $slug Profile slug. * * @return string */ - public function um_localize_profile_url( $profile_url, $page_id, $slug = '' ) { + public function um_localize_profile_url( $profile_url, $slug ) { + if ( ! $this->is_wpml_active() ) { + return $profile_url; + } - if ( $this->is_wpml_active() && um_profile_id() ) { - $lang_post_id = apply_filters( 'wpml_object_id', $page_id, 'page', true ); + $page_id = UM()->config()->permalinks['user']; + $lang_post_id = apply_filters( 'wpml_object_id', $page_id, 'page', true ); - if ( $lang_post_id && $lang_post_id !== $page_id ) { - if ( empty( $slug ) ) { - $permalink_base = UM()->options()->get( 'permalink_base' ); - $slug = strtolower( get_user_meta( um_profile_id(), "um_user_profile_url_slug_{$permalink_base}", true ) ); - } - $permalink_type = get_option( 'permalink_structure' ); - $user_page_url = get_permalink( $lang_post_id ); + if ( $lang_post_id && $lang_post_id !== $page_id ) { + $user_page_url = get_permalink( $lang_post_id ); - if ( $permalink_type ) { - if ( false === strpos( $user_page_url, '?' ) ){ - $profile_url = trailingslashit( $user_page_url ) . trailingslashit( $slug ); - } else { - $profile_url = str_replace( '?', trailingslashit( $slug ) . '?', $user_page_url ); - } + if ( UM()->is_permalinks ) { + if ( false === strpos( $user_page_url, '?' ) ) { + $profile_url = trailingslashit( $user_page_url ) . trailingslashit( $slug ); } else { - $profile_url = add_query_arg( 'um_user', strtolower( $slug ), $user_page_url ); + $profile_url = str_replace( '?', trailingslashit( $slug ) . '?', $user_page_url ); } + } else { + $profile_url = add_query_arg( 'um_user', strtolower( $slug ), $user_page_url ); } } return $profile_url; } + /** + * Change current URL for WPML compatibility. + * + * Note: It's used for User Profile nav links fix + * + * @hook um_get_current_page_url + * @see \um\core\Permalinks::get_current_url() + * + * @param string $page_url Current URL. + * @param bool $no_query_params Ignore $_GET attributes in URL. "true" == ignore. + * + * @return string + */ + public function um_localize_profile_nav_url( $page_url, $no_query_params ) { + if ( ! $this->is_wpml_active() ) { + return $page_url; + } + + if ( false === $no_query_params ) { + return $page_url; + } + + if ( ! empty( $_GET['lang'] ) ) { + $page_url = add_query_arg( 'lang', sanitize_key( $_GET['lang'] ), $page_url ); + } + + return $page_url; + } /** * Filters the displayed languages of the WPML language switcher. @@ -228,23 +252,20 @@ if ( ! class_exists( 'um\core\External_Integrations' ) ) { * @return array */ public function um_core_page_wpml_permalink( $array ) { - if ( $this->is_wpml_active() && um_is_core_page( 'user' ) && is_array( $array ) ) { global $sitepress; - $current_language = apply_filters( 'wpml_current_language', null ); - $page_id = UM()->config()->permalinks[ 'user' ]; - $permalink_type = get_option( 'permalink_structure' ); - $permalink_base = UM()->options()->get( 'permalink_base' ); - $slug = strtolower( get_user_meta( um_profile_id(), "um_user_profile_url_slug_{$permalink_base}", true ) ); + $current_language = wpml_get_current_language(); + $slug = strtolower( UM()->user()->get_profile_slug( um_profile_id() ) ); foreach ( $array as $lang_code => $arr ) { $sitepress->switch_lang( $lang_code ); - $lang_post_id = apply_filters( 'wpml_object_id', $page_id, 'page', true ); + + $lang_post_id = apply_filters( 'wpml_object_id', UM()->config()->permalinks['user'], 'page', true ); $user_page_url = get_permalink( $lang_post_id ); - if ( $permalink_type ) { - if ( false === strpos( $user_page_url, '?' ) ){ + if ( UM()->is_permalinks ) { + if ( false === strpos( $user_page_url, '?' ) ) { $profile_url = trailingslashit( $user_page_url ) . trailingslashit( $slug ); } else { $profile_url = str_replace( '?', trailingslashit( $slug ) . '?', $user_page_url ); @@ -262,7 +283,6 @@ if ( ! class_exists( 'um\core\External_Integrations' ) ) { return $array; } - /** * Check if WPML is active * diff --git a/includes/core/class-permalinks.php b/includes/core/class-permalinks.php index f125f938..59f9e6cd 100644 --- a/includes/core/class-permalinks.php +++ b/includes/core/class-permalinks.php @@ -1,35 +1,32 @@ current_url = $this->get_current_url(); } - - /** - * SEO canonical href bugfix - * - * @deprecated since version 2.1.7 - * - * @see function um_profile_remove_wpseo() - */ - function um_rel_canonical_() { - global $wp_the_query; - - if ( ! is_singular() ) - return; - - /** - * UM hook - * - * @type filter - * @title um_allow_canonical__filter - * @description Allow canonical - * @input_vars - * [{"var":"$allow_canonical","type":"bool","desc":"Allow?"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $enable_canonical = apply_filters( "um_allow_canonical__filter", true ); - - if( ! $enable_canonical ) - return; - - if ( !$id = $wp_the_query->get_queried_object_id() ) - return; - - if ( UM()->config()->permalinks['user'] == $id ) { - $link = esc_url( $this->get_current_url() ); - echo "\n"; - return; - } - - $link = get_permalink( $id ); - if ( $page = get_query_var( 'cpage' ) ){ - $link = get_comments_pagenum_link( $page ); - echo "\n"; - } - - } - - /** * Get query as array * * @return array */ - function get_query_array() { + public function get_query_array() { $parts = parse_url( $this->get_current_url() ); if ( isset( $parts['query'] ) ) { parse_str( $parts['query'], $query ); @@ -118,66 +56,61 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) { return array(); } - /** * Get current URL anywhere * * @param bool $no_query_params * - * @return mixed|void + * @return string */ - function get_current_url( $no_query_params = false ) { + public function get_current_url( $no_query_params = false ) { //use WP native function for fill $_SERVER variables by correct values wp_fix_server_vars(); //check if WP-CLI there isn't set HTTP_HOST, use localhost instead if ( defined( 'WP_CLI' ) && WP_CLI ) { $host = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : 'localhost'; - } else{ - if ( isset( $_SERVER['HTTP_HOST'] ) ) { - $host = $_SERVER['HTTP_HOST']; - }else{ - $host = 'localhost'; - } - } + } else { + if ( isset( $_SERVER['HTTP_HOST'] ) ) { + $host = $_SERVER['HTTP_HOST']; + } else { + $host = 'localhost'; + } + } $page_url = ( is_ssl() ? 'https://' : 'http://' ) . $host . $_SERVER['REQUEST_URI']; - if ( $no_query_params == true ) { + if ( false !== $no_query_params ) { $page_url = strtok( $page_url, '?' ); } /** - * UM hook + * Filters current page URL. * - * @type filter - * @title um_get_current_page_url - * @description Change current page URL - * @input_vars - * [{"var":"$page_url","type":"string","desc":"Page URL"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * Add your custom $_GET attribute to all links. + * function my_um_get_current_page_url( $page_url, $no_query_params ) { + * $page_url = add_query_arg( '{attr_value}', '{attr_key}', $page_url ); // replace to your custom value and key. * return $page_url; * } - * ?> + * add_filter( 'um_get_current_page_url', 'my_um_get_current_page_url', 10, 2 ); */ - return apply_filters( 'um_get_current_page_url', $page_url ); + return apply_filters( 'um_get_current_page_url', $page_url, $no_query_params ); } - /** * Activates an account via email */ public function activate_account_via_email_link() { if ( isset( $_REQUEST['act'] ) && 'activate_via_email' === sanitize_key( $_REQUEST['act'] ) && isset( $_REQUEST['hash'] ) && is_string( $_REQUEST['hash'] ) && strlen( $_REQUEST['hash'] ) == 40 && - isset( $_REQUEST['user_id'] ) && is_numeric( $_REQUEST['user_id'] ) ) { // valid token + isset( $_REQUEST['user_id'] ) && is_numeric( $_REQUEST['user_id'] ) ) { // valid token $user_id = absint( $_REQUEST['user_id'] ); delete_option( "um_cache_userdata_{$user_id}" ); @@ -238,18 +171,15 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) { $redirect = apply_filters( 'um_after_email_confirmation_redirect', $redirect, $user_id, $login ); exit( wp_redirect( $redirect ) ); - } - } - /** * Makes an activate link for any user * * @return bool|string */ - function activate_url() { + public function activate_url() { if ( ! um_user( 'account_secret_hash' ) ) { return false; } @@ -283,17 +213,15 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) { return $url; } - /** * Checks for UM query strings */ - function check_for_querystrings() { + public function check_for_querystrings() { if ( isset( $_REQUEST['message'] ) ) { UM()->shortcodes()->message_mode = true; } } - /** * Add a query param to url * @@ -302,12 +230,11 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) { * * @return string */ - function add_query( $key, $value ) { + public function add_query( $key, $value ) { $this->current_url = add_query_arg( $key, $value, $this->get_current_url() ); return $this->current_url; } - /** * Remove a query param from url * @@ -316,18 +243,17 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) { * * @return string */ - function remove_query( $key, $value ) { + public function remove_query( $key, $value ) { $this->current_url = remove_query_arg( $key, $this->current_url ); return $this->current_url; } - /** * @param $slug * * @return int|null|string */ - function slug_exists_user_id( $slug ) { + public function slug_exists_user_id( $slug ) { global $wpdb; $permalink_base = UM()->options()->get( 'permalink_base' ); @@ -348,82 +274,93 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) { return false; } - /** * Get Profile Permalink * * @param string $slug - * @return string $profile_url + * + * @return string */ - function profile_permalink( $slug ) { + public function profile_permalink( $slug ) { + /** + * Filters user profile URL externally with own logic. + * + * @since 2.6.3 + * @hook um_external_profile_url + * + * @param {bool|string} $profile_url Profile URL. + * @param {string} $slug User profile slug. + * + * @return {string} Profile URL. + * + * @example