/** * The constructor. * * Load a content type by the file. * * @param string $file_path */ public function __construct($file_path = '') { // Try to load the file if the file path is empty. if (empty($file_path)) { $page_type = papi_get_content_type_id(); $file_path = papi_get_file_path($page_type); } parent::__construct($file_path); }
/** * Get page type id by post id. * * @param int $post_id * * @return string */ function papi_get_page_type_id($post_id = 0) { $meta_value = get_post_meta($post_id, papi_get_page_type_key(), true); $content_type_id = empty($meta_value) ? '' : $meta_value; return empty($content_type_id) ? papi_get_content_type_id() : $content_type_id; }
/** * 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; }