Suggestion : Action before/after encoded string in wrap_function_call()

Support MB Builder Suggestion : Action before/after encoded string in wrap_function_call()

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #36030
    KevinKevin
    Participant

    Hi 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
    Kevin

    #36037
    Long NguyenLong Nguyen
    Moderator

    Hi Kevin,

    Thanks for your suggestion.

    I will inform the development team to consider supporting those actions in future updates.

    #36041
    KevinKevin
    Participant

    Hi Long, thanks for sharing,

    suggestions for both filter name :
    rwmb_mbb_before_php_output
    rwmb_mbb_after_php_output

    Hope you're fine,
    have a nice day
    Kevin

    #36045
    KevinKevin
    Participant

    Sorry,
    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.php

        private 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

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