我在下面定义了一个自定义帖子类型,我想添加一个自定义行操作,以允许我通过管理面板“更新”帖子
class LeagueCpt
{
function __construct()
{
add_action( \'init\', array(&$this,\'registerLeagueCPT\'));
add_filter(\'post_row_actions\', array(&$this,\'post_row_actions\'), 0, 2);
}
function registerLeagueCPT()
{
$leagueLabels = array(
\'name\' => _x( \'Leagues\', \'league\' ),
\'singular_name\' => _x( \'League\', \'league\' ),
\'add_new\' => _x( \'Add New\', \'league\' ),
\'add_new_item\' => _x( \'Add New League\', \'league\' ),
\'edit_item\' => _x( \'Edit League\', \'league\' ),
\'new_item\' => _x( \'New League\', \'league\' ),
\'view_item\' => _x( \'View League\', \'league\' ),
\'search_items\' => _x( \'Search Leagues\', \'league\' ),
\'not_found\' => _x( \'No league found\', \'league\' ),
\'not_found_in_trash\' => _x( \'No leagues found in Trash\', \'league\' ),
\'parent_item_colon\' => _x( \'Parent League:\', \'league\' ),
\'menu_name\' => _x( \'Leagues\', \'league\' ),
);
$leagueArgs = array(
\'labels\' => $leagueLabels,
\'hierarchical\' => false,
\'description\' => \'League Details\',
\'supports\' => array( \'title\',\'editor\',\'excerpt\',\'thumbnail\',\'custom-fields\',\'page-attributes\',\'comments\'),
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'publicly_queryable\' => true,
\'exclude_from_search\' => false,
\'has_archive\' => true,
\'query_var\' => true,
\'can_export\' => true,
\'rewrite\' => true,
\'capability_type\' => \'post\'
);
register_post_type(\'league\', $leagueArgs );
}
这是注册行操作的代码
function post_row_actions($actions, $post) {
$actions = array_merge($actions, array(
\'update\' => sprintf(\'<a href="%s">Update</a>\',
wp_nonce_url(sprintf(\'edit.php?post_type=league&action=update&post_id=%d\',$post->ID),
\'abc\'))
));
return $actions;
}
我在同一个php文件中定义了一个函数update(),我计划在其中进行实际工作
function update()
{
// do some custom update stuff on the post content
}
我的问题是,如何确保具有更新操作的URL请求调用上述函数?
我使用了以下资源
Custom Post Row Actions
http://wordpress.org/support/topic/trying-to-add-custom-post_row_actions-for-custom-post-status
Row actions for custom post types?
http://wordpress.org/support/topic/replacement-for-post_row_actions
http://www.ilovecolors.com.ar/saving-custom-fields-quick-bulk-edit-wordpress/