Merge pull request #1201 from ultimatemember/fix/wpml_profile_url

WPML: Profile links are incorrect
This commit is contained in:
Mykyta Synelnikov
2023-06-09 12:32:33 +03:00
committed by GitHub
4 changed files with 287 additions and 235 deletions
+1
View File
@@ -4,6 +4,7 @@ on:
push:
branches:
- master
- development/2.6.3
jobs:
hookdocs:
+1 -1
View File
@@ -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 . '/';
+86 -48
View File
@@ -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_localize_permalink_filter', array( &$this, 'um_localize_permalink_filter' ), 10, 2 );
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,76 +176,113 @@ if ( ! class_exists( 'um\core\External_Integrations' ) ) {
return $single_template;
}
/**
* @param $profile_url
* @param $page_id
* Change user profile URL for WPML compatibility.
*
* @return bool|false|string
* @hook um_external_profile_url
* @see \um\core\Permalinks::profile_permalink()
*
* @param bool|string $profile_url Profile URL.
* @param string $slug Profile slug.
*
* @return string
*/
function um_localize_permalink_filter( $profile_url, $page_id ) {
if ( ! $this->is_wpml_active() )
public function um_localize_profile_url( $profile_url, $slug ) {
if ( ! $this->is_wpml_active() ) {
return $profile_url;
}
/*if ( function_exists( 'icl_get_current_language' ) && icl_get_current_language() != icl_get_default_language() ) {
if ( get_the_ID() > 0 && get_post_meta( get_the_ID(), '_um_wpml_user', true ) == 1 ) {
$profile_url = get_permalink( get_the_ID() );
}
}*/
$page_id = UM()->config()->permalinks['user'];
$lang_post_id = apply_filters( 'wpml_object_id', $page_id, 'page', true );
// WPML compatibility
if ( function_exists( 'icl_object_id' ) ) {
$language_code = ICL_LANGUAGE_CODE;
$lang_post_id = icl_object_id( $page_id , 'page', true, $language_code );
if ( $lang_post_id && $lang_post_id !== $page_id ) {
$user_page_url = get_permalink( $lang_post_id );
if ( $lang_post_id != 0 ) {
$profile_url = get_permalink( $lang_post_id );
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 );
}
} else {
// No page found, it's most likely the homepage
global $sitepress;
$profile_url = $sitepress->language_url( $language_code );
$profile_url = add_query_arg( 'um_user', strtolower( $slug ), $user_page_url );
}
}
return $profile_url;
}
/**
* @param $array
* Change current URL for WPML compatibility.
*
* @return mixed
* 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
*/
function um_core_page_wpml_permalink( $array ) {
if ( ! $this->is_wpml_active() )
return $array;
global $sitepress;
if( ! um_is_core_page("user") ) return $array;
if( ! defined("ICL_LANGUAGE_CODE") ) return $array;
if( ! function_exists('icl_object_id') ) return $array;
// Permalink base
$permalink_base = UM()->options()->get( 'permalink_base' );
// Get user slug
$profile_slug = strtolower( get_user_meta( um_profile_id(), "um_user_profile_url_slug_{$permalink_base}", true ) );
$current_language = ICL_LANGUAGE_CODE;
foreach ( $array as $lang_code => $arr ) {
$sitepress->switch_lang( $lang_code );
$user_page = um_get_core_page( "user" );
$array[ $lang_code ]['url'] = "{$user_page}{$profile_slug}/";
public function um_localize_profile_nav_url( $page_url, $no_query_params ) {
if ( ! $this->is_wpml_active() ) {
return $page_url;
}
$sitepress->switch_lang( $current_language );
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.
*
* @hook icl_ls_languages
* @see https://wpml.org/wpml-hook/icl_ls_languages/
*
* @param array $array Collection of active languages to display in the language switcher.
*
* @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 = 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', UM()->config()->permalinks['user'], 'page', true );
$user_page_url = get_permalink( $lang_post_id );
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 );
}
} else {
$profile_url = add_query_arg( 'um_user', strtolower( $slug ), $user_page_url );
}
$array[ $lang_code ]['url'] = $profile_url;
}
$sitepress->switch_lang( $current_language );
}
return $array;
}
/**
* Check if WPML is active
*
+199 -186
View File
@@ -1,35 +1,32 @@
<?php
namespace um\core;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'um\core\Permalinks' ) ) {
/**
* Class Permalinks
* @package um\core
*/
class Permalinks {
/**
* @var
*/
var $core;
/**
* @var
*/
var $current_url;
/**
* Permalinks constructor.
*/
function __construct() {
public function __construct() {
add_action( 'init', array( &$this, 'set_current_url' ), 0 );
add_action( 'init', array( &$this, 'check_for_querystrings' ), 1 );
@@ -37,78 +34,19 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
add_action( 'init', array( &$this, 'activate_account_via_email_link' ), 1 );
}
/**
* Set current URL variable
*/
function set_current_url() {
public function set_current_url() {
$this->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
* <?php add_filter( 'um_allow_canonical__filter', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_allow_canonical__filter', 'my_allow_canonical', 10, 1 );
* function my_allow_canonical( $allow_canonical ) {
* // your code here
* return $allow_canonical;
* }
* ?>
*/
$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 "<link rel='canonical' href='$link' />\n";
return;
}
$link = get_permalink( $id );
if ( $page = get_query_var( 'cpage' ) ){
$link = get_comments_pagenum_link( $page );
echo "<link rel='canonical' href='$link' />\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
* <?php add_filter( 'um_get_current_page_url', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_get_current_page_url', 'my_get_current_page_url', 10, 1 );
* function my_get_current_page_url( $page_url ) {
* // your code here
* @param {string} $page_url Current page URL.
* @param {bool} $no_query_params Ignore $_GET attributes in URL. false !== ignore.
*
* @return {string} Current page URL.
*
* @since 1.3.x
* @hook um_get_current_page_url
*
* @example <caption>Add your custom $_GET attribute to all links.</caption>
* 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,26 +243,25 @@ 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' );
$user_id = $wpdb->get_var(
"SELECT user_id
FROM {$wpdb->usermeta}
WHERE meta_key = 'um_user_profile_url_slug_{$permalink_base}' AND
"SELECT user_id
FROM {$wpdb->usermeta}
WHERE meta_key = 'um_user_profile_url_slug_{$permalink_base}' AND
meta_value = '{$slug}'
ORDER BY umeta_id ASC
LIMIT 1"
@@ -348,57 +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 <caption>Change profile URL to your custom link and ignore native profile permalink handlers.</caption>
* 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
* <?php add_filter( 'um_localize_permalink_filter', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_localize_permalink_filter', 'my_localize_permalink', 10, 2 );
* @since 1.3.x
* @deprecated 2.6.3 Use <a href="https://developer.wordpress.org/reference/hooks/post_link/" target="_blank" title="'post_link' hook article on developer.wordpress.org">'post_link'</a> 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 <caption>Change profile base URL to your custom link.</caption>
* 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 );
}
/**
* Filters user profile URL.
*
* @since 2.6.3
* @hook um_profile_permalink
*
* @param {string} $profile_url Profile URL.
* @param {int} $page_id Profile Page ID.
* @param {string} $slug User profile slug.
*
* @return {string} Profile URL.
*
* @example <caption>Change profile URL to your custom link.</caption>
* 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_profile_permalink', $profile_url, $page_id, $slug );
return ! empty( $profile_url ) ? $profile_url : '';
}
/**
* Generate profile slug
*
@@ -407,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++;
}
@@ -450,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
*
@@ -528,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
* <?php add_filter( 'um_allow_canonical__filter', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_allow_canonical__filter', 'my_allow_canonical', 10, 1 );
* function my_allow_canonical( $allow_canonical ) {
* // your code here
* return $allow_canonical;
* }
* ?>
*/
$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 "<link rel='canonical' href='$link' />\n";
return;
}
$link = get_permalink( $id );
if ( $page = get_query_var( 'cpage' ) ) {
$link = get_comments_pagenum_link( $page );
echo "<link rel='canonical' href='$link' />\n";
}
}
}
}