Is using register_activation_hook required?

You don’t have to use the register_activation_hook or register_deactivation_hook hook, they are optional. As their name suggests, they are hooks planned to run a task on plugin’s activation/deactivation, such as updating the status of all users for some purpose. So, if your plugin doesn’t require such tasks, then simply don’t use them. If you want … Read more

Can’t get JS code to work with shortcode

You need to return the Shortcode generated string, not echo, like this: function gg_product_front_end() { wp_register_script( ‘gg_loadProducts_frontEnd’, plugins_url( ‘js/front_end.js’, __FILE__ ), array( ‘jquery’ )); wp_enqueue_script( ‘gg_loadProducts_frontEnd’ ); return ‘<p id=”test”>Test!</p>’; } Also, you need to call the JavaScript function, like this: function gg_loadProducts_frontEnd() { console.log( ‘Test!’ ); } gg_loadProducts_frontEnd(); Otherwise Test! will not be logged … Read more

Use php libarary in wordpress plugins

You can always use the Composer when making a plugin and require all its dependencies. But as MikenGarrett said, finally you have to bundle all the required vendors into the plugin as a whole package. There are WordPress repository, containing /vendor/ directory1 and their development environment containing composer.json file declaring production-dependencies (‘require’)2. But using Composer … Read more

Can I differentiate between “Delete Post Permanently” and “Empty Trash” and do something for each accordingly?

So as leymannx pointed out in his comment, the “delete_post” hook actually handles both scenarios I was looking for, as it seems to know to run a “for each post deleted, do x” when “Empty Trash” is clicked and will also “do x” when “Delete Post Permanently” is clicked! My final code ended up looking … Read more

What is the use of get_option method

Well, as you can see in the contributed example to the WordPress Reference, it is not that add_settings_field magically knows about a setting being true or false, and it is not limited to checkboxes (boolean flags): Instead, the function signature states clearly that the $callback parameter it is required. And the introduction says: The $callback … Read more