From 8c4b51af851e08682b9cc6e99af55a9a92722ec0 Mon Sep 17 00:00:00 2001 From: girafffee <46720998+girafffee@users.noreply.github.com> Date: Fri, 26 Mar 2021 10:49:18 +0200 Subject: [PATCH] Improved registration of PluginManager & RegisterFormMetaBox --- src/JetEngine/RegisterFormMetaBox.php | 10 ++++++++-- src/JetFormBuilder/PluginManager.php | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/JetEngine/RegisterFormMetaBox.php b/src/JetEngine/RegisterFormMetaBox.php index 405f58e..788f24c 100644 --- a/src/JetEngine/RegisterFormMetaBox.php +++ b/src/JetEngine/RegisterFormMetaBox.php @@ -6,7 +6,13 @@ abstract class RegisterFormMetaBox { - public function __construct() { + public static function register() { + if ( function_exists( 'jet_engine' ) ) { + ( new static() )->_add_hooks(); + } + } + + private function _add_hooks() { add_action( 'jet-engine/forms/editor/meta-boxes', array( $this, 'register_meta_box' ) @@ -51,7 +57,7 @@ public function register_assets() { * @return void */ public function save_meta( $post_id ) { - $data = isset( $_POST[ $this->get_id() ] ) ? json_encode( $_POST[ $this->get_id() ] ) : json_encode( array() ); + $data = isset( $_POST[ $this->get_id() ] ) ? json_encode( $_POST[ $this->get_id() ] ) : '{}'; update_post_meta( $post_id, $this->get_id(), wp_slash( $data ) ); } diff --git a/src/JetFormBuilder/PluginManager.php b/src/JetFormBuilder/PluginManager.php index b365f6c..d0b845d 100644 --- a/src/JetFormBuilder/PluginManager.php +++ b/src/JetFormBuilder/PluginManager.php @@ -12,8 +12,8 @@ abstract class PluginManager { use RegisterMetaManager; use WithJFBInit; - protected function init() { - $this->jfb_maybe_init(); + public static function register() { + ( new static() )->jfb_maybe_init(); } final protected function _on_jbf_init() {