Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow classes that extend Timber\Post to run code on object instantiation #2792

Closed
herrschuessler opened this issue Aug 28, 2023 · 2 comments
Labels

Comments

@herrschuessler
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Since #2088, post classes that extend Timber\Post cannot overwrite the constructor, thus making it impossible to run additional code when a new class object is created.

Describe the solution you’d like

I'd like to be able to overwrite a class method that runs on instantiation, so that I can add own init code.

Describe alternatives you’ve considered

Not sure if there's already a way to do this.

Additional context

@nlemoine
Copy link
Member

How about overriding build method? This is where you can put you place your custom code.

@herrschuessler
Copy link
Contributor Author

Thanks, that worked, I used the following method in my child class:

public static function build( WP_Post $wp_post ): self {
  $post = parent::build( $wp_post );
  
  // Do stuff with $post...
  
  return $post;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants