AppsService.php
3 days ago
CollaborationCommentService.php
3 weeks ago
CollaborationService.php
3 weeks ago
CollectionItemService.php
3 weeks ago
CollectionService.php
3 weeks ago
EditorService.php
3 weeks ago
FontService.php
3 days ago
GlobalDataService.php
3 days ago
MediaService.php
3 weeks ago
PageService.php
3 days ago
PageSettingsService.php
3 weeks ago
UtilityPageService.php
3 days ago
EditorService.php
46 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kirki\App\Services; |
| 4 | |
| 5 | use Kirki\App\Constants\PageMetaKeys; |
| 6 | use Kirki\App\Constants\PostStatus; |
| 7 | use Kirki\App\Models\Page as PageModel; |
| 8 | use Kirki\App\Models\PostMeta; |
| 9 | use Kirki\App\Supports\Canvas; |
| 10 | |
| 11 | defined('ABSPATH') || exit; |
| 12 | |
| 13 | class EditorService |
| 14 | { |
| 15 | public function back_to_kirki_editor(PageModel $page, ?string $new_title = null) |
| 16 | { |
| 17 | if ($page->post_status === PostStatus::AUTO_DRAFT) { |
| 18 | if (empty($new_title)) { |
| 19 | $new_title = 'Untitled'; |
| 20 | } |
| 21 | |
| 22 | $data = [ |
| 23 | 'ID' => $page->ID, |
| 24 | 'post_title' => $new_title, |
| 25 | 'post_name' => $new_title, |
| 26 | 'post_status' => PostStatus::DRAFT, |
| 27 | ]; |
| 28 | |
| 29 | $page = PageModel::update_post($page->ID, $data); |
| 30 | } |
| 31 | |
| 32 | PostMeta::update_meta_value($page->ID, PageMetaKeys::PAGE_TEMPLATE, Canvas::get_full_canvas_template_path()); |
| 33 | |
| 34 | return $page; |
| 35 | } |
| 36 | |
| 37 | public function back_to_wordpress_editor(PageModel $page) |
| 38 | { |
| 39 | $is_deleted = PostMeta::query() |
| 40 | ->where('post_id', $page->ID) |
| 41 | ->where('meta_key', PageMetaKeys::EDITOR_MODE) |
| 42 | ->delete(); |
| 43 | |
| 44 | return !empty($is_deleted); |
| 45 | } |
| 46 | } |