class-wizard-item.php
110 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SuperbAddons\Data\Utils\Wizard; |
| 4 | |
| 5 | use SuperbAddons\Admin\Controllers\Wizard\WizardTemplatePreviewController; |
| 6 | |
| 7 | defined('ABSPATH') || exit(); |
| 8 | |
| 9 | class WizardItem |
| 10 | { |
| 11 | public $id; |
| 12 | private $slug; |
| 13 | public $type; |
| 14 | public $datatype; |
| 15 | public $title; |
| 16 | public $category; |
| 17 | public $permalink; |
| 18 | public $no_reload; |
| 19 | public $is_premium; |
| 20 | public $is_file_template; |
| 21 | public $is_restoration_point; |
| 22 | public $use_custom_page_template_preview; |
| 23 | public $plugin_update_required; |
| 24 | public $external_plugin_required; |
| 25 | public $required_plugin_names; |
| 26 | public $is_missing_navigation_block; |
| 27 | public $categories = array(); |
| 28 | public $tags = array(); |
| 29 | public $industries = array(); |
| 30 | public $description = ''; |
| 31 | public $style = null; |
| 32 | public $package; |
| 33 | |
| 34 | public function __construct($template) |
| 35 | { |
| 36 | $this->id = isset($template->id) ? $template->id : false; |
| 37 | $this->slug = isset($template->slug) ? $template->slug : $this->id; |
| 38 | $this->category = isset($template->category) && is_string($template->category) ? $template->category : $this->slug; |
| 39 | $this->type = isset($template->type) ? $template->type : false; |
| 40 | $this->datatype = isset($template->datatype) ? $template->datatype : $this->type; |
| 41 | if ($this->slug === 'front-page') { |
| 42 | $this->datatype = 'front-page'; |
| 43 | } |
| 44 | // v2 API items use 'name', WP templates use 'title' |
| 45 | $this->title = isset($template->title) ? $template->title : (isset($template->name) ? $template->name : false); |
| 46 | $this->permalink = isset($template->permalink) ? $template->permalink : get_home_url(); |
| 47 | $this->no_reload = isset($template->no_reload) ? $template->no_reload : false; |
| 48 | $this->is_premium = isset($template->is_premium) ? $template->is_premium : false; |
| 49 | $this->plugin_update_required = isset($template->plugin_update_required) && $template->plugin_update_required; |
| 50 | $this->external_plugin_required = isset($template->external_plugin_required) && $template->external_plugin_required; |
| 51 | $this->required_plugin_names = isset($template->required_plugin_names) ? $template->required_plugin_names : array(); |
| 52 | $this->is_file_template = false; |
| 53 | $this->is_restoration_point = false; |
| 54 | $this->is_missing_navigation_block = isset($template->is_missing_navigation_block) ? $template->is_missing_navigation_block : false; |
| 55 | $this->use_custom_page_template_preview = isset($template->use_custom_page_template_preview) ? $template->use_custom_page_template_preview : 0; |
| 56 | if (isset($template->categories) && is_array($template->categories)) { |
| 57 | $this->categories = $template->categories; |
| 58 | } else { |
| 59 | $this->categories = array(); |
| 60 | } |
| 61 | $this->tags = isset($template->tags) && is_array($template->tags) ? $template->tags : array(); |
| 62 | $this->industries = isset($template->industries) && is_array($template->industries) ? $template->industries : array(); |
| 63 | $this->description = isset($template->description) && is_string($template->description) ? $template->description : ''; |
| 64 | $this->style = isset($template->style) ? $template->style : null; |
| 65 | $this->package = isset($template->package) ? $template->package : ($this->is_premium ? 'premium' : 'free'); |
| 66 | } |
| 67 | |
| 68 | public function GetId() |
| 69 | { |
| 70 | if ($this->is_file_template) { |
| 71 | return $this->id . WizardItemIdAffix::FILE_TEMPLATE; |
| 72 | } |
| 73 | if ($this->is_restoration_point) { |
| 74 | return $this->id . WizardItemIdAffix::RESTORATION_POINT; |
| 75 | } |
| 76 | return $this->id; |
| 77 | } |
| 78 | |
| 79 | public function GetSlug() |
| 80 | { |
| 81 | if ($this->is_file_template) { |
| 82 | return $this->slug . WizardItemIdAffix::FILE_TEMPLATE; |
| 83 | } |
| 84 | if ($this->is_restoration_point) { |
| 85 | return $this->GetId(); |
| 86 | } |
| 87 | return $this->slug; |
| 88 | } |
| 89 | |
| 90 | public function GetBaseSlug() |
| 91 | { |
| 92 | return $this->slug; |
| 93 | } |
| 94 | |
| 95 | public function SetSlug($slug) |
| 96 | { |
| 97 | $this->slug = $slug; |
| 98 | } |
| 99 | |
| 100 | public function IsPattern() |
| 101 | { |
| 102 | return $this->type === WizardItemTypes::PATTERN || $this->type === WizardItemTypes::WP_TEMPLATE_PART; |
| 103 | } |
| 104 | |
| 105 | public function GetPreviewURL() |
| 106 | { |
| 107 | return add_query_arg(array(WizardTemplatePreviewController::TEMPLATE_PREVIEW_KEY => $this->GetId(), WizardTemplatePreviewController::TEMPLATE_TYPE_KEY => $this->type, WizardTemplatePreviewController::USE_PAGE_TEMPLATE_KEY => $this->use_custom_page_template_preview, 'superb-preview-time' => time(), WizardTemplatePreviewController::TEMPLATE_PREVIEW_NONCE => wp_create_nonce(WizardTemplatePreviewController::TEMPLATE_PREVIEW_NONCE_ACTION)), $this->permalink); |
| 108 | } |
| 109 | } |
| 110 |