| | |
| | | |
| | | if (empty($posts)) { |
| | | return new Result( |
| | | outcome: 'failed', |
| | | outcome: 'success', |
| | | result: ['message' => 'No posts to update'] |
| | | ); |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | protected function maybeReorderTimeline(int $parentID):void |
| | | protected function getTimelinePosts(int $parentID):array |
| | | { |
| | | // clean_post_cache($parentID); |
| | | $parent = get_post($parentID); |
| | | if (!$parent) { |
| | | return; |
| | | return []; |
| | | } |
| | | |
| | | $children = get_children([ |
| | |
| | | |
| | | |
| | | if (count($children) === 0) { |
| | | return; |
| | | return []; |
| | | } |
| | | |
| | | $allPosts = array_merge([$parent], $children); |
| | |
| | | return strtotime($a->post_date) <=> strtotime($b->post_date); |
| | | }); |
| | | |
| | | return $allPosts; |
| | | } |
| | | protected function maybeReorderTimeline(int $parentID):void |
| | | { |
| | | // clean_post_cache($parentID); |
| | | $parent = get_post($parentID); |
| | | if (!$parent) { |
| | | return; |
| | | } |
| | | |
| | | $allPosts = $this->getTimelinePosts($parentID); |
| | | if (empty($allPosts)) { |
| | | return; |
| | | } |
| | | |
| | | |
| | | |
| | | // Check if order changed |
| | | $needsReorder = false; |
| | |
| | | 'post_title' => $data['post_title'] ?? apply_filters('jvbDefaultTitle', '', $registrar->getSlug()), |
| | | 'post_status' => $data['status'] ?? 'draft', |
| | | ]); |
| | | error_log('Created new post: '.print_r($newId, true)); |
| | | |
| | | if (!$newId || is_wp_error($newId)) { |
| | | $results['errors'][$ID] = 'Could not create post'; |
| | |
| | | return !array_key_exists('for_all', $field) || !$field['for_all']; |
| | | })); |
| | | |
| | | |
| | | if (array_key_exists('timeline_gallery', $data)) { |
| | | //This should only happen if we delete an image from the gallery |
| | | $changes = explode(',', $data['timeline_gallery']); |
| | | $timelinePosts = $this->getTimelinePosts($parentId); |
| | | if (!empty($timelinePosts)) { |
| | | $posts = array_map(function($item) { return $item->ID; }, $timelinePosts); |
| | | $changed = false; |
| | | foreach ($posts as $tID) { |
| | | if (!in_array($tID, $changes)) { |
| | | $changed = true; |
| | | wp_delete_post($tID, true); |
| | | } |
| | | } |
| | | if ($changed) { |
| | | $results['timelineParents'][] = $parentId; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | if (array_key_exists('post_date', $data) && !in_array($parentId, $results['timelineParents'])) { |
| | | $results['timelineParents'][] = $parentId; |
| | | } |