Các hàm trong WordPress
get
get_stylesheet_directory_uri(): string
Lấy URL thư mục giao diện con.
get
get_theme_mod( string $name, mixed $default_value = false ): mixed
Lấy tùy chỉnh của giao diện.
get
get_option( string $option, mixed $default_value = false ): mixed
Lấy giá trị của một tùy chọn trong cơ sở dữ liệu.
'admin_email' – Địa chỉ email của quản trị viên trang web.
'blogname' – Tiêu đề của trang web; được thiết lập trong Cài đặt Chung.
'blogdescription' – Phương châm (tagline) của trang web; được thiết lập trong Cài đặt Chung.
'blog_charset' – Mã hóa ký tự của trang web; được thiết lập trong Cài đặt Đọc.
'date_format' – Định dạng ngày mặc định; được thiết lập trong Cài đặt Chung.
'default_category' – Danh mục bài viết mặc định; được thiết lập trong Cài đặt Viết.
'home' – Địa chỉ trang chủ của trang web; được thiết lập trong Cài đặt Chung.
'posts_per_page' – Số bài viết tối đa hiển thị trên một trang; được thiết lập trong Cài đặt Đọc.
'posts_per_rss' – Số bài viết gần đây nhất tối đa hiển thị trong nguồn cấp dữ liệu; được thiết lập trong Cài đặt Đọc.
'siteurl' – Địa chỉ web của WordPress; được thiết lập trong Cài đặt Chung.
Lưu ý: Không giống như get_bloginfo('url') (trả về URL trang chủ), mà giống với get_bloginfo('wpurl').
'template' – Tên của giao diện (theme) hiện tại.
'start_of_week' – Ngày bắt đầu của tuần trong lịch; được thiết lập trong Cài đặt Chung.
'upload_path' – Đường dẫn tải lên mặc định; được thiết lập trong Cài đặt Thư viện.
'users_can_register' – Cho phép người dùng đăng ký hay không; được thiết lập trong Cài đặt Chung.
echo get_option('admin_email');
Email admin website
filter hook
apply_filters( string $hook_name, mixed $value, mixed $args ): mixed
Thêm một hàm vào filter hook.
delete
delete_transient( string $transient ): bool
Xóa một transient khỏi cơ sở dữ liệu.
delete
wp_delete_comment( int|WP_Comment $comment_id, bool $force_delete = false ): bool
Xóa một bình luận khỏi cơ sở dữ liệu.
delete
delete_term_meta( int $term_id, string $meta_key, mixed $meta_value = ” ): bool
Xóa giá trị meta của thuật ngữ.
delete
delete_user_meta( int $user_id, string $meta_key, mixed $meta_value = ” ): bool
Xóa giá trị meta của người dùng.
delete
wp_delete_post( int $post_id, bool $force_delete = false ): WP_Post|false|null
Xóa một bài viết khỏi cơ sở dữ liệu.
delete
delete_option( string $option ): bool
Xóa một tùy chọn khỏi cơ sở dữ liệu.
create
wp_create_user( string $username, string $password, string $email = ” ): int|WP_Error
Tạo một người dùng mới.
create
wp_create_category( int|string $cat_name, int $category_parent ): int|WP_Error
Tạo một danh mục (category) mới.
check
is_admin(): bool
Kiểm tra xem người dùng có đang ở trong khu vực quản trị hay không.
check
is_user_logged_in(): bool
Kiểm tra xem người dùng có đăng nhập hay không.
action hook
add_action( string $hook_name, callable $callback, int $priority = 10, int $accepted_args = 1 ): true
Thêm một hành động vào hook.
function disable_comment_reply_script() {
if (is_singular() && comments_open() && get_option('thread_comments')) {
wp_deregister_script('comment-reply');
}
}
add_action('wp_enqueue_scripts', 'disable_comment_reply_script');
Không load file comment-reply.js
action
do_action( string $hook_name, mixed $arg )
Thực thi một action hook.
set
set_post_thumbnail( int|WP_Post $post, int $thumbnail_id ): int|bool
Thiết lập ảnh đại diện cho bài viết.
set
set_transient( string $transient, mixed $value, int $expiration ): bool
Thiết lập giá trị transient vào cơ sở dữ liệu.
set
set_current_user( int|null $id, string $name = ” ): WP_User
Thiết lập người dùng hiện tại.
update
wp_update_user( array|object|WP_User $userdata ): int|WP_Error
Cập nhật người dùng trong cơ sở dữ liệu.
get
get_available_languages( string $dir = null ): string[]
Nhận tất cả các ngôn ngữ có sẵn dựa trên sự hiện diện của các tệp *.mo và *.l10n.php trong một thư mục nhất định.
$languages = get_available_languages();
$select_lang = wp_dropdown_languages(
array(
'name' => 'locale',
'id' => 'locale',
'selected' => $locale,
'languages' => $languages,
'show_available_translations' => false, //$can_install_translations,
'show_option_site_default' => false,
'echo' => false
)
);
//TRả về dropdownlist ngôn ngữ
get
wp_get_available_translations(): array
Nhận bản dịch có sẵn từ API WordPress.org.
action
wp_footer()
Kích hoạt hành động wp_footer.
function wpdocs_js_code_example() {
?>
<?php
}
add_action( 'wp_footer', 'wpdocs_js_code_example' );
//Thêm script vào footer
action
single_cat_title( string $prefix = ”, bool $display = true ): string|void
Hiển thị hoặc truy xuất tiêu đề trang để lưu trữ danh mục.
get
wp_get_current_user()
Truy xuất đối tượng người dùng hiện tại.
get
plugins_url( string $path = ”, string $plugin = ” ): string
Truy xuất một URL trong thư mục plugin hoặc mu-plugins.
get
plugin_dir_url( string $file ): string
Lấy đường dẫn thư mục URL (có dấu gạch chéo ở cuối) cho plugin __FILE__ được chuyển vào.
action
wp_nav_menu( array $args = array() ): void|string|false
Hiển thị một menu điều hướng.
delete
wp_delete_file( string $file ): bool
Xóa một tập tin.
$file_path = "/home/public_html/wp-content/uploads/2020/04/photo_img_1-8.png" // path of the file which need to be deleted.
wp_delete_file( $file_path ); //delete file here.
true or false