Created
April 24, 2023 06:44
-
-
Save jamesckemp/fea2e9dceaf97cde55566d26a1fdfbb1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Filter the list of active plugins for custom endpoint requests. | |
* | |
* @param array $active_plugins The list of active plugins. | |
* | |
* @return array The filtered list of active plugins. | |
*/ | |
function filter_active_plugins( $active_plugins ) { | |
if ( ! is_custom_endpoint_request() || ! is_array( $active_plugins ) ) { | |
return $active_plugins; | |
} | |
$allowed_plugin_files = array( 'setary.php', 'woocommerce.php' ); | |
$filtered_plugins = array(); | |
foreach ( $active_plugins as $plugin ) { | |
foreach ( $allowed_plugin_files as $allowed_plugin_file ) { | |
if ( strpos( $plugin, $allowed_plugin_file ) !== false ) { | |
$filtered_plugins[] = $plugin; | |
break; | |
} | |
} | |
} | |
return $filtered_plugins; | |
} | |
add_filter( 'option_active_plugins', 'filter_active_plugins' ); |
@Dan0sz I just check if the path contains wc/setary, but you could also pass an additional get parameter ?setary=1
Man, this is interesting. And so simple! Thanks a lot, man!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing! One last question I have, how do you decide when it's a custom endpoint request? Do you simply check the endpoint that's being called?