首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在管理顶部添加通知气泡

在管理顶部添加通知气泡
EN

WordPress Development用户
提问于 2020-06-28 12:23:55
回答 2查看 485关注 0票数 0

如何为挂起/在等待/处理顺序的管理顶级栏上添加通知泡?

EN

回答 2

WordPress Development用户

回答已采纳

发布于 2020-06-28 13:57:40

我会给你一些如何做到这一点的想法,因为你没有提到从哪里来的计数数据。将以下代码添加到主题/子主题functions.php文件中

代码语言:javascript
运行
复制
function custom_admin_bar_menu() {
    $pending_count = wc_orders_count('pending');
    $on_hold_count = wc_orders_count('on-hold');
    $processing_count = wc_orders_count('processing');

    if ( current_user_can( 'manage_options' ) ) {
        global $wp_admin_bar;

        //Add an icon with count
        $wp_admin_bar->add_menu( array(
            'id'    => 'custom-1', //Change this to yours
            'title' => ''.$pending_count.'',
            'href'  => get_admin_url( NULL, 'edit.php?post_status=wc-pending&post_type=shop_order' ),//Replace with your resired destination
        ) );

        //Add another icon with count
        $wp_admin_bar->add_menu( array(
            'id'    => 'custom-2', //Change this to yours
            'title' => ''.$on_hold_count.'',
            'href'  => get_admin_url( NULL, 'edit.php?post_status=wc-on-hold&post_type=shop_order' ),//Replace with your resired destination
        ) );

        //Add another icon with count
        $wp_admin_bar->add_menu( array(
            'id'    => 'custom-3', //Change this to yours
            'title' => ''.$processing_count.'',
            'href'  => get_admin_url( NULL, 'edit.php?post_status=wc-processing&post_type=shop_order' ),//Replace with your resired destination
        ) );

        //You can add more as per your need.
    }
}
add_action( 'admin_bar_menu', 'custom_admin_bar_menu' , 500 );

00中表示计数。您可以通过使用变量和一些自定义查询轻松地替换它。

票数 1
EN

WordPress Development用户

发布于 2021-04-23 22:15:28

对于正在寻找工作示例的人来说,他们可以根据需要的计数进行调整,或者是一个代码片段,用于在自定义菜单项上显示重力表单中的未读条目。看看这个。

此片段获取count_entries()调用中数组()中所有表单ID的计数,以便父菜单项显示所有未读条目的计数。

然后,在构建菜单时,我将更改count_entries()调用中的ID和URL -参见代码段中的注释。这允许每个子菜单项显示其特定未读条目的计数。

代码语言:javascript
运行
复制
function register_my_custom_menu_page() {
    $search_criteria = array(
        'status'     => 'active', //Active forms 
        'field_filters' => array( //which fields to search
            array(
                'key' => 'is_read', 'value' => false, // let's just get the count for entries that we haven't read yet.
            )
          )
        );

    // Add the form IDs to the array below, the parent menu will show ALL unread entries for these forms
    $notification_count = GFAPI::count_entries( array(1,4,5,6,11,13), $search_criteria );
    
    add_menu_page(
        'Full Quote Form submissions', // Page Title
        // here we're going to use the var $notification_count to get ALL the form IDS and their counts... just for the parent menu item
        $notification_count ? sprintf( 'Quotes %d', $notification_count ) : 'View Quotes',
        'manage_options', // Capabilities 
        'admin.php?page=gf_entries&id=13', // menu slug
        '', // callback function
        'dashicons-format-aside', // icon URL
        6 // position
    );
    add_submenu_page( 
        'admin.php?page=gf_entries&id=13', // this needs to match menu slug of the parent
        'View Full Quotes', // name of the page
        // The ID on the next line, 13 in this example, matches the form ID in the URL on the LAST line. Notice we're NOT using the var $notification_count from above, as that contains the entry count for ALL the forms
        GFAPI::count_entries( 13, $search_criteria ) ? sprintf( 'Full Quotes %d', GFAPI::count_entries( 13, $search_criteria ) ) : 'Full Quotes',
        'manage_options', 
        // make sure to change the ID on the end of this URL to the form you want to point to, AND make sure it matches the ID two lines above in the count_entries() call
        'admin.php?page=gf_entries&id=13'
    );
    add_submenu_page( 
        'admin.php?page=gf_entries&id=13', // this needs to match menu slug of the parent
        'View Short Quotes', // name of the page
        // The ID on the next line, 1 in this example, matches the form ID in the URL on the LAST line.     
        GFAPI::count_entries( 1, $search_criteria ) ? sprintf( 'Short Quotes %d', GFAPI::count_entries( 1, $search_criteria ) ) : 'Short Quotes',
        'manage_options', 
        // make sure to change the ID on the end of this URL to the form you want to point to, AND make sure it matches the ID two lines above in the count_entries() call
        'admin.php?page=gf_entries&id=1'
    );
    add_submenu_page( 
        'admin.php?page=gf_entries&id=13', // this needs to match menu slug of the parent
        'Sell Your Equipment', // name of the page
        // The ID on the next line, 5 in this example, matches the form ID in the URL on the LAST line.             
        GFAPI::count_entries( 5, $search_criteria ) ? sprintf( 'Selling Equip %d', GFAPI::count_entries( 5, $search_criteria ) ) : 'Selling Equip',
        'manage_options', 
        // make sure to change the ID on the end of this URL to the form you want to point to, AND make sure it matches the ID two lines above in the count_entries() call
        'admin.php?page=gf_entries&id=5'
    );
    add_submenu_page( 
        'admin.php?page=gf_entries&id=13', // this needs to match menu slug of the parent
        'Equipment Wanted', // name of the page
        // The ID on the next line, 6 in this example, matches the form ID in the URL on the LAST line.             
        GFAPI::count_entries( 6, $search_criteria ) ? sprintf( 'Equip Wanted %d', GFAPI::count_entries( 6, $search_criteria ) ) : 'Equip Wanted',
        'manage_options', 
        // make sure to change the ID on the end of this URL to the form you want to point to, AND make sure it matches the ID two lines above in the count_entries() call  
        'admin.php?page=gf_entries&id=6'
    );
    add_submenu_page( 
        'admin.php?page=gf_entries&id=13', // this needs to match menu slug of the parent
        'Appraisal Requests', // name of the page
        // The ID on the next line, 11 in this example, matches the form ID in the URL on the LAST line.                
        GFAPI::count_entries( 11, $search_criteria ) ? sprintf( 'Appraisal Requests %d', GFAPI::count_entries( 11, $search_criteria ) ) : 'Appraisal Requests',
        'manage_options', 
        // make sure to change the ID on the end of this URL to the form you want to point to, AND make sure it matches the ID two lines above in the count_entries() call
        'admin.php?page=gf_entries&id=11'
    );
    add_submenu_page( 
        'admin.php?page=gf_entries&id=13', // this needs to match menu slug of the parent
        'Contact Form',  // name of the page
        // The ID on the next line, 4 in this example, matches the form ID in the URL on the LAST line.             
        GFAPI::count_entries( 4, $search_criteria ) ? sprintf( 'Contact Form %d', GFAPI::count_entries( 4, $search_criteria ) ) : 'Contact Form',
        'manage_options', 
        // make sure to change the ID on the end of this URL to the form you want to point to, AND make sure it matches the ID two lines above in the count_entries() call
        'admin.php?page=gf_entries&id=4'
    );
    
}
add_action( 'admin_menu', 'register_my_custom_menu_page' );
票数 0
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/369941

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档