|
3 | 3 | namespace DotOrg\TryWordPress;
|
4 | 4 |
|
5 | 5 | class Storage {
|
6 |
| - private string $post_type; |
7 |
| - private string $post_type_name; |
| 6 | + private string $liberated_data_post_type; |
| 7 | + private string $liberated_data_post_type_name; |
| 8 | + private string $crawler_data_post_type; |
| 9 | + private string $crawler_data_post_type_name = 'Crawler URL'; |
| 10 | + private string $crawler_data_post_type_name_plural = 'Crawler URLs'; |
8 | 11 |
|
9 | 12 | private array $custom_post_types_supports = array( 'title', 'editor', 'custom-fields' );
|
10 | 13 |
|
11 |
| - public function __construct( string $post_type ) { |
12 |
| - $this->post_type = $post_type; |
13 |
| - $this->post_type_name = ucwords( str_replace( '_', ' ', $post_type ) ); |
| 14 | + public function __construct( string $liberated_data_post_type, string $crawler_data_post_type ) { |
| 15 | + $this->liberated_data_post_type = $liberated_data_post_type; |
| 16 | + $this->liberated_data_post_type_name = ucwords( str_replace( '_', ' ', $liberated_data_post_type ) ); |
| 17 | + $this->crawler_data_post_type = $crawler_data_post_type; |
14 | 18 |
|
15 | 19 | add_action( 'init', array( $this, 'register_post_types' ) );
|
16 | 20 | }
|
17 | 21 |
|
18 |
| - private function get_singular_name(): string { |
19 |
| - return $this->post_type_name; |
20 |
| - } |
| 22 | + public function register_post_types(): void { |
| 23 | + register_post_type( |
| 24 | + $this->liberated_data_post_type, |
| 25 | + array( |
| 26 | + 'public' => false, |
| 27 | + 'exclude_from_search' => true, |
| 28 | + 'publicly_queryable' => false, |
| 29 | + 'show_in_rest' => true, |
| 30 | + 'show_ui' => true, |
| 31 | + 'show_in_menu' => WP_DEBUG, |
| 32 | + 'menu_icon' => 'dashicons-database', |
| 33 | + 'supports' => $this->custom_post_types_supports, |
| 34 | + 'labels' => $this->get_post_type_registration_labels( |
| 35 | + $this->liberated_data_post_type_name, |
| 36 | + $this->liberated_data_post_type_name |
| 37 | + ), |
| 38 | + 'rest_base' => $this->liberated_data_post_type, |
| 39 | + ) |
| 40 | + ); |
21 | 41 |
|
22 |
| - private function get_plural_name(): string { |
23 |
| - return $this->post_type_name; |
24 |
| - } |
| 42 | + register_post_type( |
| 43 | + $this->crawler_data_post_type, |
| 44 | + array( |
| 45 | + 'public' => false, |
| 46 | + 'exclude_from_search' => true, |
| 47 | + 'publicly_queryable' => false, |
| 48 | + 'show_in_rest' => false, |
| 49 | + 'show_ui' => true, |
| 50 | + 'show_in_menu' => WP_DEBUG, |
| 51 | + 'menu_icon' => 'dashicons-editor-ul', |
| 52 | + 'supports' => array( '' ), // has to be empty string array, otherwise title and content support comes in by default |
| 53 | + 'labels' => $this->get_post_type_registration_labels( |
| 54 | + $this->crawler_data_post_type_name, |
| 55 | + $this->crawler_data_post_type_name_plural |
| 56 | + ), |
| 57 | + 'rest_base' => $this->liberated_data_post_type, |
| 58 | + ) |
| 59 | + ); |
25 | 60 |
|
26 |
| - public function register_post_types(): void { |
27 |
| - $name = $this->get_singular_name(); |
28 |
| - $name_plural = $this->get_plural_name(); |
29 |
| - |
30 |
| - $args = array( |
31 |
| - 'public' => false, |
32 |
| - 'exclude_from_search' => true, |
33 |
| - 'publicly_queryable' => false, |
34 |
| - 'show_in_rest' => true, |
35 |
| - 'show_ui' => true, |
36 |
| - 'show_in_menu' => WP_DEBUG, |
37 |
| - 'menu_icon' => 'dashicons-database', |
38 |
| - 'supports' => $this->custom_post_types_supports, |
39 |
| - 'labels' => $this->get_post_type_registration_labels( $name, $name_plural ), |
40 |
| - 'rest_base' => $this->post_type, |
| 61 | + register_post_status( |
| 62 | + 'discovered', |
| 63 | + array( |
| 64 | + 'label' => _x( 'Discovered', 'post status', 'try_wordpress' ), |
| 65 | + 'public' => false, |
| 66 | + 'exclude_from_search' => true, |
| 67 | + 'show_in_admin_all_list' => true, |
| 68 | + 'show_in_admin_status_list' => true, |
| 69 | + 'internal' => true, |
| 70 | + // translators: %s: Number of discovered posts |
| 71 | + 'label_count' => _n_noop( 'Discovered <span class="count">(%s)</span>', 'Discovered <span class="count">(%s)</span>', 'try_wordpress' ), |
| 72 | + ) |
41 | 73 | );
|
42 | 74 |
|
43 |
| - register_post_type( $this->post_type, $args ); |
| 75 | + register_post_status( |
| 76 | + 'crawled', |
| 77 | + array( |
| 78 | + 'label' => _x( 'Crawled', 'post status', 'try_wordpress' ), |
| 79 | + 'public' => false, |
| 80 | + 'exclude_from_search' => true, |
| 81 | + 'show_in_admin_all_list' => true, |
| 82 | + 'show_in_admin_status_list' => true, |
| 83 | + 'internal' => true, |
| 84 | + // translators: %s: Number of crawled posts |
| 85 | + 'label_count' => _n_noop( 'Crawled <span class="count">(%s)</span>', 'Crawled <span class="count">(%s)</span>', 'try_wordpress' ), |
| 86 | + ) |
| 87 | + ); |
44 | 88 | }
|
45 | 89 |
|
46 | 90 | public function get_post_type_registration_labels( string $name, string $name_plural ): array {
|
|
0 commit comments