function hocwp_setup_theme_wp_setup_nav_menu_item($menu_item)
{
    if (is_a($menu_item, 'WP_Post') && $menu_item->post_type == 'nav_menu_item') {
        if ('trang-chu' == $menu_item->post_name || 'home' == $menu_item->post_name) {
            $menu_url = $menu_item->url;
            $home_url = home_url('/');
            if (hocwp_get_domain_name($menu_url) != hocwp_get_domain_name($home_url)) {
                $menu_item->url = $home_url;
                update_post_meta($menu_item->ID, '_menu_item_url', $home_url);
                wp_update_nav_menu_item($menu_item->ID, $menu_item->db_id, array('url' => $home_url));
            }
        } elseif ('page' == $menu_item->object) {
            $post_id = $menu_item->object_id;
            $page = get_post($post_id);
            $diff_title = get_post_meta($post_id, 'different_title', true);
            $title = $menu_item->title;
            if (!hocwp_string_empty($diff_title) && $page->post_title != $diff_title && $title == $diff_title) {
                $title = do_shortcode($page->post_title);
                $title = apply_filters('translate_text', $title, $lang = null, $flags = 0);
                $menu_item->title = $title;
            }
        }
    }
    return $menu_item;
}
Example #2
0
function hocwp_replace_text_placeholder($text)
{
    remove_filter('hocwp_replace_text_placeholder', 'hocwp_replace_text_placeholder');
    $text = apply_filters('hocwp_replace_text_placeholder', $text);
    add_filter('hocwp_replace_text_placeholder', 'hocwp_replace_text_placeholder');
    $text_placeholders = array('%DOMAIN%', '%CURRENT_YEAR%', '%PAGED%', '%HOME_URL%', '%SITE_NAME%');
    $text_placeholders = apply_filters('hocwp_text_placeholders', $text_placeholders);
    $placeholder_replace = array(hocwp_get_domain_name(home_url()), date('Y'), hocwp_get_paged(), home_url('/'), get_bloginfo('name'));
    $placeholder_replace = apply_filters('hocwp_text_placeholders_replace', $placeholder_replace);
    $text = str_replace($text_placeholders, $placeholder_replace, $text);
    return $text;
}
function hocwp_is_localhost($site_url = '')
{
    if (empty($site_url)) {
        $site_url = get_bloginfo('url');
    }
    $domain = hocwp_get_domain_name($site_url);
    $root_domain = hocwp_get_domain_name_only($domain);
    if (empty($root_domain)) {
        $root_domain = $domain;
    }
    $result = false;
    $last = substr($domain, -3);
    if ('localhost' == $root_domain || hocwp_is_ip($root_domain) || 'dev' == $last) {
        $result = true;
    }
    return apply_filters('hocwp_is_localhost', $result);
}