• what is wrong?
    thanks
    howard

    my code – activated by require_once
    ———————————–

    <?php
    function my_log($msg){
        $date=date_create("now");
        $fdate = date_format($date,"Y/m/d H:i:s");
        $abs_path =  'C:\a_wp_dev\htdocs\scr\my_log.log';
        //$log = fopen ("./my_log.log" ,'a');
        $log = fopen ($abs_path,'a');
        $written = fwrite($log, PHP_EOL . $fdate . ': ' . $msg. PHP_EOL);
        $ok = fclose($log);
    }
    my_log('started');
    
    function my_save_post_action( $post_object ) {
        // modify post object here
        my_log('my_save_post_action' . var_export($post_object));
    }
    add_action( 'save_post', 'my_save_post_action' );
    
    function my_shutdown( ) {
        // modify post object here
        my_log('my_shutdown');
    }
    add_action( 'shutdown', 'my_shutdown' );

    ———————
    from the log, after adding a page

    2020/06/16 15:28:20: started

    2020/06/16 15:28:20: my_shutdown

    • This topic was modified 4 years, 5 months ago by Jan Dembowski. Reason: Formatting
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    The logged entries are from when the code page is loaded due to require_once(). Your my_save_post_action() is called only when a post is saved, not when the code page is loaded. Where is this require_once() call? It might not even be used when posts are saved. There’s not enough context to properly evaluate what is happening.

    Thread Starter tcr howard

    (@howardpa)

    Hi bcworkz,

    Thanks for your prompt response and comments and questions.

    In my posting, I accidentally omitted the relevant entries from my_log.log .

    They were

    2020/06/16 15:59:00: started

    2020/06/16 15:59:00: my_shutdown

    Which shows that the functionality of my code was active.

    To your other points. The ‘require_once’ was appended to the top level index.php file.

    And, I exercised adding a page via the dashboard UI. And indeed, that page showed up in the menu thereafter.

    Any more suggestions would be welcome.
    howard

    Thread Starter tcr howard

    (@howardpa)

    Got it working now, but still not sure what the problem was. All praise for stepping thru code with Eclipse.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘add_action(‘save_post’ .. not firing’ is closed to new replies.