1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
<?php
namespace TotalPoll\Admin\Ajax; ! defined( 'ABSPATH' ) && exit();
use TotalPoll\Contracts\Modules\Repository; use TotalPollVendors\TotalCore\Contracts\Http\Request;
/** * Class Templates * @package TotalPoll\Admin\Ajax * @since 1.0.0 */ class Templates { /** * @var array $template */ protected $template; /** * @var Request $request */ protected $request; /** * @var Repository $request */ protected $repository; /** * @var array */ protected $templates = [];
/** * Templates constructor. * * @param Request $request * @param Repository $repository */ public function __construct( Request $request, Repository $repository ) { $this->request = $request; $this->repository = $repository;
$this->template = (string) $this->request->request( 'template' ); $this->templates = $this->repository->getActiveWhere( [ 'type' => 'template' ] );
if ( empty( $this->template ) || ! isset( $this->templates[ $this->template ] ) ): wp_send_json_error( new \WP_Error( 'unknown_template', 'Unknown template.' ) ); endif; }
/** * Get template defaults * @action-callback wp_ajax_totalpoll_templates_get_defaults */ public function getDefaults() { wp_send_json( $this->repository->getDefaults( $this->template ) ); }
/** * Get template settings * @action-callback wp_ajax_totalpoll_templates_get_settings */ public function getSettings() { echo $this->repository->getSettings( $this->template ); wp_die(); }
/** * Get template preview * @action-callback wp_ajax_totalpoll_templates_get_preview */ public function getPreview() { echo $this->repository->getPreview( $this->template ); wp_die(); } }
|