How to get path or root of plugin folder, not file or dir?

How about just define a constant that stores the plugin’s root path? Define path constant For calling numerous files, it is sometimes convenient to define a constant: define( ‘MY_PLUGIN_PATH’, plugin_dir_path( __FILE__ ) ); include( MY_PLUGIN_PATH . ‘includes/admin-page.php’); include( MY_PLUGIN_PATH . ‘includes/classes.php’); // etc. — See https://developer.wordpress.org/reference/functions/plugin_dir_path/#comment-491 So in your main plugin file: define( ‘MY_PLUGIN_PATH’, plugin_dir_path( … Read more

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

Plugins ignored a line breaks or tag in the WordPress comment functions

On orbisius-support-tickets/modules/core/cpt.php file the comment is sanitised as a single-line input with the function sanitize_text_field() which removes the line breaks. For a textarea field WordPress has sanitize_textarea_field(); Ref: https://developer.wordpress.org/reference/functions/sanitize_textarea_field/ On that file, you can find the line $comment = sanitize_text_field( wp_strip_all_tags( $_POST[‘comment’] ) ); And replace it with: $comment = sanitize_textarea_field( wp_strip_all_tags( $_POST[‘comment’] ) );

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