WP_LIST_TABLE bulk action

时间:2016-07-17 作者:Saeed Darvish

我创建了一个类扩展WP_List_Table 并创建了如下批量操作的方法:

 function get_bulk_actions()
    {
        $actions = array(
            \'synchronize\' => \'Synchronize\',
            \'delete\' => \'Delete from Shareino\',
        );
        return $actions;
    }
以及另一种处理它们的方法:

  function process_bulk_action()
    {

        //Detect when a bulk action is being triggered...
        if (\'delete\' === $this->current_action()) {
            wp_die(\'Items deleted (or they would be if we had items to delete)!\');
        }

    }
此操作显示在dropbox 但当我选择项目和一个动作并按下apply时,它不会做任何事情,所以process_bulk_action 不工作;

1 个回复
SO网友:Saeed Darvish

通话时间$synchronizationList->display() 关于表创建、分页、排序和批量操作的每一件事,但当其创建批量操作时,其只需创建2个输入dropbox 它包含所有批量操作和应用按钮的提交按钮,因此不会创建from 标记和当提交按钮不在form 它什么都不做。所以我创建了一个form 一切都很好。

  add_action(\'admin_menu\', array("Shareino", \'ShareinoAdminMenu\'));
    /**
     * This method adds shareino items to admin menu
     */
    public static function ShareinoAdminMenu()
    {
        add_menu_page(__(\'Shareino\', \'access\'), __(\'Shareino\', \'access\'), \'manage_options\', __(\'shareino\', \'vibe\'),
            array("Shareino", "shareinoSetting"), WP_PLUGIN_URL . "/shareino/assets/images/logo.gif", 80);
        add_submenu_page(
            \'shareino\',
            __(\'Synchronize\', \'access\'),
            __(\'Synchronize\'),
            \'manage_options\',
            __(\'Synchronize\'),
            array("Shareino", "shareinoSynchronize"));

    }


    public function shareinoSynchronize()
    {
        $synchronizationList = new SynchronizationList();
        $synchronizationList->prepare_items();
        ?>
        <!-- Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions -->
        <form id="movies-filter" method="get">
            <!-- For plugins, we also need to ensure that the form posts back to our current page -->
            <input type="hidden" name="page" value="<?php echo $_REQUEST[\'page\'] ?>"/>
            <!-- Now we can render the completed list table -->
            <?php $synchronizationList->display() ?>
        </form>
        <?php
    }

相关推荐

POST_ROW_ACTIONS不适用于分层帖子类型

我正在开发一个插件,其中注册了一个自定义帖子类型(CPT),我需要向该特定帖子类型添加自定义行操作。但无法将以下代码连接到post_row_actions 工作:function ttest_copy_button( $actions, $post ) { // var_dump($actions); if( \'ttest\' === $post->post_type ) { // pass nonce to check and ve