Ẩn Menu trong Admin Menu
function remove_menus(){
remove_menu_page( 'index.php' ); //Dashboard
remove_menu_page( 'edit.php' ); //Posts
remove_menu_page( 'upload.php' ); //Media
remove_menu_page( 'edit.php?post_type=page' ); //Pages
remove_menu_page( 'edit-comments.php' ); //Comments
remove_menu_page( 'themes.php' ); //Appearance
remove_menu_page( 'plugins.php' ); //Plugins
remove_menu_page( 'users.php' ); //Users
remove_menu_page( 'tools.php' ); //Tools
remove_menu_page( 'options-general.php' ); //Settings
}
add_action( 'admin_menu', 'remove_menus' );
Chế độ bảo trì nhanh
function hdev_che_do_bao_tri()
{
if (!current_user_can(‘edit_themes’) || !is_user_logged_in()) {
wp_die(‘Trang web tạm thời đang được bảo trì. Xin vui lòng quay trở lại sau.’);
}
}
add_action(‘get_header’, ‘hdev_che_do_bao_tri’);
Vô hiệu hóa WooCommerce Admin
add_filter( 'woocommerce_admin_disabled', '__return_true' );
Thêm font đuôi .woff vào upload
function my_myme_types($mime_types){
$mime_types['woff'] = 'application/x-font-woff';
return $mime_types;
}
add_filter('upload_mimes', 'my_myme_types', 1, 1);
Bật Classic Editor
add_filter('use_block_editor_for_post', '__return_false');
Bật Classic Widgets
add_filter( 'gutenberg_use_widgets_block_editor', '__return_false' );
add_filter( 'use_widgets_block_editor', '__return_false' );
Dịch nhanh Woocommerce
add_filter( 'gettext', 'huanle_translate_woocommerce_strings', 999 );
function huanle_translate_woocommerce_strings( $translated ) {
$translated = str_ireplace( 'Đọc tiếp', 'Xem thêm', $translated );
return $translated;
}
Check SĐT hợp lệ Contact Form 7
function custom_filter_wpcf7_is_tel( $result, $tel ) {
$result = preg_match( '/((09|03|07|08|05)+([0-9]{8})\b)/', $tel );
return $result;
}
add_filter( 'wpcf7_is_tel', 'custom_filter_wpcf7_is_tel', 10, 2 );
Cấu hình SMTP
add_action( 'phpmailer_init', function( $phpmailer ) {
if ( !is_object( $phpmailer ) )
$phpmailer = (object) $phpmailer;
$phpmailer->Mailer = 'smtp';
$phpmailer->Host = 'smtp.gmail.com';
$phpmailer->SMTPAuth = 1;
$phpmailer->Port = 587;
$phpmailer->Username = 'lehuanpro@gmail.com'; // Tài khoản gmail
$phpmailer->Password = 'yiovemykuxrszvpw'; // Mật khẩu ứng dụng
$phpmailer->SMTPSecure = 'TLS';
$phpmailer->From = 'lehuanpro@gmail.com'; // Tài khoản gmail gửi mail
$phpmailer->FromName = 'HuanLe Media'; // Tên tài khoản gửi mail
});