add( (object) [ 'id' => $this->id, 'object' => $this ]); $this->hooks(); } /** * Initializing Hooks * @return void */ public function hooks(){ add_action( 'enqueue_block_editor_assets', [ $this, 'scripts' ] ); add_action( 'admin_footer', [ $this, 'print_admin_js_template' ] ); } /** * Assets Enqueueing * @return void */ public function scripts(){ $this->is_gutenberg_active = true; templately()->assets->enqueue( 'templately-gutenberg', 'css/gutenberg.css' ); templately()->assets->enqueue( 'templately-gutenberg', 'js/gutenberg.js' ); templately()->admin->scripts( 'gutenberg' ); } /** * Templately Button and Wrapper for Gutenberg * * @since 2.0.0 * * @return void */ public function print_admin_js_template() { if ( ! $this->is_gutenberg_active ) { return; } ?>
get_content( $id, 'gutenberg' ); if( is_wp_error( $inserted_ID ) ) { return $inserted_ID; } if ( ! empty( $inserted_ID['content'] ) ) { $inserted_ID = wp_insert_post( array ( 'post_status' => 'draft', 'post_type' => 'page', 'post_title' => $title, 'post_content' => wp_slash($inserted_ID['content']), ) ); } if ( is_wp_error( $inserted_ID ) ) { return Helper::error( 'import_failed', $inserted_ID->get_error_message(), 'import/page', $inserted_ID->get_error_code() ); } return [ 'post_id' => $inserted_ID, 'edit_link' => get_edit_post_link( $inserted_ID, 'internal' ), 'visit' => get_permalink( $inserted_ID ) ]; } /** * Inserting Template in Gutenberg Editor * * @param mixed $data * @return array */ public function insert( $data ){ return $data; } }