• Resolved d1gsolutions

    (@d1gsolutions)


    Hi Jordy,

    I was hoping to move all my custom code from functions.php to the Snippet Vault Plugin. I noticed the “Safe Mode” issue in version 0.1.1, and today I was happy to discover that version 0.1.2 has fixed it.

    However, I’ve observed that with Snippet Vault Plugin (version 0.1.2), the snippets are not triggered properly. I created four triggers (with different scopes) to monitor the behavior. Here is a link to the details:
    https://monosnap.com/file/3mX4Fm5U0m3gcsG6L3vKJKfax8XwBR

    Unfortunately, I’m not able to precisely report what is happening, but I do know that when loading the home page without being authenticated, none of the snippets are triggered. However, the snippets are triggered at login and on some pages that contain a JavaScript callback.

    Best regards,
    Catalin

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Val Meow

    (@valwa)

    Hey @d1gsolutions! ??

    For security purposes, before executing snippets, we ensure the requested root is part of a whitelist that contains only a small number of endpoints. Snippet Vault is primarily designed to run snippets executed from your WordPress REST API, so any request not sent from /wp-json/ will not be accepted (except for the admin pages, which are whitelisted automatically).

    You can manually alter these whitelisted endpoints by using the “meow_mwcode_white_listed_rest” filter, which returns the array of currently allowed REST endpoints.

    If, for any reason, you want snippets to be executed outside of WordPress REST API calls, you can use the “meow_mwcode_white_listed_rest_authorized” filter. This filter provides access to $authorized and $requested_route, allowing you to create your own conditions to validate the execution of any route.

    Hope this helps!

    Thread Starter d1gsolutions

    (@d1gsolutions)

    Hi @valwa ,
    Thank you for your quick answer. I’ve tried to use both (meow_mwcode_white_listed_rest,meow_mwcode_white_listed_rest_authorized) hooks, but it didn’t worked. Maybe I’m doing something wrong, or I don’t understand how to use it.
    I’m quite new with WordPress&Wordpress plugins. I added the following code to functions.php, but the function is never executed.

    // Custom function to authorize specific routes
    function custom_meow_mwcode_white_listed_rest_authorized($authorized, $requested_route) {
    // Debug: Log the function call
    error_log('custom_meow_mwcode_white_listed_rest_authorized called');
    
    // Custom allowed routes
    $custom_allowed_routes = array(
        '/',
        '/blog/'
    );
    
    // Check if the requested route starts with any of the custom allowed routes
    foreach ($custom_allowed_routes as $route) {
        if (strpos($requested_route, $route) === 0) {
            // Debug: Log the matched route
            error_log('Authorized route: ' . $route);
    
            $authorized = true;
            break;
        }
    }
    
    return $authorized;
    }
    
    // Adding the custom function to the filter
    add_filter('meow_mwcode_white_listed_rest_authorized', 'custom_meow_mwcode_white_listed_rest_authorized', 10, 2);

    I’m trying to use Snippet Vault Plugin to store the code that I usually put inside functions.php.
    I like the idea that I can Import/Export my snippets and that I have a Snippet Endpoint that I can use.

    Thank you,
    Catalin

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Snippet Vault Plugin (version 0.1.2), the snippets are not triggered properly’ is closed to new replies.