Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use editable_extensions filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
June 10, 2023
5 minutes read

 

Alright, let’s dive into the world of WordPress hooks! If you’re like me, always tinkering with WordPress to make it just right, you’re in the right place. Today, we’re talking about the editable_extensions filter. It’s all about filtering the list of file types you can edit in the plugin file editor. Pretty handy, right?

Example 1: Basic Usage of editable_extensions

Here’s a straightforward example of how you can use the editable_extensions hook. The function weplugins_modify_editable_extensions_defaults is created to modify the default types based on your specific needs.

    function weplugins_modify_editable_extensions_defaults($default_types, $plugin) {
        // Update the $default_types variable according to your website requirements and return this variable. 
        return $default_types; 
    }
    // Add the filter
    add_filter("editable_extensions", "weplugins_modify_editable_extensions_defaults", 10, 2);
    

Example 2: Conditional Modification

Sometimes, you might need to conditionally modify the editable file extensions. Here’s how you can do that.

    function weplugins_modify_editable_extensions_conditionally($default_types, $plugin) {
        // Check some condition, for example, a specific plugin
        if ($plugin === 'specific-plugin/specific-file.php') {
            $default_types[] = 'json'; // Add json extension
        }
        return $default_types;
    }
    // Add the filter
    add_filter("editable_extensions", "weplugins_modify_editable_extensions_conditionally", 10, 2);
    

Example 3: Removing the Hook

If you ever find the need to remove a previously registered hook, here’s a quick guide on how to do it. Just make sure you use the same callback function, priority, and number of arguments.

    // Remove the filter
    remove_filter("editable_extensions", "weplugins_modify_editable_extensions_defaults", 10, 2);
    

Access Premium WordPress Plugins

Contact Us

If you’re having any trouble using this hook or need customization, don’t hesitate to contact us. We’re here to help!

 

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.