/**
 * override default template
 *
 * @param array $column
 * @param init $post_id
 * @return void
 */
function mgm_template_include($template)
{
    // check override
    if (bool_from_yn(mgm_get_setting('override_theme_for_custom_pages'))) {
        // name
        $name = mgm_get_query_var('name');
        // switch
        switch ($name) {
            case 'register':
            case 'profile':
            case 'lost_password':
            case 'login':
                $content = mgm_get_query_post_content();
                // @todo check #BUG_PENDING
                // check
                if (mgm_is_custom_page_published($name, $content)) {
                    // if template exists in theme only
                    if ($c_template = mgm_get_page_template($name, false, true)) {
                        $template = $c_template;
                    }
                }
                break;
        }
    }
    // return
    return $template;
}
/**
 * get custom url, return default if not published
 *
 * @param string key/name of page
 * @param bool force default
 * @param array query string
 * @return string url 
 */
function mgm_get_custom_url($name, $load_default = false, $query_arg = array())
{
    // get system
    $system_obj = mgm_get_class('system');
    // is published page
    $is_published = mgm_is_custom_page_published($name == 'purchase_content' ? 'transactions' : $name);
    // on name
    switch ($name) {
        case 'login':
            // custom
            if (!$load_default && $is_published && ($login_url = mgm_get_setting('login_url'))) {
                $url = mgm_site_url($login_url);
            } else {
                // default
                $url = site_url('wp-login.php?action=login', 'login');
            }
            break;
        case 'register':
            // custom
            if (!$load_default && $is_published && ($register_url = mgm_get_setting('register_url'))) {
                $url = mgm_site_url($register_url);
            } elseif (!$load_default) {
                // old
                $url = add_query_arg(array('method' => 'register'), mgm_home_url('purchase_subscription'));
            } else {
                // default
                $url = site_url('wp-login.php?action=register', 'login');
            }
            break;
        case 'lostpassword':
            // custom
            if (!$load_default && $is_published && ($lostpassword_url = mgm_get_setting('lostpassword_url'))) {
                $url = mgm_site_url($lostpassword_url);
            } else {
                // default
                $url = site_url('wp-login.php?action=lostpassword');
            }
            break;
        case 'profile':
            // custom
            if (!$load_default && $is_published && ($profile_url = mgm_get_setting('profile_url'))) {
                $url = mgm_site_url($profile_url);
            } else {
                // default
                $url = admin_url('profile.php');
            }
            break;
        case 'userprofile':
            // custom
            if (!$load_default && $is_published && ($public_profile_url = mgm_get_setting('userprofile_url'))) {
                $url = mgm_site_url($public_profile_url);
            } else {
                // default
                $url = admin_url('profile.php');
            }
            break;
        case 'purchase_content':
            // reuse the same transactions url here: issue#: 756
            // $is_published = mgm_is_custom_page_published('transactions');
        // reuse the same transactions url here: issue#: 756
        // $is_published = mgm_is_custom_page_published('transactions');
        case 'transactions':
            // custom
            if ($is_published && ($transactions_url = mgm_get_setting('transactions_url'))) {
                $url = mgm_site_url($transactions_url, true);
            } else {
                // default
                $url = mgm_home_url($name == 'purchase_content' ? 'purchase_content' : 'purchase_subscription');
            }
            break;
        case 'membership_details':
            // custom
            if ($is_published && !$load_default && !is_super_admin() && ($membership_details_url = mgm_get_setting('membership_details_url'))) {
                $url = mgm_site_url($membership_details_url);
            } else {
                // default
                $url = admin_url(sprintf('%s.php?page=mgm/profile', is_super_admin() ? 'users' : 'profile'));
            }
            break;
        case 'membership_contents':
            // custom
            if ($is_published && !$load_default && !is_super_admin() && ($membership_contents_url = mgm_get_setting('membership_contents_url'))) {
                $url = mgm_site_url($membership_contents_url);
            } else {
                // default
                $url = admin_url(sprintf('%s.php?page=mgm/membership/content', is_super_admin() ? 'users' : 'profile'));
            }
            break;
        default:
            // default
            $url = mgm_home_url('purchase_subscription');
            break;
    }
    // @todo: add_query_arg urlencodes url with page=mgm/ need fix in some servers
    // add query arg
    if (!empty($query_arg)) {
        $url = add_query_arg($query_arg, $url);
    }
    // return
    return $url;
}