PHP/plugin Development Flashcards
Should you ever touch any wordpress core files?
NO!!!!!
what is this doing:
if ( ! defined( ‘ABSPATH’ ) ) {
exit;
}
defined( ‘ABSPATH’ ): This checks if the constant ABSPATH has been defined. ABSPATH is a constant in WordPress that contains the absolute path to the root directory of the WordPress installation.
!: This is a negation operator, so ! defined( ‘ABSPATH’ ) means “if ABSPATH has not been defined.”
exit;: This stops the script from running.
Purpose:
The purpose of this code is to prevent direct access to PHP files in WordPress. If someone tries to directly access a file (such as by typing its URL in the browser), WordPress will prevent it from running unless it’s being accessed through WordPress itself.
If ABSPATH is not defined, it means the file is likely being accessed directly, and the script exits immediately to avoid potential security risks. This is a common security measure in WordPress development, especially for plugins and themes.
what does the add_action function do in wordpress?
The add_action function allows you to attach your custom function to a specific action hook in WordPress. When that action hook is triggered, your custom function will be executed.
add_action( ‘hook_name’, ‘function_name’, [priority], [arguments] );
what is the php function isset()?
In PHP, isset() is a built-in function that checks if a variable is set and is not null. It returns a boolean value (true or false) depending on whether the variable is defined and has a value other than null.
what is maybe_unserialize
In WordPress, the function maybe_unserialize() is a utility function used to conditionally unserialize data. It checks if a string is serialized and only unserializes it if it is, otherwise it returns the value as-is. This helps prevent errors when trying to unserialize data that is not in a serialized format.
what does the init wordpress action do?
// The init
action runs after WordPress has finished loading but before any output is sent to the browser.
what is a wordpress action
In WordPress, an action is a type of hook that allows you to add or modify functionality at specific points in the WordPress lifecycle. Actions are part of WordPress’ Hooks system, which enables developers to insert their custom code into WordPress without modifying core files.
is there a refrence for all the built in functions that wordpress has?
yes it can be found here: https://developer.wordpress.org/reference/functions/