PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.2.3
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.2.3
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 / API / ThemeBuilderApi.php

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

67 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\API;
4
5 use Templately\Builder\Types\BaseTemplate;
6 use WP_Error;
7 use WP_REST_Request;
8
9 class ThemeBuilderApi extends API {
10 public function permission_check( WP_REST_Request $request ) {
11 if ( $request->get_route() === '/templately/v1/create-template' ) {
12 return wp_verify_nonce( $request->get_param( 'nonce' ), 'templately_nonce' );
13 }
14
15 return parent::permission_check( $request );
16 }
17
18 public function register_routes() {
19 $this->post( 'create-template', [ $this, 'create' ], [
20 'platform' => [
21 'required' => true,
22 'validate_callback' => function ( $param ) {
23 return is_string( $param ) && ( $param == 'elementor' || 'gutenberg' == $param );
24 }
25 ],
26 'type' => [
27 'required' => true,
28 'validate_callback' => function ( $param ) {
29 return is_string( $param ) && array_key_exists( $param, templately()->theme_builder::$templates_manager->get_template_types() );
30 }
31 ],
32 'title' => [
33 'required' => true,
34 ]
35 ] );
36 }
37
38 public function create( WP_REST_Request $request ) {
39 $platform = $request->get_param( 'platform' );
40 $template_type = $request->get_param( 'type' );
41 $title = $request->get_param( 'title' );
42
43 if ( empty( $title ) ) {
44 $title = '';
45 }
46
47 $post_data = [
48 'post_title' => $title,
49 'post_status' => 'publish',
50 'post_type' => 'templately_library'
51 ];
52
53 /**
54 * @var BaseTemplate $template
55 */
56 $template = templately()->theme_builder::$templates_manager->create( $template_type, $post_data, [ 'platform' => $platform ] );
57
58 if ( is_wp_error( $template ) ) {
59 /**
60 * @var WP_Error $template ;
61 */
62 return $this->error( 'failed_template_creation', sprintf( __( 'Something went wrong. %s', 'templately' ), $template->get_error_message() ) );
63 }
64
65 return $this->success( $template->get_edit_url() );
66 }
67 }