Media Library Issues

What you need is a way to scan your uploads directory and register any unregistered files. There are plugins that can help with this. One such plugin is “Add From Server“. This allows you to import media and files into the WordPress uploads manager from the server’s file system. Using this plugin, you can import … Read more

How to keep rewrite_rule without flushing each time?

My usual trick to a) flush as required but b) not flush on every page load is to use an option to determine if the rewrites have changed, and flush only if they have indeed changed. Something like this: add_action( ‘wp’, ‘wpse_421338_maybe_flush_rewrites’ ); function wpse_421388_maybe_flush_rewrites() { $rewrite_obj = new WP_Rewrite(); $rewrites = $rewrite_obj->wp_rewrite_rules(); // Compare … Read more

Show only taxonomy types terms associated with a custom post type in WordPress PHP

UPDATE The custom SQL query below can be used to produce a list of unique types taxonomy terms that have been assigned to newsroom posts. In PHP, you can call the function get_newsroom_types_terms to get the list: $terms = get_newsroom_types_terms();. Custom SQL query function get_newsroom_types_terms() { global $wpdb; $table_prefix = $wpdb->prefix; $taxonomy = ‘types’; $post_type=”newsroom”; … Read more

Ajax call to a function in another module returns a 400 (Bad Request) error

Assuming your apps/save-books.php file contains the save_book_form() function and the wp_ajax_save_book_form hook, the problem is that you’re only including this file inside the admin_menu hook. The admin-ajax.php file does not run the admin_menu hook, so your apps/save-books.php file won’t be loaded for admin AJAX requests, which means that your action is never hooked. You need … Read more

Can’t access dashboard, no access to FTP

Your best approach is to retrieve emails related to the website setup. Reach out to someone who might have valuable insights on accessing either the wp-admin users or the hosting service provider account. Look for any clues in email threads, chat history, or any other information that could lead you to the previous developers. If … Read more

Non-super-admin users cannot access CPT even though I have explicitly added the capabilities to the user role

Here’s how I’d handle it (mostly you’re right, and the tweak in your answer to use init gets you closer, but — as you’ve discovered — doing a bunch of switch_to_blog() / restore_current_blog() calls on every single page load is costly). function add_opportunities_capability_to_admins() { // Set up the needed capabilities. $capabilities = array( ‘edit_opportunity’, ‘read_opportunity’, … Read more

How to restrict the unauthorized software download

To restrict unauthorized software downloads on your WordPress website, you can implement the following approaches: Membership/Subscription System: You can use a membership or subscription plugin to control access to your downloads. Users must create an account and pay for a subscription to access the download links. This way, you can track who has paid and … Read more

Sanitization of register_setting()

You can use sanitize_text_field exactly as you are. From the function’s documentation: Checks for invalid UTF-8, Converts single < characters to entities Strips all tags Removes line breaks, tabs, and extra whitespace Strips percent-encoded characters sanitize_text_field() is already defined as a function in WordPress, so you don’t need to change anything. The sanitize_callback parameter takes … Read more