Suggestion : Action before/after encoded string in wrap_function_call()
Support › MB Builder › Suggestion : Action before/after encoded string in wrap_function_call()
- This topic has 3 replies, 2 voices, and was last updated 2 years, 11 months ago by
Kevin.
-
AuthorPosts
-
May 15, 2022 at 8:45 PM #36030
Kevin
ParticipantHi everyone @metabox.io,
Hope you all get well !Just a suggestion, it would be great to add an action/filter before and after the template that output generated php code from the builder, for example to pass som custom functions used in code, or comment, or whatever can extend the generated php code, like so :
private function wrap_function_call() { $before = apply_filters('rwmb_before_encoded_string', ''); $after = apply_filters('rwmb_after_encoded_string', ''); $this->encoded_string = sprintf( '<?php add_filter( \'rwmb_meta_boxes\', \'%1$s\' ); function %1$s( $meta_boxes ) { $prefix = \'%3$s\'; %4$s $meta_boxes[] = %2$s; %5$s return $meta_boxes; }', $this->function_name, $this->encoded_string, $this->prefix, $before, $after ); return $this; } }
so we could call something like :
add_filter('rwmb_before_encoded_string', function($string){ return '$test = \'my lazy test\'; $mycallback = lazy_callback_function();'; });
for more improvements and automation.
i really would love it !have a nice day
KevinMay 16, 2022 at 2:35 PM #36037Long Nguyen
ModeratorHi Kevin,
Thanks for your suggestion.
I will inform the development team to consider supporting those actions in future updates.
May 16, 2022 at 3:18 PM #36041Kevin
ParticipantHi Long, thanks for sharing,
suggestions for both filter name :
rwmb_mbb_before_php_output
rwmb_mbb_after_php_outputHope you're fine,
have a nice day
KevinMay 17, 2022 at 12:41 AM #36045Kevin
ParticipantSorry,
have another idea, on the same files here's the final code :
file : wp-content/plugins/meta-box-aio/vendor/meta-box/mbb-parser/src/Encoders/MetaBox.phpprivate function wrap_function_call() { $before = apply_filters('rwmb_mbb_before_php_output', ''); $after = apply_filters('rwmb_mbb_after_php_output', ''); $this->encoded_string = sprintf( '<?php add_filter( \'rwmb_meta_boxes\', \'%1$s\' ); function %1$s( $meta_boxes ) { $prefix = \'%3$s\'; %4$s $this_id = \'%6$s\'; $meta_boxes[$this_id] = %2$s; %5$s return $meta_boxes; }', $this->function_name, $this->encoded_string, $this->prefix, $before, $after, $this->settings['id'] ); return $this; }
basically, you could extend the php output for get some variables first (before) and modify the $meta_boxes array by calling it with the $this_id index to some more depending on conditions or whatever you like to. very powerful !
Just a suggestions, as i said, but would be an awesome features for developers.
Have a nice day, and thanks again,
Kevin -
AuthorPosts
- You must be logged in to reply to this topic.