• Resolved Chad Reitsma

    (@chadreitsma)


    Hey guys,

    In version 2.9.0 you added a filter called “publishpressfuture_expiration_actions” which we had previously used to add custom expiration actions (post statuses)

    Example code:

    add_filter('publishpressfuture_expiration_actions',
    'dut_add_custom_expire_actions', 9999, 2);
    function dut_add_custom_expire_actions($actions, $post_type) {$actions['expired'] = "Expired";
    $actions['archived'] = "Archived";
    return $actions;
    }

    It seems like the filter is still active as I can see them show up in the “Actions” list. However, after saving the post, then going back to the posts list – it shows an error that the action cannot be scheduled due to a configuration error.

    I think something changed in Version 3, as this no longer works. Can you please explain how this filter should work?

    Cheers,
    C.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author andergmartins

    (@andergmartins)

    Hi, thank you for using PublishPress Future.

    Sorry, on version 3 we modified the engine that runs the actions, and we didn’t make it clear how to extend it.

    In addition to the filter you are using, you have to use the filter publishpressfuture_expiration_action_factory. It should return an instance of a class that implements the interface PublishPress\Future\Modules\Expirator\Interfaces\ExpirationActionInterface, available at

    https://github.com/publishpress/PublishPress-Future/blob/3.1.3/src/Modules/Expirator/Interfaces/ExpirationActionInterface.php

    You can see an example of a class implementation on the following link. Each custom status, should have its own action class:

    https://github.com/publishpress/PublishPress-Future/blob/b7e84bcc54423562d8d9ceaabbb03501296b49d0/src/Modules/Expirator/ExpirationActions/PostStatusToPrivate.php

    And the callback for the filter could be something like:

    add_filter('publishpressfuture_expiration_action_factory', 'my_action_factory', 10, 3);
    
    /**
     * @param \PublishPress\Future\Modules\Expirator\Interfaces\ExpirationActionInterface $action The action class
     * @param string $actionName
     * @param \PublishPress\Future\Modules\Expirator\Models\ExpirablePostModel $postModel
     * @return \PublishPress\Future\Modules\Expirator\Interfaces\ExpirationActionInterface
    function my_action_factor($action, $actionName, $postModel) {
        switch ($actionName) {
            case 'custom_status_expired':
                return new MyExpiredActionClass();
                break;
            case 'custom_status_archived':
                return new MyArchivedActionClass();
                break;
        }
    }

    When the action is triggered by the plugin, it will execute the method execute of the respective custom class.

    Please, let us know if that works for you.

    Thanks

    Thread Starter Chad Reitsma

    (@chadreitsma)

    Thanks, I’ll try it out and reply back as soon as possible!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Filter: publishpressfuture_expiration_actions not working’ is closed to new replies.