/** * Load property from page type. * * @param string $slug * @param string $child_slug * * @return object */ public function get_property($slug, $child_slug = '') { $content_type_id = papi_get_qs('page'); if (empty($content_type_id)) { $property = null; $content_types = papi_get_all_content_types(['types' => 'option']); foreach ($content_types as $index => $content_type) { if ($property = $content_type->get_property($slug, $child_slug)) { $this->option_type = $content_type; break; } } if (is_null($property)) { return; } return $property; } $content_type = papi_get_content_type_by_id($content_type_id); if (!papi_is_option_type($content_type)) { return; } $this->option_type = $content_type; return $content_type->get_property($slug, $child_slug); }
/** * Get the Page type name. * * @param int $post_id * * @return string */ function papi_get_page_type_name($post_id = 0) { $post_id = papi_get_post_id($post_id); if (empty($post_id)) { return ''; } $page_type_id = papi_get_page_type_id($post_id); if (empty($page_type_id)) { return ''; } $page_type = papi_get_content_type_by_id($page_type_id); if (empty($page_type)) { return ''; } return $page_type->name; }
/** * Load right Papi file if it exists. * * @return bool */ public function setup_papi() { // If the post type isn't in the post types array we can't proceed. if (in_array($this->post_type, ['revision', 'nav_menu_item'])) { return false; } $content_type_id = papi_get_content_type_id(); // If a post type exists, try to load the content type id // from only page type filter. if ($this->post_type) { $content_type_id = papi_filter_settings_only_page_type($this->post_type); } // If the content type id is empty try to load // the content type id from `page` query string. // // Example: // /wp-admin/options-general.php?page=papi/option/site-option-type if (empty($content_type_id)) { $content_type_id = preg_replace('/^papi\\/\\w+\\//', '', papi_get_qs('page')); } // Use the default content type id if empty. if (empty($content_type_id)) { $content_type_id = papi_get_content_type_id(); } // If no content type id exists Papi can't setup a content type. if (empty($content_type_id)) { return false; } // Do a last check so we can be sure that we have a page type instance. return ($this->page_type = papi_get_content_type_by_id($content_type_id)) instanceof Papi_Content_Type; }