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

Execute wp_after_insert_post after the permalink is customized

To execute update_post_meta after the permalink is customized, you can use the save_post hook instead of wp_after_insert_post. Here’s how you can modify your code: add_action(‘save_post’, ‘add_permalink_to_new_post’, 10, 2); function add_permalink_to_new_post($post_id, $post) { // Check if this is a new post if ($post->post_date_gmt == $post->post_modified_gmt) { // Only run this on a newly created post update_post_meta($post_id, … Read more

Issue with WordPress Plugin Activation Hook and Table Creation

Not sure if this helps but try doing this in the main plugin file: require plugin_dir_path(__FILE__).’inc/plugin-setting.php’; require plugin_dir_path(__FILE__).’inc/db.php’; // Register activation hook in the main plugin file register_activation_hook(__FILE__, ‘wp_comment_reactions’); Move your function wp_comment_reactions to the db.php file and call it from the main plugin file.