Skip to content

Commit

Permalink
Improved registration of PluginManager & RegisterFormMetaBox
Browse files Browse the repository at this point in the history
  • Loading branch information
girafffee committed Mar 26, 2021
1 parent f27fee8 commit 8c4b51a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/JetEngine/RegisterFormMetaBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' )
Expand Down Expand Up @@ -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 ) );
}
Expand Down
4 changes: 2 additions & 2 deletions src/JetFormBuilder/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 8c4b51a

Please sign in to comment.