This document provides an overview of the allowed WordPress functions for use in your widget options logic. The functions are categorized based on their purpose, including Database Operations, Escaping and Sanitizing, URL and Links, Security and Authentication, Formatting, Metadata and Post Details, Plugins and Themes, User and Authentication, Media and Files, Taxonomies, and Checking Functions.
1. Database Operations #
These functions handle retrieving data from the WordPress database, such as options, posts, and user data.
get_option– Retrieve an option value from the database.get_post– Retrieve a post by ID.get_user_meta– Retrieve user metadata.get_bloginfo– Get information about the WordPress site (like URL, name, etc.).get_theme_mod– Get theme modifications.
2. Escaping and Sanitizing #
These functions help with escaping and sanitizing data to prevent security vulnerabilities.
esc_url– Escape a URL for safe output.esc_html– Escape HTML for safe output.esc_attr– Escape an attribute for safe HTML output.esc_js– Escape JavaScript for safe output.sanitize_text_field– Sanitize a text field (removes harmful characters).sanitize_email– Sanitize an email address.sanitize_title– Sanitize a post title.sanitize_key– Sanitize a string key.
3. URL and Links #
Functions for working with URLs and link generation.
get_permalink– Retrieve the permalink (URL) of a post or page.get_home_url– Get the home URL of the WordPress site.get_site_url– Get the site URL.get_admin_url– Get the admin URL.wp_parse_url– Parse a URL into its components.urlencode– URL encode a string.urldecode– URL decode a string.rawurlencode– URL encode a string without special handling for certain characters.rawurldecode– URL decode a string without special handling.parse_url– Parse a URL and return its components.http_build_query– Build a URL-encoded query string from an array.
4. Security and Authentication #
Functions related to security, such as verifying nonces and checking user capabilities.
wp_verify_nonce– Verify that a nonce is valid.check_admin_referer– Check a referer for the admin area.current_user_can– Check if the current user has a specific capability.is_user_logged_in– Check if the current user is logged in.wp_nonce_field– Output a nonce field for security.wp_nonce_url– Generate a URL containing a nonce.
5. Formatting #
Functions that handle text formatting and processing.
wp_kses– Allow certain HTML tags in a string.wp_kses_post– Allow only post-related HTML tags in a string.wp_trim_words– Trim a string to a specific number of words.wpautop– Automatically add<p>and<br>tags to content.
6. Retrieval of Metadata and Post Details #
Functions for retrieving metadata or details about posts, pages, comments, and terms.
get_post_meta– Retrieve metadata for a specific post.get_page_template_slug– Get the template slug of a page.get_the_author_meta– Get metadata about the post’s author.get_the_terms– Get the terms (categories, tags) associated with a post.get_comments– Retrieve comments for a post or page.get_category– Get category information.get_terms– Retrieve terms from a specific taxonomy.get_nav_menu_locations– Get menu locations.get_posts– Retrieve a list of posts based on a query.get_post_status– Get the status of a post.get_comment_meta– Retrieve metadata for a specific comment.get_taxonomy– Retrieve taxonomy information.get_object_taxonomies– Get taxonomies associated with a specific object type.get_post_type– Get the post type for a given post.get_the_ID– Get the current post’s ID.get_the_title– Get the title of a post or page.get_edit_post_link– Get the URL to edit a post.
7. Plugins and Themes #
Functions related to plugins and theme features.
is_plugin_active– Check if a plugin is active.get_plugins– Get a list of installed plugins.get_theme_support– Check if a theme supports a specific feature.
8. Utilities #
General utility functions.
wp_generate_uuid4– Generate a UUID (version 4).
9. User and Authentication #
Functions for managing user data and authentication.
get_userdata– Get the data of a specific user by ID.get_user_by– Retrieve a user based on specific criteria (ID, login, email, etc.).get_users– Retrieve a list of users based on query parameters.get_author_posts_url– Get the URL to an author’s posts archive.get_user_roles– Get the roles of a user.get_users_by_role– Retrieve users with a specific role.wp_get_current_user– Retrieve the current logged-in user.
10. Media and Files #
Functions for managing media, file metadata, and image handling.
wp_get_attachment_image_src– Get the source URL for an attachment image.wp_get_attachment_url– Retrieve the URL of an attachment.wp_get_attachment_metadata– Retrieve metadata of an attachment.wp_get_attachment_image– Retrieve an image tag for an attachment.wp_get_attachment_thumb_url– Get the thumbnail URL for an attachment.
11. File Handling #
Functions for managing file uploads and directories.
wp_get_upload_dir– Retrieve the directory paths for uploaded files.wp_handle_upload– Handle a file upload.wp_check_filetype_and_ext– Check the file type and extension.wp_get_file_upload_url– Get the URL for file uploads.
12. Taxonomies #
Functions related to taxonomies (e.g., categories, tags).
get_term_meta– Retrieve metadata for a term.get_the_category_list– Get a list of categories for a post.get_the_tag_list– Get a list of tags for a post.get_the_term_list– Get a list of terms for a post, including custom taxonomies.
13. Checking Functions #
Functions for checking various conditions in WordPress.
is_admin– Check if the current request is for an admin page.is_network_admin– Check if the current request is for the network admin.is_main_query– Check if the current query is the main WordPress query.is_single– Check if a single post is being viewed.is_singular– Check if a single post type is being viewed.is_category– Check if the current view is a category archive.is_tag– Check if the current view is a tag archive.is_page– Check if the current view is a page.is_front_page– Check if the current view is the front page.is_home– Check if the current view is the blog home page.is_attachment– Check if the current view is an attachment.is_archive– Check if the current view is an archive.is_date– Check if the current view is a date archive.is_year– Check if the current view is a year archive.is_month– Check if the current view is a month archive.is_day– Check if the current view is a day archive.is_author– Check if the current view is an author archive.is_search– Check if the current view is a search results page.is_404– Check if the current view is a 404 error page.is_multisite– Check if the current site is part of a multisite network.is_customize_preview– Check if the customizer preview is active.
If you’d like to add custom functions that aren’t included in the default list of allowed functions, you can easily extend the functionality by adding a filter to your functions.php file (or any other suitable location in your theme or plugin).
To add multiple functions, simply add additional lines with the $allowed_functions[] array.
function add_extra_hooks( $allowed_functions ) {
// Add your custom functions here
$allowed_functions[] = 'function_to_add';
return $allowed_functions;
}
add_filter( 'widgetopts_allowed_php_functions', 'add_extra_hooks' );