PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.0.1
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.0.1
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
templately / includes / Core / Platform / Gutenberg.php

Gutenberg.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.0.1, at includes/Core/Platform/Gutenberg.php

152 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Templately\Core\Platform;
3
4 use Templately\API\Import;
5 use Templately\Core\Platform;
6 use Templately\Core\Module;
7 use Templately\Utils\Helper;
8
9 use WP_Error;
10 use function get_permalink;
11 use function get_edit_post_link;
12 use function wp_insert_post;
13 use function wp_slash;
14 use function wp_unslash;
15 use function json_decode;
16
17 class Gutenberg extends Platform {
18 /**
19 * Platform ID
20 * @var string
21 */
22 private $id = 'gutenberg';
23
24 /**
25 * Is gutenberg is active or not
26 * @var boolean
27 */
28 public $is_gutenberg_active = false;
29
30 /**
31 * Initializing the platform and add it to module.
32 */
33 public function __construct(){
34 Module::get_instance()->add( (object) [
35 'id' => $this->id,
36 'object' => $this
37 ]);
38
39 $this->hooks();
40 }
41
42 /**
43 * Initializing Hooks
44 * @return void
45 */
46 public function hooks(){
47 add_action( 'enqueue_block_editor_assets', [ $this, 'scripts' ] );
48 add_action( 'admin_footer', [ $this, 'print_admin_js_template' ] );
49 }
50
51 /**
52 * Assets Enqueueing
53 * @return void
54 */
55 public function scripts(){
56 $this->is_gutenberg_active = true;
57 templately()->assets->enqueue( 'templately-gutenberg', 'css/gutenberg.css' );
58 templately()->assets->enqueue( 'templately-gutenberg', 'js/gutenberg.js' );
59 templately()->admin->scripts( 'gutenberg' );
60 }
61
62 /**
63 * Templately Button and Wrapper for Gutenberg
64 *
65 * @since 2.0.0
66 *
67 * @return void
68 */
69 public function print_admin_js_template() {
70 if ( ! $this->is_gutenberg_active ) {
71 return;
72 }
73 $post_type = apply_filters( 'templately_cloud_push_post_type', get_post_type());
74
75 ?>
76 <div id="templately-gutenberg"></div>
77 <script id="templately-gutenberg-button-switch-mode" type="text/html">
78 <div id="templately-gutenberg-buttons">
79 <button id="templately-gutenberg-button" type="button" class="button button-primary button-large gutenberg-add-templately-button">
80 <i class="templately-icon" aria-hidden="true"></i>
81 <?php echo esc_html__( 'Templately', 'templately' ); ?>
82 </button>
83 <button id="templately-cloud-push" type="button" class="button button-primary button-large">
84 <i class="templately-cloud-icon" aria-hidden="true"></i>
85 <?php echo sprintf( __( 'Save %s in Templately', 'templately' ), $post_type ); ?>
86 </button>
87 </div>
88 </script>
89 <?php
90 }
91
92 /**
93 * Determine Active UI Theme
94 * @return string
95 */
96 public function ui_theme(){
97 return 'light';
98 }
99
100 /**
101 * Creating a gutenberg page
102 *
103 * @param integer $id
104 * @param string $title
105 * @param Import $importer
106 *
107 * @since 2.0.0
108 *
109 * @return array|WP_Error array on success, WP_Error on failure.
110 */
111 public function create_page( $id, $title, $importer = null ){
112 $inserted_ID = $importer->get_content( $id, 'gutenberg' );
113
114 if( is_wp_error( $inserted_ID ) ) {
115 return $inserted_ID;
116 }
117
118 if ( ! empty( $inserted_ID['content'] ) ) {
119 $inserted_ID = wp_insert_post( array (
120 'post_status' => 'draft',
121 'post_type' => 'page',
122 'post_title' => $title,
123 'post_content' => wp_slash($inserted_ID['content']),
124 ) );
125 }
126
127 if ( is_wp_error( $inserted_ID ) ) {
128 return Helper::error(
129 'import_failed',
130 $inserted_ID->get_error_message(),
131 'import/page',
132 $inserted_ID->get_error_code()
133 );
134 }
135
136 return [
137 'post_id' => $inserted_ID,
138 'edit_link' => get_edit_post_link( $inserted_ID, 'internal' ),
139 'visit' => get_permalink( $inserted_ID )
140 ];
141 }
142
143 /**
144 * Inserting Template in Gutenberg Editor
145 *
146 * @param mixed $data
147 * @return array
148 */
149 public function insert( $data ){
150 return $data;
151 }
152 }