• Resolved fabx77

    (@fabx77)


    Hello
    1/ I created some code, but it doesn’t execute, even though it’s active.

    2/ I added a display of the contents of my variables (ACF), but I don’t see them. Neither on the website screen nor in the debug.log file.

    For example, I’m using:

    echo ‘Hello’;

    var_dump ($name_variable);

    error_log( print_r( $acf_name_variable) );

    do_action( ‘inspect’, [ ‘variable_name’, $acf_name_variable ] );

    ps: In my wp-config.php file, all “debug_XXX” entries are set to true.

    Thank you very much for your help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Carolina

    (@carolinaop)

    Hi @fabx77,

    Thanks for reaching out! I had a look at your message, and from what you’ve shared, it doesn’t look like the issue is directly related to the Code Snippets plugin itself. The plugin’s job is to safely run your PHP code, but it can’t fix or debug the code logic itself — that part still works just like it would in your theme’s functions.php file.

    That said, I’d love to help you get things working! Here are a few things to check:

    1. Where is your snippet set to run?
    Make sure your snippet is set to run in the right context. If it’s meant to run on the front end, choose “Only run on site front-end” or “Run everywhere” when creating the snippet.

    2. Are you using the right hooks?
    If your code depends on WordPress loading certain things (like ACF fields), you might need to wrap it in an action hook like:
    add_action( 'wp', function() { // your code here });

    3. Debugging output
    echo and var_dump won’t show anything if the code runs before the page output starts or in the wrong context.
    error_log() should work if WP_DEBUG and WP_DEBUG_LOG are both set to true in your wp-config.php. Make sure you’re checking the right debug.log file (usually in wp-content).

    Let us know if this helps!

    Thread Starter fabx77

    (@fabx77)

    Hi Caroline,

    Thank you so much for your information!

    I have to add var_dump($name_variable); to my procedure because I’ve noticed that my code isn’t executing and I can’t even see the variables displayed by another plugin called “variable_inspector”.

    I have four options in your plugin to run the code:

    • Run everywhere
    • Run only in the admin area
    • Run only in the public interface
    • Run only once

    I’ve tried each one, but the code still doesn’t run… Here’s just the beginning of my code:

    ==================================================================

    // Create a cron job to run the day after an event happens or ends
    function set_expiry_date( $post_id ) {

    / // See if an event_end_date or event_date has been entered, and if not, then end the function

    if( get_post_meta( $post_id, $key = ‘date_de_latelier’, $single = true ) ) {

    / // Get the end date of the event in Unix grenwich mean time
    $acf_date_de_latelier = get_post_meta( $post_id, $key = ‘date_de_latelier’, $single = true );

    var_dump($acf_date_de_latelier);
    do_action(‘inspect’, [‘variable_name’, $acf_date_de_latelier]);

    } else {

    // No start or end date. Lets delete any CRON jobs related to this post and end the function.
    wp_clear_scheduled_hook(‘make_past_event’, array($post_id));
    return; }

    ……

    The “workshop_date” variable is, of course entered for each article.

    Thank you.

    ps:WP_DEBUG and WP_DEBUG_LOG are indeed enabled in the config.php file.

    • This reply was modified 1 month ago by fabx77.
    Plugin Contributor Carolina

    (@carolinaop)

    Hi @fabx77,

    Thank you for the detailed explanation and code sample.

    From what you’ve described, this doesn’t indicate an issue with the Code Snippets plugin itself. When a snippet is active, our plugin loads it the same way WordPress loads code from a theme’s functions.php file. However, defining a function does not automatically execute it.

    In your example, you are defining:

    function set_expiry_date( $post_id ) {

    But this function will only run if it is attached to a WordPress hook (for example save_post) or called somewhere else in your code. If it is not hooked or called, it will never execute — which would explain why:

    • var_dump() shows nothing
    • echo shows nothing
    • error_log() does not write anything
    • Variable Inspector does not display anything

    Additionally, please make sure:

    • You are using straight quotes (') and not curly/smart quotes (‘ ’), as those will break PHP execution.
    • The snippet does not contain malformed comments.
    • The function is properly attached to the correct WordPress or ACF hook so that $post_id is actually available when it runs.

    Since Code Snippets only executes the PHP code safely but does not alter how WordPress hooks or ACF logic works, the behavior you’re seeing is consistent with the function simply not being triggered.

    To quickly confirm that Code Snippets is executing properly, please try this php test snippet:

    add_action( 'init', function () {
    error_log( 'Code Snippets test: snippet executed successfully.' );
    } );

    How to test it:

    1. Add this as a new snippet.
    2. Set it to Run everywhere.
    3. Visit any page of your site.
    4. Check your wp-content/debug.log file (or your server’s PHP error log).

    If you see this line in the log: “Code Snippets test: snippet executed successfully.”

    If you’re experiencing an issue specifically with the snippet not saving or activating properly, please let us know which plugin version you’re using and we’ll be happy to investigate further.

    Let us know if this helps.

    Plugin Contributor Carolina

    (@carolinaop)

    Hello @fabx77

    Since we haven’t received any further feedback, I’ll go ahead and close this ticket for now. Please feel free to reopen it at any time if needed—we’ll be happy to assist 🙂

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.