הוספת אפשרות מותאמת לתפריט bulk actions ברשימת הפוסטים. בדוגמה זו מסמנים פוסטים נבחרים כ-"Featured". לעוד על הוקים בוורדפרס.
add_filter( 'bulk_actions-edit-post', function ( $actions ) {
$actions['mark_featured'] = 'Mark as Featured';
return $actions;
} );
add_filter( 'handle_bulk_actions-edit-post', function ( $redirect_to, $action, $post_ids ) {
if ( $action !== 'mark_featured' ) {
return $redirect_to;
}
foreach ( $post_ids as $post_id ) {
update_post_meta( $post_id, '_is_featured', '1' );
}
return add_query_arg( 'marked_featured', count( $post_ids ), $redirect_to );
}, 10, 3 );
add_action( 'admin_notices', function () {
if ( empty( $_REQUEST['marked_featured'] ) ) {
return;
}
$count = intval( $_REQUEST['marked_featured'] );
printf(
'<div class="notice notice-success is-dismissible"><p>%d post(s) marked as featured.</p></div>',
$count
);
} );הוסיפו ל-functions.php. שנו את mark_featured ואת מפתח ה-meta בהתאם לצורך שלכם.