This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Adding Builder Element in Plugin

  • Creator
    Topic
  • #22077
    John
    Participant

    I’m trying to add a builder element from a plugin like so:

    function jma_flip_code($atts, $content = null){ 
    	extract( shortcode_atts( array(
    		'back' => '',
    		'class' => ''
    		), $atts ) ); 
    	$x = '<div class="' . $class . ' jma-hover jma-flip-panel">';
    	$x .= '<div class="side front">';
    	$x .= '<div class="inner">';
    	$x .= do_shortcode($content); 
    	$x .= '</div><!--inner-->';
    	$x .= '</div><!--front-->';
    	$x .= '<div class="side back">';	
    	$x .= '<div class="inner">';
    	$x .= do_shortcode($back);
    	$x .= '</div><!--inner-->';
    	$x .= '</div><!--back-->';
    	$x .= '</div><!--jma-flip-panel-->';
    	return $x;
    }
    add_shortcode('jma_flip_shortcode','jma_flip_code');
    
    function jma_add_flip_panel(){
    	if ( ! defined('TB_FRAMEWORK_VERSION')  ) {
    		return;
    	}
    	$options = array(
    	    array(
    	        'name'      => 'Class',
    	        'desc'      => 'An optional class for the wrapping div.',
    	        'id'        => 'class',
    	        'type'      => 'text'
    	    ),
    	    array(
    	        'name'      => 'Front',
    	        'desc'      => 'Content for the front of the panel.',
    	        'id'        => 'front',
    	        'type'      => 'editor'
    	    ),
    	    array(
    	        'name'      => 'Back',
    	        'desc'      => 'Content for the back of the panel.',
    	        'id'        => 'back',
    	        'type'      => 'editor'
    	    )
    	);
    	themeblvd_add_builder_element( 'flip_panel', 'Flip Panel', 'none', $options, 'display_flip_panel' );
    }
    add_action('after_setup_theme', 'jma_add_flip_panel');
    
    function display_flip_panel( $id, $options, $location = '') {
        $atts['class'] = $options['class'];
        $atts['back'] = $options['back'];
    	echo jma_flip_code($atts, $option['front']);
    }

    The element displays in the page editor as expected, but when I update the page it doesn’t hold the value (editors in my ‘flip panel’ go blank). I think I need to be on ‘after_theme_setup’, but maybe there is a better hook. If I don’t set a default value for $location I get a warning when the page is displayed.
    thx,
    John

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #22078
    John
    Participant

    Found a solution:

    array(
    	        'name'      => 'Back',
    	        'desc'      => 'Content for the back of the panel.',
    	        'id'        => 'back',
    	        'type'      => 'textarea',
    		'editor'	=> true,
    	    )

    thanks,
    john

    #22079
    John
    Participant

    One last question. When using this editor to add an image the width attribute gets set to 600 and the height is then calculated from that. Any way to eliminate this and get the image at its intended size?

    #22080
    John
    Participant

    strangly, if I add this pluggable function:

    function themeblvd_admin_content_width() {
    	global $content_width;
    	$content_width = 10000;
    }

    the issue is resolved.
    my question becomes what unintended consequences will this have. Is there a condition I could add? i.e.

    function themeblvd_admin_content_width() {
    	global $content_width;
    	if(/*jma flip panels is running*/)
    		$content_width = 10000;
    	else
    		$content_width = 600;
    }
    • This reply was modified 7 years, 11 months ago by John.
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.