Skip to content

Instantly share code, notes, and snippets.

@badabingbreda
Last active April 16, 2018 16:32
Show Gist options
  • Save badabingbreda/983059311e4eb9fc86464f4c941d45d7 to your computer and use it in GitHub Desktop.
Save badabingbreda/983059311e4eb9fc86464f4c941d45d7 to your computer and use it in GitHub Desktop.
Oxygenbuilder 2.0 getting my own shortcode data
<?php
// ATTENTION:
// first you will need to add 2 lines of code (only lines 9+10, the } else if () { ) to the current oxygen-dynamic-shortcode.php file in Oxygenbuilder 2.0-Alpha2/3
// it is located within the oxygen_vsb_dynamic_shortcode class-function
//
// if (method_exists($this, $handler)) {
// $output = call_user_func(array($this, $handler), $atts);
// } else if (class_exists('Dynamic_Shortcodes_' . $atts['data']) && in_array( 'Oxygen_VSB_Dynamic_Shortcodes', class_parents('Dynamic_Shortcodes_' . $atts['data']) ) ){
// $output = call_user_func( array( 'Dynamic_Shortcodes_' . $atts['data'] , 'output' ) , $atts );
// } else {
// return "No such function ".$handler;
// }
add_action( 'plugins_loaded' , 'load_extra_dynamic_datatypes' , 10 ,1 );
function load_extra_dynamic_datatypes() {
/**
* Add a reusable data-type to Oxygenbuilder (needs code hack, too)
*
* takes any arguments but needs at least these 2:
*
* view_id postid for the template or re-usable
* frompost postid for another post if you want to use that data
*
* [oxygen data='reusable' view_id='7' frompost='36']
* ^^ insert this as a shortcode-component, use template with id #7 and use postid #36 as data for any data-field.
*
* Reuseables with
*/
//[ct_reusable ct_options='{"view_id":9}'][/ct_reusable]
class Dynamic_Shortcodes_reusable extends Oxygen_VSB_Dynamic_Shortcodes {
public static function output( $atts ) {
global $post;
// Do we want to use another posts data (hint: use templates inside templates)?
if (isset($atts['frompost'])):
// reset post to other post-id
$post = get_post( $atts['frompost'], OBJECT );
setup_postdata( $post );
endif;
// only display if we want that or not in builder
if ( $atts['render'] == 'true' || strpos($_SERVER['HTTP_REFERER'], 'oxygen_iframe')==0) {
// output the shortcode
$output = do_shortcode('[ct_reusable ct_options=\''. json_encode( $atts ) . '\'][/ct_reusable]');
// process 'hack'-shortcodes
$output = str_replace( array('/%', '%/'), array('[', ']'), $output );
// output with hacks
$output = do_shortcode( $output );
} else {
// some temp output
$output = '<div style="background-color:#f1f1f1;width:100%;height:auto;padding:10px;">REUSABLE PART</div>';
}
if ( isset($atts['frompost'])):
// reset the post id to what it should be
wp_reset_postdata();
endif;
return $output;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment