• Resolved zulok

    (@zulok)


    Hello

    I built a plugin to handle custom post types. Within that plugin meta data should be modified if some requirements are met after modification of the post. When I hook to ‘save_post’ within the plugin it never gets fired, however if I simply move the add_action sentence to the child theme functions.php the hook is fired correctly.

    Here is the code:

    <?php
    /*
    Plugin Name: MDV CPT Plugin
    Author: MDV
    Version: 1.1
    */

    defined( ‘ABSPATH’ ) or die( ‘This is a WordPress Plugin – No direct access permitted!’ );

    add_action(‘save_post’, ‘validar_promocio_ini’,10,3);
    add_action(‘edit_post’, ‘validar_promocio_ini’,10,3);

    function validar_promocio_ini( $post_id , $post)
    {

    // Don’t run the echo if this is an auto save
    if (defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE )
    return;

    // If this is a revision, get real post ID
    if ($parent_id = wp_is_post_revision( $post_id ) )
    $post_id = $parent_id;

    // Run only for events that go publish or future
    $poststatus= get_post_status($post_id);
    if ($poststatus !=’publish’ && $poststatus != ‘future’ )
    return;

    /* Based on some logic, update meta data */

    return;
    }

    Could the problem depend on the load order of plugins vs functions.php?

    Thanks

    Zulok

  • The topic ‘'save_post' hook not firing within a plugin’ is closed to new replies.