how to show to blog owner Pro Site status in admin bar?

Hi,
as super admin i can see the Pro Site status in admin bar. and that's great! but i also want to show the same status to the blog owner.

  • Ash

    Hello @Ruslan

    I hope you are well today and thanks for asking the question.

    Please try this code:

    add_action( 'admin_bar_menu', 'add_extension', 999 );
    
    function add_extension($wp_admin_bar) {
        if( !is_main_site() ) {
    	$id = get_current_blog_id();
    	$expire = ProSites::get_expire($id);
    	$diff = $expire - time();
    	$years = floor($diff / (365*60*60*24));
    	$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
    	$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
    
    	$args = array(
    		'id'    => 'pro_level',
    		'title' => sprintf("Your Pro Level expires at %d years, %d months, %d days\n", $years, $months, $days),
    		'parent' => 'top-secondary'
    	);
    	$wp_admin_bar->add_node( $args );
        }
    }

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Is that something you want?

    Cheers
    Ash

  • Ruslan

    Hi @Ashok,

    Thanks! thats help. i made some improvements to this code. i will give the full code son when i will finish to make more couple things :slight_smile:

    now i need help to get the pro site upgrade link (dynamically) so i could make this clickable when less then month.

    if ($years ==0 && $months ==0 ) {
    $args = array(
    		'id'    => 'pro_level',
    		'title' => sprintf("Click Here to Update Your Pro Level! otherwise is will expire at %d days\n", $days),
                   'href'  => 'pro sites link goes here',
    		'parent' => 'top-secondary'
    	);
    	$wp_admin_bar->add_node( $args );
        }
    }
  • Ash

    Hello @Ruslan

    Here is modification of my above code:

    add_action( 'admin_bar_menu', 'add_extension', 999 );
    
    function add_extension($wp_admin_bar) {
        if( !is_main_site() ) {
    	$id = get_current_blog_id();
    	$expire = ProSites::get_expire($id);
            global $psts;
            $month = 30 * 60 * 60 * 24;
    	$diff = $expire - time();
    	$years = floor($diff / (365*60*60*24));
    	$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
    	$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
    
    	$args = array(
    		'id'    => 'pro_level',
    		'title' => sprintf("Your Pro Level expires at %d years, %d months, %d days\n", $years, $months, $days),
                    'href' => $month > $diff ? $psts->checkout_url($id) : '#',
    		'parent' => 'top-secondary'
    	);
    	$wp_admin_bar->add_node( $args );
        }
    }

    You need to adjust your modification again. In my code, the link will be available only when his subscription will expire in less than 30 days.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

  • Ash

    Hello @Ruslan

    In that case, you can try this:

    add_action( 'admin_bar_menu', 'add_extension', 999 );
    
    function add_extension($wp_admin_bar) {
        if( !is_main_site() ) {
    	$id = get_current_blog_id();
    	$expire = ProSites::get_expire($id);
            global $psts;
            $month = 30 * 60 * 60 * 24;
    	$diff = $expire - time();
    	$years = floor($diff / (365*60*60*24));
    	$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
    	$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
    
    	$args = array(
    		'id'    => 'pro_level',
    		//'title' => sprintf("Your Pro Level expires at %d years, %d months, %d days\n", $years, $months, $days),
                    'title' => sprintf("Your Pro Level expires at %s %s %s\n", ( $years != 0 ? $years . ' years, ' : '' ), ( $months != 0 ? $months . ' months, ' : '' ), ( $days != 0 ? $days . ' days, ' : '' )),
                    'href' => $month > $diff ? $psts->checkout_url($id) : '#',
    		'parent' => 'top-secondary'
    	);
    	$wp_admin_bar->add_node( $args );
        }
    }

    Cheers
    Ash

  • Ash

    Hello @Ruslan

    I hope you are well today.

    Try the following code:

    add_action( 'admin_bar_menu', 'add_extension', 999 );
    
    function add_extension($wp_admin_bar) {
        if( !is_main_site() ) {
    	$id = get_current_blog_id();
    	$expire = ProSites::get_expire($id);
            global $psts;
            $month = 30 * 60 * 60 * 24;
    	$diff = $expire - time();
    	$years = floor($diff / (365*60*60*24));
    	$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
    	$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
    
            switch( $years ){
                case 0:
                    $ytext = '';
                    break;
    
                case 1:
                    $ytext = 'single year text';
                    break;
    
                case 2:
                    $ytext = 'double year text';
                    break;
    
                default:
                    $ytext = $years . ' years, ';
            }
    
            switch( $months ){
                case 0:
                    $mtext = '';
                    break;
    
                case 1:
                    $mtext = 'single month text';
                    break;
    
                case 2:
                    $mtext = 'double month text';
                    break;
    
                default:
                    $mtext = $months . ' months, ';
            }
    
            switch( $days ){
                case 0:
                    $dtext = '';
                    break;
    
                case 1:
                    $dtext = 'single day text';
                    break;
    
                case 2:
                    $dtext = 'double day text';
                    break;
    
                default:
                    $dtext = $days . ' days, ';
            }
    
    	$args = array(
    		'id'    => 'pro_level',
                    'title' => sprintf("Your Pro Level expires at %s %s %s\n", $ytext, $mtext, $dtext ),
                    'href' => $month > $diff ? $psts->checkout_url($id) : '#',
    		'parent' => 'top-secondary'
    	);
    	$wp_admin_bar->add_node( $args );
        }
    }

    You need to change the text "single year text" or "double year text" etc.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

  • Ash

    Hello @Ruslan

    I hope you are well today.

    That should not be any issue, it's just a notice. But you can try this if that works:

    add_action( 'admin_bar_menu', 'add_extension', 999 );
    
    function add_extension($wp_admin_bar) {
        if( !is_main_site() ) {
    	$id = get_current_blog_id();
            $proSite = new ProSites();
    	$expire = $proSite->get_expire($id);
            global $psts;
            $month = 30 * 60 * 60 * 24;
    	$diff = $expire - time();
    	$years = floor($diff / (365*60*60*24));
    	$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
    	$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
    
            switch( $years ){
                case 0:
                    $ytext = '';
                    break;
    
                case 1:
                    $ytext = 'single year text';
                    break;
    
                case 2:
                    $ytext = 'double year text';
                    break;
    
                default:
                    $ytext = $years . ' years, ';
            }
    
            switch( $months ){
                case 0:
                    $mtext = '';
                    break;
    
                case 1:
                    $mtext = 'single month text';
                    break;
    
                case 2:
                    $mtext = 'double month text';
                    break;
    
                default:
                    $mtext = $months . ' months, ';
            }
    
            switch( $days ){
                case 0:
                    $dtext = '';
                    break;
    
                case 1:
                    $dtext = 'single day text';
                    break;
    
                case 2:
                    $dtext = 'double day text';
                    break;
    
                default:
                    $dtext = $days . ' days, ';
            }
    
    	$args = array(
    		'id'    => 'pro_level',
                    'title' => sprintf("Your Pro Level expires at %s %s %s\n", $ytext, $mtext, $dtext ),
                    'href' => $month > $diff ? $psts->checkout_url($id) : '#',
    		'parent' => 'top-secondary'
    	);
    	$wp_admin_bar->add_node( $args );
        }
    }

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.