Exemple #1
0
/**
 * Check if the page type should be displayed or not.
 *
 * @param  string|object $page_type
 *
 * @return bool
 */
function papi_display_page_type($page_type)
{
    $post_type = papi_get_post_type();
    if (empty($post_type)) {
        return false;
    }
    if (is_string($page_type)) {
        $page_type = papi_get_page_type_by_id($page_type);
    }
    if (!is_object($page_type)) {
        return false;
    }
    if (!in_array($post_type, $page_type->post_type)) {
        return false;
    }
    $display = $page_type->display($post_type);
    if (!is_bool($display) || $display === false) {
        return false;
    }
    if (preg_match('/papi\\-standard\\-\\w+\\-type/', $page_type->get_id())) {
        return true;
    }
    $parent_page_type = papi_get_page_type_by_post_id(papi_get_parent_post_id());
    if (papi_is_page_type($parent_page_type)) {
        $child_types = $parent_page_type->get_child_types();
        if (!empty($child_types)) {
            return in_array($page_type, $parent_page_type->get_child_types());
        }
    }
    // Run show page type filter.
    return papi_filter_settings_show_page_type($post_type, $page_type);
}
 /**
  * Load property from page type.
  *
  * @param  string $slug
  * @param  string $child_slug
  *
  * @return object
  */
 public function get_property($slug, $child_slug = '')
 {
     $page_type_id = str_replace('papi/', '', papi_get_qs('page'));
     if (empty($page_type_id)) {
         $page_types = papi_get_all_page_types(false, null, true);
         $property = null;
         foreach ($page_types as $index => $page_type) {
             if ($property = $page_type->get_property($slug, $child_slug)) {
                 break;
             }
         }
         if (is_null($property)) {
             return;
         }
         return $property;
     }
     $page_type = papi_get_page_type_by_id($page_type_id);
     if ($page_type instanceof Papi_Option_Type === false) {
         return;
     }
     return $page_type->get_property($slug, $child_slug);
 }
		<?php 
    }
}
?>
<div class="wrap">
	<div class="papi-options-logo"></div>
	<h1><?php 
echo papi()->name;
?>
</h1>

	<br/>

	<?php 
$page_type = papi_get_qs('page_type');
$page_type = papi_get_page_type_by_id($page_type);
if (empty($page_type)) {
    ?>
		<h3><?php 
    _e('Cannot find the page type', 'papi');
    ?>
</h3>
		<p>
			<a href="tools.php?page=papi"><?php 
    echo esc_html('Back to list', 'papi');
    ?>
</a>
		</p>
	<?php 
} else {
    ?>
 /**
  * Get child page types that lives under the current page type.
  *
  * @return array
  */
 public function get_child_types()
 {
     $child_types = [];
     foreach (papi_to_array($this->child_types) as $id) {
         $child_type = papi_get_page_type_by_id($id);
         if (papi_is_page_type($child_type)) {
             $child_types[] = $child_type;
         }
     }
     return $child_types;
 }
Exemple #5
0
/**
 * 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_page_type_by_id($page_type_id);
    if (empty($page_type)) {
        return '';
    }
    return $page_type->name;
}
 /**
  * Load property from page type.
  *
  * @param  string $slug
  * @param  string $child_slug
  *
  * @return object
  */
 public function get_property($slug, $child_slug = '')
 {
     $page_type_id = papi_get_page_type_id($this->id);
     $page_type = papi_get_page_type_by_id($page_type_id);
     if ($page_type instanceof Papi_Page_Type === false) {
         return;
     }
     return $page_type->get_property($slug, $child_slug);
 }
Exemple #7
0
 /**
  * Import data to Papi.
  *
  * @param  mixed $options
  * @param  array $fields
  *
  * @return bool
  */
 public function import($options, array $fields = [])
 {
     $options = $this->get_import_options($options);
     $post_id = $options['post_id'];
     $page_type = $options['page_type'];
     if (isset($options['update_arrays'])) {
         $this->driver->set_options(['update_array' => $options['update_arrays']]);
     }
     if (empty($post_id) || empty($fields)) {
         return false;
     }
     if (empty($page_type)) {
         $page_type = papi_get_page_type_by_post_id($options['post_id']);
     }
     if (is_string($page_type)) {
         $page_type = papi_get_page_type_by_id($page_type);
     }
     if (!papi_is_page_type($page_type)) {
         return false;
     }
     $result = true;
     foreach ($fields as $slug => $value) {
         if (!is_string($slug) || papi_is_empty($value)) {
             continue;
         }
         $property = $page_type->get_property($slug);
         if (!papi_is_property($property)) {
             $result = false;
             continue;
         }
         $value = $this->fire_filter(['filter' => 'driver:value', 'type' => 'before', 'value' => [$value, $slug]]);
         $value = $this->get_value(['post_id' => $post_id, 'property' => $property, 'slug' => $slug, 'value' => $value]);
         $value = $this->fire_filter(['filter' => 'driver:value', 'type' => 'after', 'value' => [$value, $slug]]);
         $out = papi_update_property_meta_value(['post_id' => $post_id, 'slug' => $slug, 'value' => $value]);
         $result = $out ? $result : $out;
     }
     return $result;
 }
 /**
  * Get current page type.
  *
  * @return Papi_Page_Type
  */
 private function get_page_type()
 {
     if ($page_type = papi_get_page_type_by_id(papi_get_page_type_id())) {
         return $page_type;
     }
 }
Exemple #9
0
 /**
  * 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;
     }
     if (empty($this->page_type_id)) {
         // If only page type is used, override the page type value.
         $this->page_type_id = papi_filter_settings_only_page_type($this->post_type);
         if (empty($this->page_type_id)) {
             // Load page types that don't have any real post type.
             $this->page_type_id = str_replace('papi/', '', papi_get_qs('page'));
         }
         if (empty($this->page_type_id)) {
             $this->page_type_id = papi_get_page_type_id();
         }
     }
     if (empty($this->page_type_id)) {
         return false;
     }
     $this->page_type = papi_get_page_type_by_id($this->page_type_id);
     // Do a last check so we can be sure that we have a page type instance.
     return $this->page_type instanceof Papi_Page_Type;
 }
Exemple #10
0
		<label class="screen-reader-text" for="add-new-page-search">
			<?php 
echo $post_type->labels->search_items;
?>
		</label>

		<input placeholder="<?php 
echo $post_type->labels->search_items;
?>
..." type="search" name="add-new-page-search"
		       id="add-new-page-search" class="papi-search">
	</h2>

	<div class="papi-box-list">
		<?php 
$parent_page_type = papi_get_page_type_by_id(papi_get_page_type_id());
$page_types = papi_get_all_page_types();
$show_standard = papi_filter_settings_show_standard_page_type($post_type_name);
if (papi_is_page_type($parent_page_type)) {
    $child_types = $parent_page_type->get_child_types();
    $page_types = empty($child_types) ? $page_types : $child_types;
    if (!$show_standard) {
        $show_standard = $parent_page_type->standard_type;
    }
}
if ($show_standard) {
    $id = sprintf('papi-standard-%s-type', $post_type_name);
    $page_type = new Papi_Page_Type($id);
    $page_type->id = $id;
    $page_type->name = papi_filter_settings_standard_page_name($post_type_name);
    $page_type->description = papi_filter_settings_standard_page_description($post_type_name);