function jeml_page_management_dropdown() { global $submenu, $wpdb; $pages = $wpdb->get_results("SELECT ID, post_title, post_name, post_parent FROM {$wpdb->posts} WHERE post_type = 'page' AND post_status = 'publish' ORDER BY menu_order ASC, post_title ASC"); $indexed_pages = get_page_hierarchy($pages); foreach ($pages as $page) { $indexed_pages[$page->ID] = $page; } foreach ($indexed_pages as $page) { $indent = ''; $parent = $page->post_parent; while ($parent != 0) { $indent .= ' '; $parent = $indexed_pages[$parent]->post_parent; } $submenu['edit.php?post_type=page'][] = array($indent . $page->post_title, 'edit_pages', 'post.php?action=edit&post=' . $page->ID); } }
function generate_page_rewrite_rules() { global $wpdb; //get pages in order of hierarchy, i.e. children after parents $posts = get_page_hierarchy($wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_status = 'static'")); //now reverse it, because we need parents after children for rewrite rules to work properly $posts = array_reverse($posts, true); $page_rewrite_rules = array(); $page_attachment_rewrite_rules = array(); if ($posts) { foreach ($posts as $id => $post) { // URI => page name $uri = get_page_uri($id); $attachments = $wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_status = 'attachment' AND post_parent = '$id'"); if ( $attachments ) { foreach ( $attachments as $attachment ) { $attach_uri = get_page_uri($attachment->ID); $page_attachment_rewrite_rules[$attach_uri] = $attachment->post_name; } } $page_rewrite_rules[$uri] = $post; } update_option('page_uris', $page_rewrite_rules); if ( $page_attachment_rewrite_rules ) update_option('page_attachment_uris', $page_attachment_rewrite_rules); } }
/** * Retrieve all page and attachments for pages URIs. * * The attachments are for those that have pages as parents and will be * retrieved. * * @since 2.5.0 * @access public * * @return array Array of page URIs as first element and attachment URIs as second element. */ function page_uri_index() { global $wpdb; //get pages in order of hierarchy, i.e. children after parents $posts = get_page_hierarchy($wpdb->get_results("SELECT ID, post_name, post_parent FROM {$wpdb->posts} WHERE post_type = 'page' AND post_status != 'auto-draft'")); // If we have no pages get out quick if (!$posts) { return array(array(), array()); } //now reverse it, because we need parents after children for rewrite rules to work properly $posts = array_reverse($posts, true); $page_uris = array(); $page_attachment_uris = array(); foreach ($posts as $id => $post) { // URL => page name $uri = get_page_uri($id); $attachments = $wpdb->get_results($wpdb->prepare("SELECT ID, post_name, post_parent FROM {$wpdb->posts} WHERE post_type = 'attachment' AND post_parent = %d", $id)); if (!empty($attachments)) { foreach ($attachments as $attachment) { $attach_uri = get_page_uri($attachment->ID); $page_attachment_uris[$attach_uri] = $attachment->ID; } } $page_uris[$uri] = $id; } return array($page_uris, $page_attachment_uris); }
/** * get_page_hierarchy() - {@internal Missing Short Description}} * * Fetches the pages returned as a FLAT list, but arranged in order of their hierarchy, * i.e., child parents immediately follow their parents. * * @package WordPress * @subpackage Post * @since 2.0 * * @param array $posts posts array * @param int $parent parent page ID * @return array {@internal Missing Description}} */ function get_page_hierarchy($posts, $parent = 0) { $result = array(); if ($posts) { foreach ($posts as $post) { if ($post->post_parent == $parent) { $result[$post->ID] = $post->post_name; $children = get_page_hierarchy($posts, $post->ID); $result += $children; //append $children to $result } } } return $result; }
function generate_page_uri_index() { global $wpdb; //get pages in order of hierarchy, i.e. children after parents $posts = get_page_hierarchy($wpdb->get_results("SELECT ID, post_name, post_parent FROM {$wpdb->posts} WHERE post_type = 'page'")); //now reverse it, because we need parents after children for rewrite rules to work properly $posts = array_reverse($posts, true); $page_uris = array(); $page_attachment_uris = array(); if ($posts) { foreach ($posts as $id => $post) { // URL => page name $uri = get_page_uri($id); $attachments = $wpdb->get_results("SELECT ID, post_name, post_parent FROM {$wpdb->posts} WHERE post_type = 'attachment' AND post_parent = '{$id}'"); if ($attachments) { foreach ($attachments as $attachment) { $attach_uri = get_page_uri($attachment->ID); $page_attachment_uris[$attach_uri] = $attachment->ID; } } $page_uris[$uri] = $id; } delete_option('page_uris'); update_option('page_uris', $page_uris); if ($page_attachment_uris) { delete_option('page_attachment_uris'); update_option('page_attachment_uris', $page_attachment_uris); } } }
/** * prev_lecture( $lecture ) * Get the previous lecture * * @param Mixed $lecture object, current lecture * @return Mixed the previous $lecture object */ function prev_lecture($lecture) { global $bp; // Get lectures $lectures = BPSP_Lectures::has_lectures($bp->groups->current_group->id); if (empty($lectures)) { return null; } // Try to sort them by menu_order usort($lectures, array('BPSP_Lectures', 'cmp_menu_order')); // Use WordPress's hierarchical algorithm $hierarchy = get_page_hierarchy($lectures, 0); // Find current position in hierarchy while (next($hierarchy)) { if (current($hierarchy) == $lecture->post_name) { break; } } $prev = prev($hierarchy); if ($prev) { return BPSP_Lectures::is_lecture($prev); } else { return null; } }