/**
  * 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;
             }
         }
     }
 }
Beispiel #2
0
/**
 * Load the entry type id on a taxonomy.
 *
 * @param  string $entry_type_id
 * @param  string $type
 *
 * @return string
 */
function papi_load_taxonomy_type_id($entry_type_id = '', $type = 'term')
{
    if ($type !== 'term') {
        return $entry_type_id;
    }
    $key = papi_get_page_type_key();
    $term_id = papi_get_term_id();
    $taxonomy = papi_get_taxonomy($term_id);
    // Try to load the entry type id from only taxonomy type filter.
    if (empty($entry_type_id)) {
        $entry_type_id = papi_filter_settings_only_taxonomy_type($taxonomy);
    }
    // If we have a term id we can load the entry type id from the term.
    if (empty($entry_type_id) && $term_id > 0 && papi_supports_term_meta()) {
        $meta_value = get_term_meta($term_id, $key, true);
        $entry_type_id = empty($meta_value) ? '' : $meta_value;
    }
    // Load entry type id from the container if it exists.
    if (empty($entry_type_id)) {
        $key = sprintf('entry_type_id.taxonomy.%s', $taxonomy);
        if (papi()->exists($key)) {
            return papi()->make($key);
        }
    }
    return $entry_type_id;
}
Beispiel #3
0
/**
 * Load the entry type id on a taxonomy.
 *
 * @param  string $entry_type_id
 * @param  string $type
 *
 * @return string
 */
function papi_load_taxonomy_type_id($entry_type_id = '', $type = 'term')
{
    if ($type !== 'term') {
        return $entry_type_id;
    }
    $key = papi_get_page_type_key();
    $term_id = papi_get_term_id();
    $taxonomy = papi_get_taxonomy($term_id);
    // Try to load the entry type id from only taxonomy type filter.
    if (empty($entry_type_id)) {
        $entry_type_id = papi_filter_settings_only_taxonomy_type($taxonomy);
    }
    // If we have a term id we can load the entry type id from the term.
    if (empty($entry_type_id) && $term_id > 0 && papi_supports_term_meta()) {
        $meta_value = get_term_meta($term_id, $key, true);
        $entry_type_id = empty($meta_value) ? '' : $meta_value;
    }
    // Try to load the entry type from all taxonomy types and check
    // if only one exists of that post type.
    //
    // The same as only taxonomy type filter but without the filter.
    if (empty($entry_type_id)) {
        $key = sprintf('entry_type_id.taxonomy.%s', $taxonomy);
        if (papi()->exists($key)) {
            return papi()->make($key);
        }
        $entries = papi_get_all_entry_types(['args' => $taxonomy, 'mode' => 'include', 'types' => ['taxonomy']]);
        if (is_array($entries)) {
            usort($entries, function ($a, $b) {
                return strcmp($a->name, $b->name);
            });
        }
        $entries = papi_sort_order(array_reverse($entries));
        if (count($entries) === 1) {
            $entry_type_id = $entries[0]->get_id();
            papi()->bind($key, $entry_type_id);
        }
    }
    return $entry_type_id;
}
Beispiel #4
0
 /**
  * Setup actions.
  */
 private function setup_actions()
 {
     add_action('admin_init', [$this, 'admin_init']);
     add_action('edit_form_after_title', [$this, 'edit_form_after_title']);
     add_action('load-post-new.php', [$this, 'load_post_new']);
     add_action('add_meta_boxes', [$this, 'hidden_meta_boxes'], 10);
     if ($taxonomy = papi_get_taxonomy()) {
         add_action($taxonomy . '_add_form', [$this, 'edit_form_after_title']);
         add_action($taxonomy . '_edit_form', [$this, 'edit_form_after_title']);
     }
 }
 /**
  * Save meta boxes.
  *
  * @param int     $id
  * @param object  $post
  */
 public function save_meta_boxes($id, $post = null)
 {
     // Check if there was a multisite switch before.
     if (is_multisite() && ms_is_switched()) {
         return;
     }
     // Can't proceed without a id.
     if (empty($id)) {
         return;
     }
     // Check if our nonce is vailed.
     if (!wp_verify_nonce(papi_get_sanitized_post('papi_meta_nonce'), 'papi_save_data')) {
         return;
     }
     $meta_type = $this->get_meta_type();
     $post = is_array($post) ? (object) $post : $post;
     if ($meta_type === 'post' && ($post_type = get_post_type_object($post->post_type))) {
         // Check so the id is a post id and not a autosave post.
         if ($this->valid_post_id($id)) {
             return;
         }
         // Check the `edit_posts` capability before we continue.
         if (!current_user_can($post_type->cap->edit_posts)) {
             return;
         }
         // Save post revision data.
         if ($parent_id = wp_is_post_revision($id)) {
             $slugs = papi_get_slugs($id, true);
             foreach ($slugs as $slug) {
                 papi_update_field($id, $slug, papi_get_field($parent_id, $slug));
             }
         }
     }
     if ($meta_type === 'term' && ($taxonomy = get_taxonomy(papi_get_taxonomy()))) {
         // Check the `edit_terms` capability before we continue.
         if ($taxonomy && !current_user_can($taxonomy->cap->edit_terms)) {
             return;
         }
     }
     $this->save_properties($id);
 }
Beispiel #6
0
 /**
  * Setup actions.
  */
 protected function setup_actions()
 {
     add_action('admin_init', [$this, 'admin_init']);
     add_action('edit_form_after_title', [$this, 'edit_form_after_title']);
     if ($taxonomy = papi_get_taxonomy()) {
         add_action($taxonomy . '_add_form', [$this, 'edit_form_after_title']);
         add_action($taxonomy . '_edit_form', [$this, 'edit_form_after_title']);
     }
 }
 /**
  * Setup globals.
  */
 protected function setup_globals()
 {
     $this->post_type = papi_get_post_type();
     $this->taxonomy = papi_get_taxonomy();
 }