post_type !== $this->PT) return; // Nonce is not valid if (!$this->nonce_check()) return; // The nonce proves request origin, but does not authorize this post edit. if (!current_user_can('edit_post', $post_id)) return; // We don't need to do anything on post auto save if (defined('DOING_AUTOSAVE') and DOING_AUTOSAVE) return; // Entity $entity = $this->entity($post_id); // Prepare only the expected editor payload. Keep safe HTML available // for rich fields; store handlers apply field-specific validation. $data = []; if ($this->request_key && isset($_POST[$this->request_key]) && is_array($_POST[$this->request_key])) { $data = Input::sanitize(wp_unslash($_POST[$this->request_key])); } // Data $data = apply_filters('DayTidy/F__DayTidy/Post__save/data', $data, $entity, $this); // Before Save do_action('DayTidy/A__DayTidy/Post__save/before_save', $entity, $data, $this); // Store Data $this->store($entity, $data); // After Save do_action('DayTidy/A__DayTidy/Post__save/after_save', $entity, $data, $this); } /** * {@inheritDoc} * @throws Exception */ abstract public function store(Post $entity, array $data): void; /** * Status Updated * * @param string $new_status * @param string $old_status * @param WP_Post $post * @return void */ public function status(string $new_status, string $old_status, $post): void { if ($post->post_type === $this->PT && $new_status !== $old_status) { do_action('DayTidy/A__DayTidy/Post__status/changed/' . $this->PT, $post->ID, $new_status, $old_status); } } /** * Post Type Labels * * @param string $singular * @param string $plural * @return array */ public function labels(string $singular, string $plural): array { $singular_readable = Str::humanify($singular); $plural_readable = Str::humanify($plural); $plural_lower = Str::lowercase($plural); return [ 'name' => $plural_readable, 'singular_name' => $singular_readable, // translators: Placeholder values. 'add_new' => sprintf(esc_html__('Add %s', 'daytidy'), $singular_readable), // translators: Placeholder values. 'add_new_item' => sprintf(esc_html__('Add New %s', 'daytidy'), $singular_readable), // translators: Placeholder values. 'edit_item' => sprintf(esc_html__('Edit %s', 'daytidy'), $singular_readable), // translators: Placeholder values. 'new_item' => sprintf(esc_html__('New %s', 'daytidy'), $singular_readable), // translators: Placeholder values. 'view_item' => sprintf(esc_html__('View %s', 'daytidy'), $singular_readable), // translators: Placeholder values. 'view_items' => sprintf(esc_html__('View %s', 'daytidy'), $plural_readable), // translators: Placeholder values. 'search_items' => sprintf(esc_html__('Search %s', 'daytidy'), $plural_readable), // translators: Placeholder values. 'not_found' => sprintf(esc_html__('No %s found!', 'daytidy'), $plural_lower), // translators: Placeholder values. 'not_found_in_trash' => sprintf(esc_html__('No %s found in Trash!', 'daytidy'), $plural_lower), // translators: Placeholder values. 'all_items' => sprintf(esc_html__('All %s', 'daytidy'), $plural_readable), // translators: Placeholder values. 'archives' => sprintf(esc_html__('%s Archives', 'daytidy'), $singular_readable), ]; } /** * Used to register the post type in DayTidy system * * @param mixed[] $post_types * @return mixed[] * @see Entity::postTypes() */ public function introduce(array $post_types): array { $post_types[] = $this->PT; return $post_types; } }