• Hi,

    I use WPML to translate my website but pages that do not core pages are not translated, such as password and custom tabs pages, error 404 appears.

    Is there any way to rewrite these urls to work properly?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Alessandro Tesoro

    (@alessandrotesoro)

    Hi @brunobns

    At the moment there isn’t compatibility with WPUM. The issue however is high likely connected to the fact that WPUM doesn’t know what to do when in the url there’s some extra content, in this case it would be the language code set by WPML in the url.

    What is the URL structure generated for the account page and profile tabs with your WPML settings? If you could provide this to me, I might be able to give you a snippet that should hopefully make it compatible.

    Let me know.

    Thread Starter brunobns

    (@brunobns)

    You can see at:

    https://webapp80166.ip-104-200-16-4.cloudezapp.io/conta/

    (read only user)
    user: venture
    pass: venture

    URLs that work in default language:
    /conta (Load my custom tab with priority -1)
    /conta/relatorios (Same as /conta)
    /conta/settings
    /conta/password

    Broken URLs:
    /en/account/reports (/conta/relatorios translation)
    /en/account/settings (/conta/settings)
    /en/account/password (/conta/password)

    I don’t use the profile page, just the ones above.

    Thank you for your help.

    Plugin Contributor Alessandro Tesoro

    (@alessandrotesoro)

    Hi @brunobns

    Open your theme’s functions.php file and at the very top of the file add the following 2 lines:

    
    use Brain\Cortex\Route\RouteCollectionInterface;
    use Brain\Cortex\Route\QueryRoute;
    

    At the bottom of the file, add the following code

    
    add_action(
    	'cortex.routes',
    	function( RouteCollectionInterface $routes ) {
    
    		$account_page_id = wpum_get_core_page_id( 'account' );
    		$exists          = ( 'publish' == get_post_status( $account_page_id ) ) ? true : false;
    
    		if ( ! $account_page_id || ! $exists ) {
    			return;
    		}
    
    		$page_slug = esc_attr( get_post_field( 'post_name', intval( $account_page_id ) ) );
    		$hierarchy = wpum_get_full_page_hierarchy( $account_page_id );
    
    		if ( ! empty( $hierarchy ) && is_array( $hierarchy ) ) {
    			$page_slug = '';
    			foreach ( array_reverse( $hierarchy )  as $page ) {
    				$parent_page_slug = esc_attr( get_post_field( 'post_name', intval( $page['id'] ) ) );
    				$page_slug       .= $parent_page_slug . '/';
    			}
    		}
    
    		$routes->addRoute(
    			new QueryRoute(
    				'{lang:[a-zA-Z0-9_.-]+}/' . $page_slug . '{tab:[a-zA-Z0-9_.-]+}',
    				function( array $matches ) use ( $account_page_id ) {
    					return [
    						'tab'     => $matches['tab'],
    						'page_id' => $account_page_id,
    					];
    				}
    			)
    		);
    	}
    );
    

    This code basically just tells WPUM “there’s something else before the page slug in the url” but it doesn’t actually do anything with it.

    Let me know how it goes.

    Thread Starter brunobns

    (@brunobns)

    Did not work. ??

    Same errors.

    Plugin Contributor Alessandro Tesoro

    (@alessandrotesoro)

    I’ve done some tests on my end with WPMl but I can’t seem to get it work unfortunately it’s literally ignoring whatever rewrite rules I’m setting ??

    I’m afraid at the moment I don’t have a solution for this.

    Plugin Contributor Alessandro Tesoro

    (@alessandrotesoro)

    Just wanted to add, I think it won’t be possible to add WPML support because it doesn’t look like that WPML injects custom parameters to the WP_Query class. The routing system of WPUM modifies the arguments of the WP_Query class when it’s called, so for example with another plugin like Polylang it might possible to add multilanguage support since Polylang has custom parameters for WP_Query.

    Thread Starter brunobns

    (@brunobns)

    ??

    Thank you for your dedication.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘WPML support’ is closed to new replies.