/** * This function will update all children of a particular page (if any) * by renaming/moving all related files to their new path and updating * their database information. This is a recursive function and will work * to any depth. * * @param integer $page_id * The ID of the Page whose children need to be updated * @param string $page_path * The path of the Page, which is the handles of the Page parents. If the * page has multiple parents, they will be separated by a forward slash. * eg. article/read. If a page has no parents, this parameter should be null. * @return boolean */ public static function editPageChildren($page_id = null, $page_path = null) { if (!is_int($page_id)) { return false; } $page_path = trim($page_path, '/'); $children = PageManager::fetchChildPages($page_id); foreach ($children as $child) { $child_id = $child['id']; $fields = array('path' => $page_path); if (!PageManager::createPageFiles($page_path, $child['handle'], $child['path'], $child['handle'])) { $success = false; } if (!PageManager::edit($child_id, $fields)) { $success = false; } self::editPageChildren($child_id, $page_path . '/' . $child['handle']); } return $success; }