editor->isEditMode()) { return null; } if (Plugin::$instance->editor->isEditMode()) { $post_id = Plugin::$instance->editor->getPostId(); $document = Plugin::$instance->documents->getDocOrAutoSave($post_id); } else { $post_id = get_the_ID(); $document = Plugin::$instance->documents->getDocForFrontend($post_id); } if (!$document) { return null; } $model = $this->getModel($document->getPost()->ID); if ($document->isAutosave()) { $model->setSettings('post_status', $document->getMainPost()->post_status); } return $model; } /** * Ajax before saving settings. * * Validate the data before saving it and updating the data in the database. * * @since 1.6.0 * * @param array $data Post data * @param int $id Post ID * * @throws \Exception if invalid post returned using the `$id` * @throws \Exception if current user don't have permissions to edit the post */ public function ajaxBeforeSaveSettings(array $data, $id) { $post = get_post($id); if (empty($post)) { throw new \Exception('Invalid post.', Exceptions::NOT_FOUND); } if (!current_user_can('edit', $id)) { throw new \Exception('Access denied.', Exceptions::FORBIDDEN); } // Avoid save empty post title. if (!empty($data['post_title'])) { $post->post_title = $data['post_title']; } // if (isset($data['post_excerpt']) && post_type_supports($post->post_type, 'excerpt')) { // $post->post_excerpt = $data['post_excerpt']; // } if (isset($data['post_status'])) { // $this->savePostStatus($id, $data['post_status']); // unset($post->post_status); $post->post_status = $data['post_status']; } wp_update_post($post); // Check updated status // if (DB::STATUS_PUBLISH === get_post_status($id)) $autosave = wp_get_post_autosave($post->ID); if ($autosave) { wp_delete_post_revision($autosave->ID); } if (isset($data['post_featured_image'])) { if (empty($data['post_featured_image']['url'])) { delete_post_meta($post->ID, '_og_image'); } else { update_post_meta($post->ID, '_og_image', $data['post_featured_image']['url']); } } if (Utils::isCptCustomTemplatesSupported($post)) { $template = get_post_meta($post->ID, '_wp_page_template', true); if (isset($data['template'])) { $template = $data['template']; } if (empty($template)) { $template = 'default'; } update_post_meta($post->ID, '_wp_page_template', $template); } } /** * {@inheritDoc} * * Override parent because the page setting moved to document.settings. */ protected function printEditorTemplateContent($name) { ?> <# const tabs = elementor.config.document.settings.tabs; if ( Object.values( tabs ).length > 1 ) { #>
<# _.each( tabs, function( tabTitle, tabSlug ) { #>
{{{ tabTitle }}}
<# } ); #>
<# } #>
getPostId(); if ($css_file instanceof PostPreview) { $autosave = Utils::getPostAutosave($post_id); if ($autosave) { $post_id = $autosave->ID; } } return $this->getModel($post_id); } /** * Get special settings names. * * Retrieve the names of the special settings that are not saved as regular * settings. Those settings have a separate saving process. * * @since 1.6.0 * * @return array Special settings names */ protected function getSpecialSettingsNames() { return [ 'id', 'post_title', 'post_status', 'template', 'post_excerpt', 'post_featured_image', // Do not save: 'action', '_nonce', 'section_page_settings', 'section_page_style', 'section_custom_css', 'template_default_description', 'template_canvas_description', ]; } // public function savePostStatus($post_id, $status) }