Hello together,
we are currently setting up a custom theme that uses the page builder.
Our theme has some metaboxes for pages/posts in the sidebar area with settings for the page/post.
After long debugging I came to the conclusion that the “add_meta_boxes” action in our theme somehow affects/overrides the action from the Page Builder. If I delete the action from the theme everything works fine.
The problem is that the Page Builder always reverts to WP-Editor mode after saving the post.
I cannot say why the breaking point seems to be there. The metabox from the Page Builder seems to be added normally, just the callback function gets overridden/not called.
Does anyone know where this could come from? The call to the theme meta boxes is in a class and the callback is added as follows:
//add meta box action public function __construct() { add_action( 'add_meta_boxes', array($this, 'defaultMetaBoxes') ); } public function defaultMetaBoxes() { add_meta_box( 'drowtheme_breadcrumb', __( 'Options', 'drowtheme' ), array($this, 'metaboxCallback'), array('post', 'page'), 'side', 'high' ); }
Normally, since we initialize the hook within the class context, there should be no problem.
Sadly I am stuck with this and cannot find a solution so I would be very happy if someone could help.
EDIT:
We have found the solution. The problem was that in our metabox callback we had a WP_Query.
The problem was that the WP_Query had overridden the globaled $post object.
To avoid further problems with this I would recommend to the plugin authors to delete the globaled $post from the following function:
function siteorigin_panels_get_current_admin_panels_data( ){ $screen = get_current_screen(); // Localize the panels with the panels data if($screen->base == 'appearance_page_so_panels_home_page'){ $home_page_id = get_option( 'page_on_front' ); if( empty($home_page_id) ) $home_page_id = get_option( 'siteorigin_panels_home_page_id' ); $panels_data = !empty($home_page_id) ? get_post_meta( $home_page_id, 'panels_data', true ) : null; if( is_null( $panels_data ) ){ // Load the default layout $layouts = apply_filters( 'siteorigin_panels_prebuilt_layouts', array() ); $home_name = siteorigin_panels_setting('home-page-default') ? siteorigin_panels_setting('home-page-default') : 'home'; $panels_data = !empty($layouts[$home_name]) ? $layouts[$home_name] : current($layouts); } elseif( empty( $panels_data ) ) { // The current page_on_front isn't using page builder return false; } $panels_data = apply_filters( 'siteorigin_panels_data', $panels_data, 'home'); } else{ global $post; $panels_data = get_post_meta( $post->ID, 'panels_data', true ); $panels_data = apply_filters( 'siteorigin_panels_data', $panels_data, $post->ID ); } if ( empty( $panels_data ) ) $panels_data = array(); return $panels_data; }
Instead you can use the post parameter that is already passed to the metabox callback like here (Example from the WP Doc):
/** * This function adds a meta box with a callback function of my_metabox_callback() */ function add_wpdocs_meta_box() { $var1 = 'this'; $var2 = 'that'; add_meta_box( 'metabox_id', __( 'Metabox Title', 'textdomain' ), 'wpdocs_metabox_callback', 'page', 'normal', 'low', array( 'foo' => $var1, 'bar' => $var2 ) ); } /** * Get post meta in a callback * * @param WP_Post $post The current post. * @param array $metabox With metabox id, title, callback, and args elements. */ function wpdocs_metabox_callback( $post, $metabox ) { // Output last time the post was modified. echo 'Last Modified: ' . $post->post_modified; // Output 'this'. echo $metabox['args']['foo']; // Output 'that'. echo $metabox['args']['bar']; // Output value of custom field. echo get_post_meta( $post->ID, 'wpdocs_custom_field', true ); }
Kind regards
Patrick