REST API – filters not working inside plugin class

This is a problem: public function __contruct() it should be __construct, the S is missing, meaning there is no constructor and the add_filter calls never happen The function that registers the routes also never runs because the add_action call is commented out: //add_action( ‘rest_api_init’, array( $this, ‘extend_default_routes’ ) ); This means the constructor never runs, … Read more

Get a list of folders inside uploads directory

The closest is the WP Filesystem API, but that’s mainly intended for compatibility purposes, e.g. to enable files to be written when the only access is via FTP and direct filesystem write access is unavailable. Particularly: https://developer.wordpress.org/reference/classes/wp_filesystem_base/dirlist/ However, if you are not distributing this code and only using it for yourself or known environments, you … Read more

how to test for options(fields) in settings API?

Before saving the options the first time get_option( ‘rtwhc_settings’ ) returns false as the option doesn’t exist. Saving values, deleting them and then saving again causes the value of get_option( ‘rtwhc_settings’ ) to be an array with the field names as keys, which have empty values. You can see this, if you var_dump() the option … Read more

Import WordPress header / footer into an external page(s)

You haven’t really given enough information to know what options you have within the software. You may be able to use a setting or hook into the loading of your forum. But, if not, perhaps you could use a combination of html, jquery and ajax to solve this. In your header/footer you could just hold … Read more

Too few arguments – wp_login action

The custom role needs the read capability to view the backend. Example: $your_role = get_role(‘your_custom_role’); $your_role->add_cap( ‘read’ ); See: https://wordpress.org/documentation/article/roles-and-capabilities/#read Ideally, this should only be done once, e.g. when activating your plugin or theme.

Deleting all CPT related to user deleting

Using the action hook delete_user is the right way to do it, but there are a couple of things missing. The main one being that you haven’t set up any $args for the WP_Query that fetches the custom post type entries with the user-id metakey of the deleted user. add_action( ‘delete_user’, ‘delete_his_posts’); function delete_his_posts($user_id) { … Read more

Compare user meta values before update them

So you need to check if the values for a single user meta field are different or the same as the new values? If so, you don’t need to check the current values. Simply update the meta field regardless. It will be slower to check the current values and there is no benefit to doing … Read more

Help with AJAX request

The code you provided is on the right track, but it’s possible that the issue you’re facing is related to WordPress’s admin-ajax.php handling. Here’s how you can modify your code to make sure you stay on the same page after submitting the form: Change the form action to the current page instead of admin-ajax.php. Form: … Read more

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