Skip to content

Add hooks to modify ArrayTransformer, TextTransformer and set transform Constraints#30

Open
perrelet wants to merge 7 commits intomarcbelletre:masterfrom
perrelet:master
Open

Add hooks to modify ArrayTransformer, TextTransformer and set transform Constraints#30
perrelet wants to merge 7 commits intomarcbelletre:masterfrom
perrelet:master

Conversation

@perrelet
Copy link

It would be helpful if we could modify the Recurr\Transformer\ArrayTransformer and Recurr\Transformer\TextTransformer objects. Further, ArrayTransformer::transform also accepts an optional second argument to set a constraint by passing one of:

Recurr\Transformer\Constraint\AfterConstraint
Recurr\Transformer\Constraint\BeforeConstraint
Recurr\Transformer\Constraint\BetweenConstraint

We propose adding the following filters to expose these features:

apply_filters('ACF/RRule/ArrayTransformer', $transformer);
apply_filters('ACF/RRule/TextTransformer', $textTransformer);
$constraint = apply_filters('ACF/RRule/Constraint', null);

We need to add an additional check when setting $new_value['end_date'] because a constraint may cause the $new_value['dates_collection'] array to be empty. In such instances, $end_date = end($new_value['dates_collection']) returns false and therefore isset($end_date) = true. By checking that $end_date is indeed an instance of DateTime (and not false) we ensure that $end_date->format('Ymd') doesn't throw a fatal error.

@marcbelletre
Copy link
Owner

Hi @perrelet,

Thank you for this PR!
Could you please provide an example of how you would use these filters?

Also I would suggest changing the names of the filters for two reasons:

  • I don't own the ACF namespace
  • Wordpress never uses uppercase characters in its function/filter naming

I would be happy to merge this PR then ;)

@perrelet
Copy link
Author

Hi @marcbelletre

I have changed the hook signatures to lowercase and used the acf_rrule namespace: d51ef48

Here's a couple of examples of how these can be used:

1. Limit the number of instances generated for a recurring event with no end date

add_filter('acf_rrule/recurr/array_transformer', function (Recurr\Transformer\ArrayTransformer $transformer) {
   
    $config = new Recurr\Transformer\ArrayTransformerConfig();
    $config->setVirtualLimit(200);

    $transformer->setConfig($config);

});

2. Only generate instances between a date range

add_filter('acf_rrule/recurr/constraint', function ($constraint) {
   
    $from = new DateTime();
    $to = (new DateTime())->modify('+1 month');

    return new Recurr\Transformer\Constraint\BetweenConstraint($from, $to, true);

});

Let me know if you need any more information or changes 👍

@perrelet
Copy link
Author

perrelet commented Oct 7, 2025

Hi @marcbelletre,

This PR remains of immense benefit to our implementations of acf-rrule.

Would you be able to review this?

Many thanks 🙏

@marcbelletre
Copy link
Owner

marcbelletre commented Nov 15, 2025

Hello there!

I'm really sorry I abandoned this project and I appreciate your patience! I stopped working as a freelancer last year and got a new position where I don't use Wordpress at all. I don't use this plugin anymore and I honestly don't have time to continue maintaining it.

I would be happy to transfer the ownership of the repository to you or anyone who would like to take over the project maintenance, as well as the WordPress SVN access, so you guys can continue using it :)

Don't hesitate to send me an email if you'd like to get in touch.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants