`post_updated_messages` filter

The function you attach as a filter needs to take in a variable as an argument and return that variable once it’s done processing whatever it is you need it to do. For example: function wpse426272_messages( $messages ) { $messages[‘game’] = array( ‘Game updated’, ‘Game published’, ‘etc’ ); return $messages; } add_filter( ‘post_updated_messages’, ‘wpse426272_messages’ );

How to use native wordpress translation domain inside a custom plugin?

How to use native wordpress translation domain inside a custom plugin? You would use __() without a textdomain, but this won’t work for you because that’s not how post status labels work. get_post_status doesn’t return the name of the post status, it returns a slug, e.g. pending not Pending. The solution is in the user … Read more

Fetch portion of Admin URL

Detecting WordPress admin screens using URL parameters can be a pain in the butt and also raise security issues. However, there’s a whole set of built in functions ready to help… but first off, why are you trying to detect an admin page using a funky string like admin.php?page=my-custom-page is this an admin page? an … Read more

Add Imports to Existing WordPress Import Map

Turns out to be quite simple in WordPress 6.5. Use wp_register_script_module to register the imports, and include them as dependencies in wp_enqueue_script_module: add_action(‘wp_enqueue_scripts’, ‘enqueue_three_d_script’); function enqueue_three_d_script() { wp_register_script_module( ‘three’, “https://unpkg.com/[email protected]/build/three.module.js”, array(), null ); wp_register_script_module( ‘three/addons/’, “https://unpkg.com/[email protected]/examples/jsm/”, array(), null ); wp_enqueue_script_module( ‘three-d-script’, SCRIPTS_DIR . ‘threeDTest.js’, array(‘three’, ‘three/addons/’), null ); }

$_GET[”] variable with nonce verification

There are two ways of creating nonce verification for $_GET parameters: If you are coming from a form, you can use the wp_nonce_field function to create your own field. For example: <form action=”edit.php” method=”get”> <input type=”text” name=”example”> ….. <?php wp_nonce_field(‘my_custom_action’, ‘my_custom_name’); ?> <input type=”submit” value=”Submit”> </form> If you are coming from a link you created, … Read more

Custom page template from plugin does not work with pre-installed themes in WordPress 6.6.1

Newer themes including Twenty Twenty Four use block themes/Full Site Editing. This means all the templates are created with HTML and theme.json, not using PHP templates at all anymore. You can read up on bloc themes, and see ways to create a “hybrid theme” which uses both PHP and HTML, here – https://fullsiteediting.com/courses/full-site-editing-for-theme-developers/

Load specific CSS file

/** * Enqueue a script or stylesheet in the WordPress admin on edit.php. * * @param string $hook_suffix Hook suffix for the current admin page. */ function wpse426722_admin_enqueue( $hook_suffix ) { if( ‘admin_print_scripts-profile’ == $hook_suffix ) { wp_enqueue_style( ‘your-stylesheet-slug’, ‘/path/to/your_stylesheet.css’ ); } } add_action( ‘admin_enqueue_scripts’, ‘wpse426722_admin_enqueue’ ); The above function has the hook suffix for … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)