Custom tables with revisions enabled - mbct_before_add fires for the revision

Support MB Revision Custom tables with revisions enabled - mbct_before_add fires for the revision

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #44828
    Ben RBen R
    Participant

    I am using custom tables with revisions.

    I am trying to detect when a status has changed, either as the result of modifying a field, or by adding a new record to the table.

    When I update an existing record, I see that both mbct_before_update and mbct_before_add are fired. The reason mbct_before_add fires is because of the new revision that is being written.

    This behavior is not desired, because I cannot distinguish between adding a record and modifying an existing one.

    If you want to keep this hook, you should add a parameter to it that we can use to differentiate between a true add and a revision. But, I'd argue that this is incorrect behavior and should be fixed.

    #44836
    PeterPeter
    Moderator

    Hello Benjamin,

    A revision actually is a new post, post type revision. If you use those hooks, you can compare two variables:
    - $row['ID']: the revision post ID
    - $_POST['ID']: the current post ID
    to "distinguish between adding a record and modifying an existing one".

    #44850
    Ben RBen R
    Participant

    Yes, I understand that a revision creates a new post, but the original id should be added to the hook parameters. (I feel like relying on the POST data is a hack.) I think you should consider not firing that at all under this particular circumstance. Consider the nature of the mbct_before_add hook and why it exists: developers are trying to understand when a new custom table record is being added, not when a revision is created.

    At the very least, please document this circumstance where it gets fired incorrectly when revisions are enabled, because this could have unintended consequences for anyone using it.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.