Пример #1
0
 /**
  * Load property from page type.
  *
  * @param  string $slug
  * @param  string $child_slug
  *
  * @return null|Papi_Core_Property
  */
 public function get_property($slug, $child_slug = '')
 {
     $page_type_id = papi_get_page_type_id($this->id);
     $page_type = papi_get_entry_type_by_id($page_type_id);
     if ($page_type instanceof Papi_Page_Type === false) {
         return;
     }
     if ($property = $page_type->get_property($slug, $child_slug)) {
         return $this->prepare_property($property);
     }
 }
Пример #2
0
 /**
  * Load property from page type.
  *
  * @param  string $slug
  * @param  string $child_slug
  *
  * @return null|Papi_Core_Property
  */
 public function get_property($slug, $child_slug = '')
 {
     $taxonomy_type_id = papi_get_taxonomy_type_id($this->id, 'term');
     $taxonomy_type = papi_get_entry_type_by_id($taxonomy_type_id);
     if ($taxonomy_type instanceof Papi_Taxonomy_Type === false) {
         return;
     }
     if ($property = $taxonomy_type->get_property($slug, $child_slug)) {
         return $this->prepare_property($property);
     }
 }
Пример #3
0
/**
 * Get the taxonomy type name.
 *
 * @param  int $term_id
 *
 * @return string
 */
function papi_get_taxonomy_type_name($term_id = 0)
{
    $term_id = papi_get_term_id($term_id);
    if (empty($term_id)) {
        return '';
    }
    $entry_type_id = papi_get_taxonomy_type_id($term_id);
    if (empty($entry_type_id)) {
        return '';
    }
    $entry_type = papi_get_entry_type_by_id($entry_type_id);
    if (empty($entry_type)) {
        return '';
    }
    return $entry_type->name;
}
Пример #4
0
 /**
  * Load property from page type.
  *
  * @param  string $slug
  * @param  string $child_slug
  *
  * @return null|object
  */
 public function get_property($slug, $child_slug = '')
 {
     $entry_type_id = papi_get_qs('page');
     if (empty($entry_type_id)) {
         $property = null;
         $entry_types = papi_get_all_entry_types(['types' => 'option']);
         foreach ($entry_types as $entry_type) {
             if ($property = $entry_type->get_property($slug, $child_slug)) {
                 break;
             }
         }
         if (is_null($property)) {
             return;
         }
         return $property;
     }
     $entry_type = papi_get_entry_type_by_id($entry_type_id);
     if ($entry_type instanceof Papi_Option_Type === false) {
         return;
     }
     if ($property = $entry_type->get_property($slug, $child_slug)) {
         return $this->prepare_property($property);
     }
 }
Пример #5
0
 /**
  * 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_entry_type_by_id($id);
         if ($child_type instanceof Papi_Page_Type) {
             $child_types[] = $child_type;
         }
     }
     return $child_types;
 }
Пример #6
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);
     $meta_id = empty($options['meta_id']) ? $options['post_id'] : $options['meta_id'];
     $meta_type = $options['meta_type'];
     $entry_type = $options['page_type'];
     if (isset($options['update_arrays'])) {
         $this->driver->set_options(['update_array' => $options['update_arrays']]);
     }
     if (empty($meta_id) || empty($fields)) {
         return false;
     }
     if (empty($entry_type)) {
         $entry_type = papi_get_entry_type_by_meta_id($meta_id, $meta_type);
     }
     if (is_string($entry_type)) {
         $entry_type = papi_get_entry_type_by_id($entry_type);
     }
     if ($entry_type instanceof Papi_Entry_Type === false) {
         return false;
     }
     update_metadata($meta_type, $meta_id, papi_get_page_type_key(), $entry_type->get_id());
     $result = true;
     foreach ($fields as $slug => $value) {
         if (!is_string($slug) || papi_is_empty($value)) {
             continue;
         }
         $property = $entry_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' => $meta_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(['id' => $meta_id, 'slug' => $slug, 'type' => $meta_type, 'value' => $value]);
         $result = $out ? $result : $out;
     }
     return $result;
 }
Пример #7
0
		<label class="screen-reader-text" for="add-new-page-search">
			<?php 
echo esc_html($post_type->labels->search_items);
?>
		</label>

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

	<div class="papi-box-list">
		<?php 
$parent_page_type = papi_get_entry_type_by_id(papi_get_entry_type_id());
$page_types = papi_get_all_page_types($post_type_name);
$show_standard = papi_filter_settings_show_standard_page_type($post_type_name);
if ($parent_page_type instanceof Papi_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_type_name($post_type_name);
    $page_type->description = papi_filter_settings_standard_page_type_description($post_type_name);
 /**
  * Switch page type if all checks pass.
  *
  * @param  int     $post_id
  * @param  WP_post $post
  */
 public function save_post($post_id, $post)
 {
     // Check if post id and post object is empty or not.
     if (empty($post_id) || empty($post)) {
         return false;
     }
     // Check if our nonce is vailed.
     if (!wp_verify_nonce(papi_get_sanitized_post('papi_meta_nonce'), 'papi_save_data')) {
         return false;
     }
     // Check if so both page type keys exists.
     if (empty($_POST[papi_get_page_type_key()]) || empty($_POST[papi_get_page_type_key('switch')])) {
         return false;
     }
     // Page type information.
     $page_type_id = sanitize_text_field($_POST[papi_get_page_type_key()]);
     $page_type_switch_id = sanitize_text_field($_POST[papi_get_page_type_key('switch')]);
     // Don't update if the same ids.
     if ($page_type_id === $page_type_switch_id) {
         return false;
     }
     $page_type = papi_get_entry_type_by_id($page_type_id);
     $page_type_switch = papi_get_entry_type_by_id($page_type_switch_id);
     $post_type_object = get_post_type_object(papi_get_post_type());
     // Check if page type and post type is not empty.
     if (empty($page_type_switch) || empty($post_type_object)) {
         return false;
     }
     // Check if autosave.
     if (wp_is_post_autosave($post_id)) {
         return false;
     }
     // Check if revision.
     if (wp_is_post_revision($post_id)) {
         return false;
     }
     // Check if revision post type.
     if (in_array($post->post_type, ['revision', 'nav_menu_item'], true)) {
         return false;
     }
     // Check so page type has the post type.
     if (!$page_type->has_post_type($post->post_type) || !$page_type_switch->has_post_type($post->post_type)) {
         return false;
     }
     // Check page type capabilities.
     if (!papi_current_user_is_allowed($page_type_switch->capabilities)) {
         return false;
     }
     // Check so user can edit posts and that the user can publish posts on the post type.
     if (!current_user_can('edit_post', $post_id) || !current_user_can($post_type_object->cap->publish_posts)) {
         return false;
     }
     // Get properties.
     $properties = $page_type->get_properties();
     $properties_switch = $page_type_switch->get_properties();
     // Delete only properties that don't have the same type and slug.
     foreach ($properties as $property) {
         $delete = true;
         // Check if the properties are the same or not.
         foreach ($properties_switch as $property_switch) {
             if ($property_switch->type === $property->type && $property_switch->match_slug($property->get_slug())) {
                 $delete = false;
                 break;
             }
         }
         if (!$delete) {
             continue;
         }
         // Delete property values.
         $property->delete_value($property->get_slug(true), $post_id, papi_get_meta_type());
     }
     // Update page type id.
     return papi_set_page_type_id($post_id, $page_type_switch_id);
 }
Пример #9
0
 /**
  * Get Entry Type instance.
  *
  * @return Papi_Entry_Type|false
  */
 private function get_entry_type()
 {
     if ($this->entry_type instanceof Papi_Entry_Type) {
         return $this->entry_type;
     }
     $entry_type_id = papi_get_entry_type_id();
     // If the entry type id is empty try to load
     // the entry type id from `page` query string.
     //
     // Example:
     //   /wp-admin/options-general.php?page=papi/option/site-option-type
     if (empty($entry_type_id)) {
         $entry_type_id = preg_replace('/^papi\\/\\w+\\//', '', papi_get_qs('page'));
     }
     // Use the default entry type id if empty.
     if (empty($entry_type_id)) {
         $entry_type_id = papi_get_entry_type_id();
     }
     // If no entry type id exists Papi can't setup a entry type.
     if (empty($entry_type_id)) {
         return false;
     }
     return $this->entry_type = papi_get_entry_type_by_id($entry_type_id);
 }
Пример #10
0
 /**
  * Parse term query arguments.
  *
  * @param  array $args
  *
  * @return array
  */
 protected function parse_term_args(array $args)
 {
     if (isset($args['taxonomy_type'])) {
         $args['entry_type'] = $args['taxonomy_type'];
         unset($args['taxonomy_type']);
     }
     $entry_type = papi_get_entry_type_by_id($args['entry_type']);
     if ($entry_type instanceof Papi_Taxonomy_Type) {
         $args['taxonomy'] = papi_to_array($entry_type->taxonomy);
     } else {
         $args['taxonomy'] = isset($args['taxonomy']) ? $args['taxonomy'] : '';
     }
     return $args;
 }
Пример #11
0
/**
 * Get entry type from meta id.
 *
 * @param  int    $id
 * @param  string $type
 *
 * @return Papi_Entry_Type
 */
function papi_get_entry_type_by_meta_id($id = 0, $type = null)
{
    if (!is_numeric($id)) {
        return;
    }
    $type = papi_get_meta_type($type);
    $id = papi_get_meta_id($type, $id);
    if ($id === 0) {
        return;
    }
    if ($entry_type = papi_get_entry_type_id($id, $type)) {
        return papi_get_entry_type_by_id($entry_type);
    }
}
Пример #12
0
 /**
  * Get current type class.
  *
  * @return Papi_Entry_Type
  */
 private function get_entry_type()
 {
     if ($entry_type = papi_get_entry_type_by_id(papi_get_entry_type_id())) {
         return $entry_type;
     }
 }
Пример #13
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 '';
    }
    $entry_type_id = papi_get_page_type_id($post_id);
    if (empty($entry_type_id)) {
        return '';
    }
    $entry_type = papi_get_entry_type_by_id($entry_type_id);
    if (empty($entry_type)) {
        return '';
    }
    return $entry_type->name;
}
Пример #14
0
 /**
  * Get current type class.
  *
  * @return Papi_Entry_Type
  */
 protected function get_entry_type()
 {
     if ($entry_type = papi_get_entry_type_by_id(papi_get_entry_type_id())) {
         return $entry_type;
     }
 }