Пример #1
0
 /**
  * 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;
             }
         }
     }
 }
Пример #2
0
 /**
  * Get meta post type.
  *
  * @return string
  */
 private function get_post_type()
 {
     if ($post_id = papi_get_post_id()) {
         return get_post_type($post_id);
     }
     if ($post_type = papi_get_post_type()) {
         return $post_type;
     }
     return $this->box->id;
 }
Пример #3
0
 /**
  * Get meta post type.
  *
  * @return string
  */
 protected function get_post_type()
 {
     if (papi_get_meta_type() === 'post') {
         if ($post_id = papi_get_post_id()) {
             return get_post_type($post_id);
         }
         if ($post_type = papi_get_post_type()) {
             return $post_type;
         }
     }
     return $this->box->id;
 }
Пример #4
0
 /**
  * Override labels with labels from the page type.
  *
  * @param Papi_Page_Type $page_type
  */
 private function override_labels(Papi_Page_Type $page_type)
 {
     global $wp_post_types;
     $post_type = papi_get_post_type();
     if (empty($post_type) || !isset($wp_post_types[$post_type])) {
         return;
     }
     foreach ($page_type->get_labels() as $key => $value) {
         if (!isset($wp_post_types[$post_type]->labels->{$key}) || empty($value)) {
             continue;
         }
         $wp_post_types[$post_type]->labels->{$key} = $value;
     }
 }
Пример #5
0
 /**
  * The construct.
  */
 public function __construct()
 {
     $this->post_type = papi_get_post_type();
     $this->setup_actions();
     $this->setup_filters();
 }
Пример #6
0
 /**
  * Setup properties.
  */
 protected function setup_properties()
 {
     $this->conditional = new Papi_Core_Conditional();
     if ($this->default_options['sort_order'] === -1) {
         $this->default_options['sort_order'] = papi_filter_settings_sort_order();
     }
     if (papi_is_empty($this->default_options['post_type'])) {
         $this->default_options['post_type'] = papi_get_post_type();
     }
 }
Пример #7
0
 /**
  * Setup default options values.
  * All default values can't be set in the `$default_options` array.
  */
 private function setup_default_options()
 {
     if ($this->default_options['sort_order'] === -1) {
         $this->default_options['sort_order'] = papi_filter_settings_sort_order();
     }
     if (empty($this->default_options['post_type'])) {
         $this->default_options['post_type'] = papi_get_post_type();
     }
     if (papi_is_empty($this->default_options['default'])) {
         $this->default_options['default'] = $this->default_value;
     }
 }
Пример #8
0
 /**
  * Get post type.
  *
  * @return string
  */
 public function get_post_type()
 {
     return papi_get_post_type();
 }
Пример #9
0
/**
 * Get page type id.
 *
 * @param  int $post_id
 *
 * @return string
 */
function papi_get_page_type_id($post_id = 0)
{
    $post_id = papi_get_post_id($post_id);
    $key = papi_get_page_type_key();
    $page_type = '';
    if ($post_id !== 0) {
        $meta_value = get_post_meta($post_id, $key, true);
        $page_type = empty($meta_value) ? '' : $meta_value;
    }
    if (empty($page_type)) {
        $page_type = str_replace('papi/', '', papi_get_qs('page_type'));
    }
    if (empty($page_type)) {
        $page_type = papi_get_sanitized_post(papi_get_page_type_key());
    }
    // Load right page type from a post query string
    if (empty($page_type)) {
        $meta_value = get_post_meta(papi_get_parent_post_id(), $key, true);
        $page_type = empty($meta_value) ? '' : $meta_value;
    }
    // Load page type id from the container if it exists or
    // load it from `papi_get_all_page_types`.
    if (empty($page_type)) {
        $post_type = papi_get_post_type();
        $load_once = papi_filter_core_load_one_type_on();
        $collection_key = 'core.page_type.' . $post_type;
        if (in_array($post_type, $load_once)) {
            if (papi()->exists($collection_key)) {
                return papi()->make($collection_key);
            }
            if ($page_types = papi_get_all_page_types(false, $post_type)) {
                return $page_types[0]->get_id();
            }
        }
    }
    return $page_type;
}
Пример #10
0
<?php

$post_type_name = papi_get_post_type();
$post_type = get_post_type_object($post_type_name);
$post_type = empty($post_type) ? get_post_type_object('page') : $post_type;
?>
<div class="wrap">
	<h1>
		<?php 
echo esc_html(sprintf(__('Add New %s', 'papi'), $post_type->labels->singular_name));
?>

		<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();
 /**
  * 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);
 }
Пример #12
0
 /**
  * Filter the link query results.
  *
  * @param  array $results
  *
  * @return array
  */
 public function wp_link_query(array $results)
 {
     $post_type = papi_get_post_type();
     foreach ($results as $index => $value) {
         $name = papi_get_page_type_name($value['ID']);
         if (empty($name)) {
             $name = papi_filter_settings_standard_page_type_name($post_type);
         }
         $results[$index]['info'] = esc_html($name);
     }
     return $results;
 }
Пример #13
0
/**
 * Load the content type id on a post types.
 *
 * @param  string $content_type_id
 *
 * @return string
 */
function papi_load_page_type_id($content_type_id = '')
{
    $key = papi_get_page_type_key();
    $post_id = papi_get_post_id();
    $post_type = papi_get_post_type($post_id);
    // If we have a post id we can load the content type id
    // from the post.
    if ($post_id > 0) {
        $meta_value = get_post_meta($post_id, $key, true);
        $content_type_id = empty($meta_value) ? '' : $meta_value;
    }
    // Try to fetch the content type id from `page_type`
    // query string.
    if (empty($content_type_id)) {
        $content_type_id = papi_get_qs('page_type');
    }
    // When using `only_page_type` filter we need to fetch the value since it
    // maybe not always saved in the database.
    if (empty($content_type_id)) {
        $content_type_id = papi_filter_settings_only_page_type($post_type);
    }
    // Load right content type from the parent post id.
    if (empty($content_type_id)) {
        $meta_value = get_post_meta(papi_get_parent_post_id(), $key, true);
        $content_type_id = empty($meta_value) ? '' : $meta_value;
    }
    // Load content type id from the container if it exists.
    if (empty($content_type_id)) {
        $key = sprintf('content_type_id.%s', $post_type);
        if (papi()->exists($key)) {
            return papi()->make($key);
        }
    }
    return $content_type_id;
}
Пример #14
0
 /**
  * Setup globals.
  */
 protected function setup_globals()
 {
     $this->post_type = papi_get_post_type();
     $this->taxonomy = papi_get_taxonomy();
 }
Пример #15
0
/**
 * Load the entry type id on a post types.
 *
 * @param  string $entry_type_id
 *
 * @return string
 */
function papi_load_page_type_id($entry_type_id = '')
{
    $key = papi_get_page_type_key();
    $post_id = papi_get_post_id();
    $post_type = papi_get_post_type($post_id);
    // Try to load the entry type id from only page type filter.
    if (empty($entry_type_id)) {
        $entry_type_id = papi_filter_settings_only_page_type($post_type);
    }
    // If we have a post id we can load the entry type id from the post.
    if (empty($entry_type_id) && $post_id > 0) {
        $meta_value = get_post_meta($post_id, $key, true);
        $entry_type_id = empty($meta_value) ? '' : $meta_value;
    }
    // Try to fetch the entry type id from `page_type` query string.
    if (empty($entry_type_id)) {
        $entry_type_id = papi_get_qs('page_type');
    }
    // Load right entry type from the parent post id.
    if (empty($entry_type_id)) {
        $meta_value = get_post_meta(papi_get_parent_post_id(), $key, true);
        $entry_type_id = empty($meta_value) ? '' : $meta_value;
    }
    // Try to load the entry type from all page types and check
    // if only one exists of that post type.
    //
    // The same as only page type filter but without the filter.
    if (empty($entry_type_id)) {
        $key = sprintf('entry_type_id.post_type.%s', $post_type);
        if (papi()->exists($key)) {
            return papi()->make($key);
        }
        $entries = papi_get_all_page_types($post_type);
        if (count($entries) === 1) {
            $entry_type_id = $entries[0]->get_id();
            papi()->bind($key, $entry_type_id);
        }
    }
    return $entry_type_id;
}