| | |
| | | } |
| | | |
| | | add_action('init', [$this, 'registerDirectories']); |
| | | jvb_register_do_once('directories_registered', [$this, 'activate']); |
| | | add_action('render_block', [$this, 'renderBlock'], 99999, 3); |
| | | } |
| | | |
| | |
| | | 'public' => true, |
| | | 'menu_icon' => jvbCSSIcon('list-dashes'), |
| | | 'publicly_queryable' => true, |
| | | 'show_in_menu' => false, |
| | | 'show_in_menu' => true, |
| | | 'show_in_admin_bar' => false, |
| | | 'has_archive' => true, |
| | | 'hierarchical' => true, |
| | |
| | | |
| | | } |
| | | |
| | | public function activate() |
| | | public static function activate() |
| | | { |
| | | $this->registerDirectories(); |
| | | $tmp = new self(); |
| | | $tmp->registerDirectories(); |
| | | |
| | | $created = []; |
| | | $directories = []; |
| | | |
| | | foreach($this->directories as $directory => $type) { |
| | | $config = $this->getConfigFromType($directory); |
| | | $title = $this->directoryTitle($config); |
| | | foreach($tmp->directories as $directory => $type) { |
| | | $config = $tmp->getConfigFromType($directory); |
| | | $title = $tmp->directoryTitle($config); |
| | | $excerpt = implode(' ', $config['description']??[]); |
| | | $ID = wp_insert_post([ |
| | | 'post_type' => BASE.'directory', |
| | |
| | | } |
| | | } |
| | | |
| | | protected function buildDirectoryList():array |
| | | { |
| | | $saved = get_option(BASE.'directory_list', []); |
| | | if (empty($saved)) { |
| | | $all = new WP_Query([ |
| | | 'post_type' => BASE.'directory', |
| | | 'post_status' => 'publish', |
| | | 'posts_per_page' => -1, |
| | | ]); |
| | | foreach($all->posts as $post) { |
| | | $saved[$post->post_name] = [ |
| | | 'slug' => $post->post_name, |
| | | 'title' => $post->post_title, |
| | | 'ID' => $post->ID, |
| | | 'url' => get_the_permalink($post->ID), |
| | | 'page' => $post->post_title, |
| | | 'description' => $this->getConfigFromType($post->post_name)['description']??'', |
| | | 'type' => get_post_meta($post->ID, self::$type,true), |
| | | 'extra' => $this->getConfigFromType($post->post_name)['directory_extra']??[], |
| | | ]; |
| | | } |
| | | update_option(BASE.'directory_list', $saved); |
| | | wp_reset_postdata(); |
| | | } |
| | | return $saved; |
| | | } |
| | | |
| | | public function getDirectoryPageIDs():array |
| | | { |
| | | if (empty($this->directoryPageIDs)) { |
| | |
| | | public function getDirectoryList():array |
| | | { |
| | | if (empty($this->directoryList)) { |
| | | $this->directoryList = get_option(BASE.'directory_list', []); |
| | | $this->directoryList = $this->buildDirectoryList(); |
| | | } |
| | | return $this->directoryList; |
| | | } |