Delete data from database using row action

The “admin_action_{$_REQUEST[‘action’]}” hook does not pass any arguments. You would need to get the article_id from the $_REQUEST array. There are also a few other concerns such as: You’re not assigning an action when you call wp_create_nonce(). As Mafnah suggets in their ansewr, you should use $wpdb::delete() as a shortcut for using $wpdb::prepare(). Here’s how … Read more

How leave selected checkboxes marked after they are selected and saved in the database

You can use get_option() to retrieve the selected role(s) that were saved in the database, then use checked() in your checkboxes. E.g. // In your code, after this line: $roles = $wp_roles->get_names(); // Add this which retrieves and stores the selected role(s): $selected_roles = (array) get_option( ‘choosed_users_role’ ); /* And then in your <input>, use … Read more

How to only load css for used blocks on frontend

To get separate files for each block you’ll need to bring your own webpack config One as simple as this should work: const defaultConfig = require(‘@wordpress/scripts/config/webpack.config’); module.exports = { …defaultConfig, entry: { ‘hero’: ‘./src/hero’, ‘call-to-action’: ‘./src/callToAction’, }, }; Ryan Welcher has an example repo and a video walk-through of its creation (that link is to … Read more

Update custom plugin with WP-CLI

You would implement this: https://make.wordpress.org/core/2021/06/29/introducing-update-uri-plugin-header-in-wordpress-5-8/ First you would add a Update URI: header to your plugin with a custom domain. Second, you would add a filter to your plugin, using the filter name update_plugins_{$hostname} where {$hostname} is the value you gave your Update URI: . E.g. Update URI: example.com would have the filter update_plugins_example.com. In … Read more

Redeclaring a plugin function within a class

How does wordpress know that the add_meta_box() function used inside the user-defined add_meta_box( $post_type ) function is a plugin function and not a recursive one? It doesn’t, WordPress just calls it, so you can indeed create infinite loops. Instead what I think you’re asking is how PHP knows to call that class method and not … Read more

Can’t get AJAX call working in custom plugin

So the AJAX action defined in Myplugin::define_admin_hooks() has been corrected (it’s just a typo in the question). But there’s another issue in your code, also in the above function, where the second parameter for $this->loader->add_action() should actually be $plugin_admin (which is an object and an instance of the Myplugin_Admin class) and not wp_ajax: Incorrect: $this->loader->add_action( … Read more