Wordpress - Separate PHP page call WPML function

If you just like me who need to create a new empty PHP page inside Wordpress, and you need to call that page inside wordpress, together with using WPML, here is the way:

 Assume that your brand new PHP file is under wp-content/themes/your-theme/new_file.php

This new_file.php will receive data from other wordpress page. Now:

# require_once wp-load.php to use all wordpress functions 
require_once dirname(dirname(dirname(dirname(__FILE__)))).'/wp-load.php';

if(!function_exists('any_new_function')){ 
    function any_new_function(lang){ 
        $lang = $_POST['lang_from_previous_wordpress_page']; 
        return $lang;
    } 
    # if you are using WPML 3.0 or later, you will see this icl_set_current_language filter 
    # I am not sure if version prior to 3.0 will have it or not, just search in sitepress.class.php to find out. 
    add_filter('icl_set_current_language', 'any_new_function');


# Init this plugin, the construction has been completed in wp-load.php $sitepress->init(); 

# Immediately after running init, remove filter so that will not affect other function(s) 

remove_filter('icl_set_current_language', 'any_new_function'); 

Hope it helps someone.

Comments

Popular posts from this blog

TCPDF How to show/display Chinese Character?

How to fix fancy box/Easy Fancybox scroll not work in mobile

Wordpress Load balancing: 2 web servers 1 MySQL without any Cloud services