From 936190d93e796f586dea9bea0f8db84021256309 Mon Sep 17 00:00:00 2001 From: Mykyta Synelnikov Date: Fri, 9 Jun 2023 12:28:15 +0300 Subject: [PATCH] - updated using get_option( 'permalink_structure' ) to UM()->is_permalinks which is the same; - code review for WPML profile links; - fixed User Profile tabs and subtabs link with WPML arguments in link; - added deprecated function to outdated `um_rel_canonical_()`. @todo remove since 2.7.0; - fixed WPCS in class-permalinks.php; - deprecated `um_localize_permalink_filter`. Use `post_link` instead; - added new hooks: `um_profile_permalink`,`um_external_profile_url` and new docs for them; - added new hookdocs for `um_get_current_page_url`; - temporarily added development/2.6.3 branch to build-docs.yml --- .github/workflows/build-docs.yml | 1 + includes/core/class-account.php | 2 +- includes/core/class-external-integrations.php | 88 ++-- includes/core/class-permalinks.php | 392 +++++++++--------- 4 files changed, 246 insertions(+), 237 deletions(-) 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 Change profile URL to your custom link and ignore native profile permalink handlers. + * function my_um_external_profile_url( $profile_url, $slug ) { + * $profile_url = '{some your custom URL}'; // replace to your custom link. + * return $profile_url; + * } + * add_filter( 'um_external_profile_url', 'my_um_external_profile_url', 10, 2 ); + */ + $external_profile_url = apply_filters( 'um_external_profile_url', false, $slug ); + if ( false !== $external_profile_url ) { + return ! empty( $external_profile_url ) ? $external_profile_url : ''; + } - $page_id = UM()->config()->permalinks['user']; + $page_id = UM()->config()->permalinks['user']; $profile_url = get_permalink( $page_id ); /** - * UM hook + * Filters the base URL of the UM profile page. * - * @type filter - * @title um_localize_permalink_filter - * @description Change user profile URL - * @input_vars - * [{"var":"$profile_url","type":"string","desc":"Profile URL"}, - * {"var":"$page_id","type":"int","desc":"Profile Page ID"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * 'post_link' instead. + * @hook um_localize_permalink_filter + * @todo fully remove since 2.7.0 + * + * @param {string} $profile_url Profile URL. + * @param {int} $page_id Profile Page ID. + * + * @return {string} Profile URL. + * + * @example Change profile base URL to your custom link. * function my_localize_permalink( $profile_url, $page_id ) { - * // your code here + * $profile_url = '{some your custom URL}'; // replace to your custom link. * return $profile_url; * } - * ?> + * add_filter( 'um_localize_permalink_filter', 'my_localize_permalink', 10, 2 ); */ $profile_url = apply_filters( 'um_localize_permalink_filter', $profile_url, $page_id ); - if ( get_option( 'permalink_structure' ) ) { - - $profile_url = trailingslashit( untrailingslashit( $profile_url ) ); - $profile_url = $profile_url . strtolower( $slug ). '/'; - + if ( UM()->is_permalinks ) { + $profile_url = trailingslashit( untrailingslashit( $profile_url ) ); + $profile_url .= trailingslashit( strtolower( $slug ) ); } else { - - $profile_url = add_query_arg( 'um_user', strtolower( $slug ), $profile_url ); - + $profile_url = add_query_arg( 'um_user', strtolower( $slug ), $profile_url ); } /** - * UM hook + * Filters user profile URL. * - * @type filter - * @title um_permalinks_profile_url - * @description Change user profile URL. - * @input_vars - * [{"var":"$profile_url","type":"string","desc":"Profile URL"}, - * {"var":"$page_id","type":"int","desc":"Profile Page ID"}, - * {"var":"$slug","type":"string","desc":"Profile slug"}] - * @change_log - * ["Since: 2.6.2"] - * @usage - * - * @example - * Change profile URL to your custom link. + * function my_um_profile_permalink( $profile_url, $page_id, $slug ) { + * $profile_url = '{some your custom URL}'; // replace to your custom link. * return $profile_url; * } - * ?> + * add_filter( 'um_profile_permalink', 'my_um_profile_permalink', 10, 3 ); */ - $profile_url = apply_filters( 'um_permalinks_profile_url', $profile_url, $page_id, $slug ); + $profile_url = apply_filters( 'um_profile_permalink', $profile_url, $page_id, $slug ); return ! empty( $profile_url ) ? $profile_url : ''; } - /** * Generate profile slug * @@ -432,41 +369,38 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) { * @param string $last_name * @return string */ - function profile_slug( $full_name, $first_name, $last_name ){ - + public function profile_slug( $full_name, $first_name, $last_name ) { $permalink_base = UM()->options()->get( 'permalink_base' ); $user_in_url = ''; - $full_name = str_replace("'", "", $full_name ); - $full_name = str_replace("&", "", $full_name ); - $full_name = str_replace("/", "", $full_name ); + $full_name = str_replace( "'", "", $full_name ); + $full_name = str_replace( "&", "", $full_name ); + $full_name = str_replace( "/", "", $full_name ); - switch( $permalink_base ) { + switch ( $permalink_base ) { case 'name': // dotted - $full_name_slug = $full_name; $difficulties = 0; - - if( strpos( $full_name, '.' ) > -1 ){ - $full_name = str_replace(".", "_", $full_name ); + if ( strpos( $full_name, '.' ) > -1 ) { + $full_name = str_replace( ".", "_", $full_name ); $difficulties++; } $full_name = strtolower( str_replace( " ", ".", $full_name ) ); - if( strpos( $full_name, '_.' ) > -1 ){ - $full_name = str_replace('_.', '_', $full_name ); + if ( strpos( $full_name, '_.' ) > -1 ) { + $full_name = str_replace( '_.', '_', $full_name ); $difficulties++; } - $full_name_slug = str_replace( '-' , '.', $full_name_slug ); - $full_name_slug = str_replace( ' ' , '.', $full_name_slug ); - $full_name_slug = str_replace( '..' , '.', $full_name_slug ); + $full_name_slug = str_replace( '-', '.', $full_name_slug ); + $full_name_slug = str_replace( ' ', '.', $full_name_slug ); + $full_name_slug = str_replace( '..', '.', $full_name_slug ); - if( strpos( $full_name, '.' ) > -1 ){ - $full_name = str_replace('.', ' ', $full_name ); + if ( strpos( $full_name, '.' ) > -1 ) { + $full_name = str_replace( '.', ' ', $full_name ); $difficulties++; } @@ -475,76 +409,73 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) { break; case 'name_dash': // dashed - $difficulties = 0; $full_name_slug = strtolower( $full_name ); // if last name has dashed replace with underscore - if( strpos( $last_name, '-') > -1 && strpos( $full_name, '-' ) > -1 ){ + if ( strpos( $last_name, '-' ) > -1 && strpos( $full_name, '-' ) > -1 ) { $difficulties++; - $full_name = str_replace('-', '_', $full_name ); + $full_name = str_replace( '-', '_', $full_name ); } // if first name has dashed replace with underscore - if( strpos( $first_name, '-') > -1 && strpos( $full_name, '-' ) > -1 ){ + if ( strpos( $first_name, '-' ) > -1 && strpos( $full_name, '-' ) > -1 ) { $difficulties++; - $full_name = str_replace('-', '_', $full_name ); + $full_name = str_replace( '-', '_', $full_name ); } // if name has space, replace with dash - $full_name_slug = str_replace( ' ' , '-', $full_name_slug ); + $full_name_slug = str_replace( ' ', '-', $full_name_slug ); // if name has period - if( strpos( $last_name, '.') > -1 && strpos( $full_name, '.' ) > -1 ){ + if ( strpos( $last_name, '.' ) > -1 && strpos( $full_name, '.' ) > -1 ) { $difficulties++; } - $full_name_slug = str_replace( '.' , '-', $full_name_slug ); - $full_name_slug = str_replace( '--' , '-', $full_name_slug ); + $full_name_slug = str_replace( '.', '-', $full_name_slug ); + $full_name_slug = str_replace( '--', '-', $full_name_slug ); - $user_in_url = rawurlencode( $full_name_slug ); + $user_in_url = rawurlencode( $full_name_slug ); break; case 'name_plus': // plus - $difficulties = 0; $full_name_slug = strtolower( $full_name ); // if last name has dashed replace with underscore - if( strpos( $last_name, '+') > -1 && strpos( $full_name, '+' ) > -1 ){ + if ( strpos( $last_name, '+' ) > -1 && strpos( $full_name, '+' ) > -1 ) { $difficulties++; - $full_name = str_replace('-', '_', $full_name ); + $full_name = str_replace( '-', '_', $full_name ); } // if first name has dashed replace with underscore - if( strpos( $first_name, '+') > -1 && strpos( $full_name, '+' ) > -1 ){ + if ( strpos( $first_name, '+' ) > -1 && strpos( $full_name, '+' ) > -1 ) { $difficulties++; - $full_name = str_replace('-', '_', $full_name ); + $full_name = str_replace( '-', '_', $full_name ); } - if( strpos( $last_name, '-') > -1 || strpos( $first_name, '-') > -1 || strpos( $full_name, '-') > -1 ){ + if ( strpos( $last_name, '-' ) > -1 || strpos( $first_name, '-' ) > -1 || strpos( $full_name, '-' ) > -1 ) { $difficulties++; } // if name has space, replace with dash - $full_name_slug = str_replace( ' ' , '+', $full_name_slug ); - $full_name_slug = str_replace( '-' , '+', $full_name_slug ); + $full_name_slug = str_replace( ' ', '+', $full_name_slug ); + $full_name_slug = str_replace( '-', '+', $full_name_slug ); // if name has period - if( strpos( $last_name, '.') > -1 && strpos( $full_name, '.' ) > -1 ){ + if ( strpos( $last_name, '.' ) > -1 && strpos( $full_name, '.' ) > -1 ) { $difficulties++; } - $full_name_slug = str_replace( '.' , '+', $full_name_slug ); - $full_name_slug = str_replace( '++' , '+', $full_name_slug ); + $full_name_slug = str_replace( '.', '+', $full_name_slug ); + $full_name_slug = str_replace( '++', '+', $full_name_slug ); $user_in_url = $full_name_slug; break; } - return $user_in_url ; + return $user_in_url; } - /** * Get action url for admin use * @@ -553,12 +484,69 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) { * * @return mixed|string|void */ - function admin_act_url( $action, $subaction ) { + public function admin_act_url( $action, $subaction ) { $url = $this->get_current_url(); - $url = add_query_arg( 'um_adm_action', $action, $url ); - $url = add_query_arg( 'sub', $subaction, $url ); - $url = add_query_arg( 'user_id', um_user('ID'), $url ); + $url = add_query_arg( 'um_adm_action', $action, $url ); + $url = add_query_arg( 'sub', $subaction, $url ); + $url = add_query_arg( 'user_id', um_user( 'ID' ), $url ); return $url; } + + /** + * SEO canonical href bugfix + * + * @deprecated since version 2.1.7 + * + * @todo remove since 2.7.0 + * @see function um_profile_remove_wpseo() + */ + public function um_rel_canonical_() { + _deprecated_function( __METHOD__, '2.1.7', 'um_profile_remove_wpseo()' ); + 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"; + } + } } }