Esempio n. 1
0
/**
 * Get edit link when admin is logged in
 * @param int $id (post ID or term ID)
 * @param string $edit_type (post type or taxonomy slug)
 * @param string $label (optional admin-facing name for $edit_type)
 * @param bool $display_inline (omit wrapping paragraph)
 * @return string (HTML)
 */
function get_edit_link($id = null, $edit_type = 'post', $label = null, $display_inline = false)
{
    if (!(is_user_logged_in() && current_user_can('manage_options'))) {
        return null;
    }
    $link_class = 'class="front-end-edit-link"';
    $link_tag = $display_inline ? 'span' : 'p';
    if (is_null($label)) {
        $label = Str::human(str_replace('-', ' ', $edit_type));
    }
    $subclasses = \Taco\Post\Loader::getSubclasses();
    $subclasses_machine = array_map(function ($el) {
        $el = substr($el, strrpos($el, '\\'));
        $el = Str::camelToHuman($el);
        $el = Str::machine($el, '-');
        return $el;
    }, $subclasses);
    if (in_array($edit_type, $subclasses_machine)) {
        // Edit post or display list of posts of this type
        $post_type_link = !is_null($id) ? get_edit_post_link($id) : '/wp-admin/edit.php?post_type=' . $edit_type;
        return sprintf('<%s %s><a href="%s">Edit %s</a></%s>', $link_tag, $link_class, $post_type_link, $label, $link_tag);
    }
    // Find an applicable post type for editing a custom term
    $post_type = null;
    $post_types_by_taxonomy = [];
    foreach ($subclasses as $subclass) {
        if (strpos($subclass, '\\') !== false) {
            $subclass = '\\' . $subclass;
        }
        $taxonomies = \Taco\Post\Factory::create($subclass)->getTaxonomies();
        if (Arr::iterable($taxonomies)) {
            foreach ($taxonomies as $key => $taxonomy) {
                $taxonomy_slug = is_array($taxonomy) ? $key : $taxonomy;
                $post_types_by_taxonomy[$taxonomy_slug][] = $subclass;
            }
        }
    }
    $post_types_by_taxonomy = array_unique($post_types_by_taxonomy);
    if (array_key_exists($edit_type, $post_types_by_taxonomy)) {
        $post_type = reset($post_types_by_taxonomy[$edit_type]);
        $post_type = substr($post_type, strrpos($post_type, '\\'));
        $post_type = Str::camelToHuman($post_type);
        $post_type = Str::machine($post_type, '-');
    } else {
        $post_type = 'post';
    }
    if (is_null($id)) {
        // View taxonomy term list
        return sprintf('<%s %s><a href="/wp-admin/edit-tags.php?taxonomy=%s&post_type=%s">View %ss</a></%s>', $link_tag, $link_class, $edit_type, $post_type, $label, $link_tag);
    }
    // Edit term
    return sprintf('<%s %s><a href="%s">Edit %s</a></%s>', $link_tag, $link_class, get_edit_term_link($id, $edit_type, $post_type), $label, $link_tag);
}
Esempio n. 2
0
 /**
  * Find a term
  * @param integer $term_id
  * @return object
  */
 public static function find($term_id)
 {
     $instance = Post\Factory::create(get_called_class());
     $instance->load($term_id);
     return $instance;
 }
<?php

//setup the page
$page = \Taco\Post\Factory::create($post);
get_header();
?>

on the page
          
<?php 
echo $page->getTheTitle();
echo $page->getTheContent();
?>
    

<?php 
get_footer();
Esempio n. 4
0
 public static function updateSubPosts($post_id, $fields_values, $object_post_parent = null)
 {
     $post_id = trim(preg_replace('/\\D/', '', $post_id));
     $subpost = \SubPost::find($post_id);
     $field_assigned_to = $subpost->get('field_assigned_to');
     $subpost_fields = \Taco\Post\Factory::create($object_post_parent->ID)->getFields()[$field_assigned_to][$subpost->get('fields_variation')]['fields'];
     if (wp_is_post_revision($post_parent)) {
         return false;
     }
     $array_remove_values = array_diff(array_keys($fields_values), array_keys($subpost_fields));
     foreach ($fields_values as $k => $v) {
         update_post_meta($post_id, $k, $v);
     }
     foreach ($array_remove_values as $field_key) {
         delete_post_meta($post_id, $field_key);
     }
     remove_action('save_post', 'AddMany::saveAll');
     return true;
 }
Esempio n. 5
0
 /**
  * Find a post
  * @param integer $post_id
  * @return object
  */
 public static function find($post_id, $load_terms = true)
 {
     $instance = Post\Factory::create(get_called_class());
     $instance->load($post_id, $load_terms);
     return $instance;
 }
 /**
  * Get breadcrumbs HTML
  * @param \Taco\Post $post_obj
  * @return string HTML
  */
 public static function getBreadcrumbs(\Taco\Post $post_obj)
 {
     $separator = ' &raquo; ';
     $post_id = $post_obj->get('ID');
     $post_type = $post_obj->getPostType();
     $ancestor_links = array();
     $post_title = null;
     if (is_archive()) {
         // This is the blog archive, what to do for breadcrumbs here?
         return null;
     }
     if ($post_type == 'page') {
         $post_title = $post_obj->getTheTitle();
         $ancestors = get_post_ancestors($post_id);
         if (Arr::iterable($ancestors)) {
             $ancestors = array_reverse($ancestors);
             foreach ($ancestors as $ancestor_post_id) {
                 $ancestor = \Taco\Post\Factory::create($ancestor_post_id, false);
                 $single_post = get_post($post_id);
                 $ancestor_links[] = sprintf('<li><a href="%s">%s</a></li>', $ancestor->getPermalink(), $ancestor->getTheTitle());
             }
         }
     } elseif ($post_type == 'article') {
         $ancestor_links[] = '<li><a href="' . URL_NEWS . '">News</a></li>';
         $topics = $post_obj->getTerms('topic');
         if (Arr::iterable($topics)) {
             $topic = reset($topics);
             $ancestor_links[] = sprintf('<li><a href="%s">%s</a></li>', $topic->getPermalink(), $topic->get('name'));
         }
     }
     // Don't display breadcrumbs unless there's at least one ancestor
     if (!Arr::iterable($ancestor_links)) {
         return null;
     }
     return sprintf('<ul class="bread-crumbs">
     %s
     <li>%s</li>
   </ul>', join('', $ancestor_links), $post_title);
 }
<?php

get_header();
// get page
$blog_post = \Taco\Post\Factory::create($post);
?>

on the post
          
<?php 
echo $blog_post->getTheTitle();
echo $blog_post->getTheContent();
?>
    

<?php 
get_footer();
    <?php 
echo $resources_search->renderGroup('taxonomy', 1);
?>
  </div>
</div>
<?php 
echo $resources_search->renderSearchFormFooter();
?>


<?php 
$results = $resources_search->getSearchresults();
if (\AppLibrary\Arr::iterable($results)) {
    ?>
  <?php 
    $result_posts = \Taco\Post\Factory::createMultiple($results);
    ?>
  <?php 
    foreach ($result_posts as $r) {
        ?>
    <div class="row">
      <div class="small-12 columns">
        <hr>
        <?php 
        echo $r->getTheTitle();
        ?>
        <?php 
        echo $r->getTheContent();
        ?>

        <?php 
Esempio n. 9
0
 /**
  * Get Taco Posts or Terms in the order specficied using a string of comma seperated ids
  * @param string $string_order comma seperated list of ids
  * @param bool $reverse should the collection be reversed
  * @param bool $is_term should the method return terms instead of posts
  * @param string $taxonomy if this method is returning terms, what taxonomy do they belong to
  * @param bool $load_terms should terms be loaded with posts
  * @return array
  */
 public static function getPostsFromOrder($string_order = '', $reverse = false, $is_term = false, $taxonomy = null, $load_terms = true)
 {
     if (!strlen($string_order)) {
         return array();
     }
     if (!preg_match('/\\d+/', $string_order)) {
         return array();
     }
     $ids_array = explode(',', trim(strip_tags($string_order)));
     if (!$is_term) {
         $ids_array = self::getItemsIfExists($ids_array, $is_term);
         $items = \Taco\Post\Factory::createMultiple($ids_array, $load_terms);
     } else {
         $ids_array = self::getItemsIfExists($ids_array, true);
         $items = \Taco\Term\Factory::createMultiple($ids_array, $taxonomy);
     }
     $items = $reverse ? array_reverse($items) : $items;
     return Arr::iterable($items) ? $items : array();
 }