Thêm Bulk Actions và Action Links cho plugin WordPress
Thêm hành động vào Bulk Actions cho plugin, cũng như thêm các link vào bên dưới tên plugin trong bảng quản lý danh sách các plugin.
function hocwp_theme_site_transient_update_plugins_filter( $value ) { if ( is_object( $value ) && isset( $value->response ) && is_array( $value->response ) ) { $options = get_option( 'disable_upgrade_plugins' ); if ( ! empty( $options ) ) { foreach ( $value->response as $file => $obj ) { if ( in_array( $file, $options ) ) { unset( $value->response[ $file ] ); } } } } return $value; } function hocwp_theme_plugin_bulk_actions_filter( $actions ) { $actions['disable-upgrade'] = __( 'Disable Upgrade', 'hocwp-theme' ); $actions['enable-upgrade'] = __( 'Enable Upgrade', 'hocwp-theme' ); return $actions; } function hocwp_theme_handle_plugin_bulk_action( $sendback, $action, $plugins ) { if ( 'disable-upgrade' == $action || 'enable-upgrade' == $action ) { $options = get_option( 'disable_upgrade_plugins' ); if ( ! is_array( $options ) ) { $options = array(); } $count = 0; foreach ( $plugins as $file ) { if ( 'disable-upgrade' == $action && ! in_array( $file, $options ) ) { $options[] = $file; $count ++; } elseif ( 'enable-upgrade' == $action ) { unset( $options[ array_search( $file, $options ) ] ); $count ++; } } $sendback = admin_url( 'plugins.php' ); if ( 0 < $count ) { update_option( 'disable_upgrade_plugins', $options ); $sendback = add_query_arg( 'count_' . $action, $count, $sendback ); } } return $sendback; } function hocwp_theme_plugin_action_links_filter( $actions, $plugin_file ) { $options = get_option( 'disable_upgrade_plugins' ); if ( ! empty( $options ) && in_array( $plugin_file, $options ) ) { $actions['disable_upgrade_status'] = '<span class="disable-upgrade-status">' . __( 'Upgrade Disabled', 'hocwp-theme' ) . '</span>'; } return $actions; } if ( current_user_can( 'manage_options' ) ) { add_filter( 'site_transient_update_plugins', 'hocwp_theme_site_transient_update_plugins_filter' ); add_filter( 'bulk_actions-plugins', 'hocwp_theme_plugin_bulk_actions_filter' ); add_filter( 'handle_bulk_actions-plugins', 'hocwp_theme_handle_plugin_bulk_action', 10, 3 ); add_filter( 'plugin_action_links', 'hocwp_theme_plugin_action_links_filter', 10, 2 ); }

Lại Đình Cường
Tôi làm quen và phát triển WordPress từ năm 2008, cho đến nay thì đã có hơn 13 năm kinh nghiệm, thật không thể tin được. Tôi có đam mê và dành nhiều thời gian làm việc với WordPress mỗi ngày, hiện tại tôi đang phát triển giao diện và plugin cho WordPress.
Nếu bạn đang cần người làm trang web bằng WordPress? Hãy liên hệ với tôi ngay để được tư vấn nhé.
Không có bình luận.
Bạn có thể trở thành người đầu tiên để lại bình luận.