/** * Override labels with labels from the entry type. * * @param Papi_Entry_Type $entry_type */ private function override_labels(Papi_Entry_Type $entry_type) { global $wp_post_types, $wp_taxonomies; if ($entry_type->type === 'taxonomy') { $meta_type_value = papi_get_taxonomy(); } else { $meta_type_value = papi_get_post_type(); } if (empty($meta_type_value) || !isset($wp_post_types[$meta_type_value]) && !isset($wp_taxonomies[$meta_type_value])) { return; } foreach ($entry_type->get_labels() as $key => $value) { // @codeCoverageIgnoreStart if (empty($value)) { continue; } // @codeCoverageIgnoreEnd if ($entry_type->type === 'taxonomy' && isset($wp_taxonomies[$meta_type_value]->labels->{$key})) { $wp_taxonomies[$meta_type_value]->labels->{$key} = $value; } else { if (isset($wp_post_types[$meta_type_value]->labels->{$key})) { $wp_post_types[$meta_type_value]->labels->{$key} = $value; } } } }
/** * Preboot all types and setup the current type if any. */ public function admin_init() { // Preload all page types. foreach (papi_get_post_types() as $post_type) { papi_get_all_entry_types(['args' => $post_type]); } if (!$this->setup_papi()) { return; } // Setup entry type. $this->entry_type->setup(); }
/** * Get meta type value. * * @param Papi_Entry_Type $entry_type * * @return string */ protected function get_meta_type_value($entry_type) { if (in_array($entry_type->get_type(), ['attachment'], true)) { return $entry_type->get_type(); } switch (papi_get_meta_type($entry_type->get_type())) { case 'post': return implode(', ', $entry_type->post_type); case 'term': return implode(', ', $entry_type->taxonomy); default: return 'n/a'; } }
/** * Setup page type. */ public function setup() { parent::setup(); // Remove post type support and meta boxes. $this->remove_post_type_support(); // Add support for displaying information in publish box from a page type. if (method_exists($this, 'publish_box')) { add_action('post_submitbox_misc_actions', [$this, 'publish_box']); } // Hide page template dropdown if it shouldn't be showed. if (!$this->show_page_template) { add_filter('theme_page_templates', '__return_empty_array'); } }
/** * Setup meta data. */ protected function setup_meta_data() { parent::setup_meta_data(); $this->taxonomy = papi_to_array($this->taxonomy); }