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
PageSettingsService.php
52 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kirki\App\Services; |
| 4 | |
| 5 | use Kirki\App\Constants\PageMetaKeys; |
| 6 | use Kirki\App\DTO\Page\PageSettingsDTO; |
| 7 | use Kirki\App\Models\Page as PageModel; |
| 8 | use Kirki\App\Models\PostMeta; |
| 9 | use Kirki\App\Utils\PostUtil; |
| 10 | |
| 11 | defined('ABSPATH') || exit; |
| 12 | |
| 13 | class PageSettingsService |
| 14 | { |
| 15 | public static function create() |
| 16 | { |
| 17 | return new static(); |
| 18 | } |
| 19 | |
| 20 | public function update_page_settings(PageModel $page, PageSettingsDTO $payload) |
| 21 | { |
| 22 | $data = [ |
| 23 | 'post_title' => $payload->page_title, |
| 24 | 'post_name' => $payload->slug, |
| 25 | 'post_excerpt' => $payload->page_description, |
| 26 | ]; |
| 27 | |
| 28 | if (!empty($payload->post_status)) { |
| 29 | $data['post_status'] = $payload->post_status; |
| 30 | } |
| 31 | |
| 32 | $page = PageModel::update_post($page->ID, $data); |
| 33 | |
| 34 | PostMeta::update_meta_value($page->ID, PageMetaKeys::SEO_SETTINGS, $payload->seo_settings); |
| 35 | PostMeta::update_meta_value($page->ID, PageMetaKeys::CUSTOM_CODE, $payload->custom_code); |
| 36 | |
| 37 | $image_id = attachment_url_to_postid($payload->featured_image); |
| 38 | |
| 39 | if ($image_id > 0) { |
| 40 | set_post_thumbnail($page->ID, $image_id); |
| 41 | } else { |
| 42 | delete_post_thumbnail($page->ID); |
| 43 | } |
| 44 | |
| 45 | return $page; |
| 46 | } |
| 47 | |
| 48 | public function update_page_custom_code(?array $custom_code = null) |
| 49 | { |
| 50 | return PostMeta::update_meta_value(PostUtil::get_post_id_from_url(), PageMetaKeys::CUSTOM_CODE, $custom_code); |
| 51 | } |
| 52 | } |