';
}
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 = intval( $_GET['post_id'] );
if ( array_key_exists( 'edit_post_id', $_GET) ) $post_id = intval( $_GET['edit_post_id'] );
if ( array_key_exists( $meta_key, $_GET ) && $post_id == $object_id ) {
return sanitize_text_field( $_GET[$meta_key] );
}
return $value;
}, 10, 4 );
/**
* Change post content to prevent shortcodes
* beeing rendered before the builder content.
*
* @param WP_Post[] $posts
* @param WP_Query $query
* @return WP_Post[]
*/
add_action( 'the_posts', function ( $posts, $query ) {
// Do nothing if another post is beeing edited or is not the main query.
if ( array_key_exists( 'edit_post_id', $_GET ) || ! $query->is_main_query() ) {
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 = '