| | |
| | | public function registerDirectories():void |
| | | { |
| | | |
| | | $singular = !empty(Site::getDirectorySingular())?:'Directory'; |
| | | $plural = !empty(Site::getDirectorySingular())?: 'Directories'; |
| | | $singular = Site::getDirectorySingular()??'Directory'; |
| | | $plural = Site::getDirectoryPlural()??'Directories'; |
| | | $config = [ |
| | | 'labels' => [ |
| | | 'name' => $plural, |
| | |
| | | } |
| | | |
| | | $config = $registrar->getConfig('directory'); |
| | | |
| | | $title = $config['title']; |
| | | //Bail early if we've already created the page |
| | | $existing = new WP_Query([ |
| | | 'post_type' => BASE.'dash', |
| | | 'name' => sanitize_title($title), |
| | | 'posts_per_page' => 1, |
| | | ]); |
| | | if ($existing->have_posts()) { |
| | | $existing = $existing->posts[0]; |
| | | $created[$directory] = $existing->ID; |
| | | $directories[$directory] = [ |
| | | 'slug' => $existing->post_name, |
| | | 'title' => $existing->post_title, |
| | | 'ID' => $existing->ID, |
| | | 'url' => get_the_permalink($existing->ID), |
| | | 'page' => $existing->post_title, |
| | | 'description'=> $existing->post_excerpt, |
| | | 'type' => $type, |
| | | 'extra' => $config[$directory]['directory_extra']??[], |
| | | ]; |
| | | continue; |
| | | } |
| | | |
| | | $excerpt = implode(' ', $config['description']??[]); |
| | | $ID = wp_insert_post([ |
| | | 'post_type' => BASE.'directory', |
| | | 'post_title' => $title, |
| | | 'post_status' => 'publish', |
| | | 'post_excerpt' => $excerpt, |
| | | 'slug' => sanitize_title($title) |
| | | 'post_name' => sanitize_title($title) |
| | | ]); |
| | | if (!is_wp_error($ID)) { |
| | | add_post_meta($ID, self::$type, $type); |