';
}
return $content;
}, 10, 3 );
/**
* Override meta data with custom values from the url.
* This makes it possible to change page tempalte etc. in the builder.
*
* @param string $value
* @param number $object_id
* @param string $meta_key
* @param boolean $single
*/
add_filter( 'get_post_metadata', function ( $value, $object_id, $meta_key, $single ) {
$post_id = null;
if ( array_key_exists( 'post_id', $_GET) ) $post_id = $_GET['post_id'];
if ( array_key_exists( 'edit_post_id', $_GET) ) $post_id = $_GET['edit_post_id'];
if ( array_key_exists( $meta_key, $_GET ) && $post_id == $object_id ) {
return $_GET[$meta_key];
}
return $value;
}, 10, 4 );
/**
* Change post content to prevent shortcodes
* beeing rendered before the builder content.
*
* @param array $posts
* @return array
*/
add_action( 'the_posts', function ( $posts ) {
static $is_replaced;
// Do nothing if another post is beeing edited or is replaced already.
if ( array_key_exists( 'edit_post_id', $_GET ) || $is_replaced ) return $posts;
// do nothing if «the_post» action has already been called.
// if ( did_action('the_post') ) return $posts;
// Get current post if no posts are found. Happens when editing a draft.
if ( empty ( $posts ) && ( array_key_exists( 'page_id', $_GET ) || array_key_exists( 'p', $_GET ) ) ) {
$posts[] = get_post( isset( $_GET['page_id'] ) ? $_GET['page_id'] : $_GET['p'] );
}
// Check if this post is beeing edited in builder.
if ( count( $posts ) == 1 && $posts[0]->ID == $_GET['post_id'] ) {
// Change post content to an Angular component.
$posts[0]->post_content = '