defined( 'ABSPATH' ) || exit;contains the absolute path to the WordPress root directory. If php run directly, it exits.
$this
- Refers to the current object instance
- Used for non-static properties and methods
- Only available inside object context
self::
- Refers to the class itself
- Used for static properties and methods
- Does NOT require an object
add_action( 'init', array( $post_types, 'register_post_types' ) )is a callable reference that means:
When the
inithook fires, call$post_types->register_post_types()
load_plugin_textdomain()is a WordPress function that tells WordPress:
Here’s the folder and text domain for my plugin translations — load them now.”
- It basically activates your plugin’s translations so all
__()and_e()strings can be displayed in the user’s language.
dirname( plugin_basename( __FILE__ ) ) . '/languages' → relative path to translations
Let’s break it down:
__FILE__→ full path of the current PHP file
Example:/var/www/html/wp-content/plugins/rt-movie-db/rt-movie-db.phpplugin_basename(__FILE__)→ plugin folder + main file relative to/wp-content/plugins/rt-movie-db/rt-movie-db.phpdirname(...)→ just the folder namert-movie-dbdirname(...) . '/languages'→ folder where.mofiles livert-movie-db/languages
Translation
Code:
echo __( 'Watch Movie', 'rt-movie-db' );
echo _x( 'Movies', 'post type general name', 'rt-movie-db' );
.po file snippet (French):
msgid "Watch Movie"
msgstr "Regarder le film"
msgctxt "post type general name"
msgid "Movies"
msgstr "Films"
WordPress will output:
Regarder le film
Films
- COmmon labels
| Key | Purpose |
|---|---|
name | General plural name for the taxonomy |
singular_name | Singular name |
search_items | Text for search box in admin |
all_items | Label for “All terms” view |
parent_item | Label for parent term (hierarchical only) |
edit_item | Label when editing a term |
add_new_item | Label when adding a new term |
new_item_name | Label for “New term name” |
menu_name | Label shown in the admin menu |
- Common args:
| Key | Purpose |
|---|---|
hierarchical | true = like categories, false = like tags |
labels | the $labels array |
show_ui | show admin UI for taxonomy |
show_admin_column | show column in post list table |
query_var | enable URL query variable for taxonomy |
rewrite | array for URL slugs |
show_in_rest | enable Gutenberg / REST API support |
public | whether taxonomy is publicly queryable |
capabilities | permissions for editing terms |
update_count_callback | function to update term counts (for non-hierarchical) |