示例#1
0
 /**
  * Get post taxonomy
  *
  * @param int    $post_id
  *
  * @param string $tax_name
  *
  * @return array
  * @static
  * @access public
  */
 public static function getTaxonomy($post_id, $tax_name = 'category')
 {
     $query_args = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all');
     $terms = \wp_get_object_terms((int) $post_id, $tax_name, $query_args);
     $terms_array = UtlArray::object_to_array($terms);
     return $terms_array;
 }
示例#2
0
 /**
  *
  * if user logged in change user meta data
  *
  * @access protected
  *
  * @param int              $post_like_count post like count
  *
  * @global \SilverWpAddons\object $current_user
  */
 protected function userLoggedLike($post_like_count)
 {
     global $current_user;
     $this->user_id = $current_user->ID;
     // current user
     $liked_posts = $this->getUserLikeMeta();
     // post ids from user meta
     $liked_users = $this->getPostMeta('_user_liked');
     // user ids from post meta
     $liked_posts[] = $this->post_id;
     // Add post id to user meta array
     $liked_users[] = $this->user_id;
     // add user id to post meta array
     $liked_posts = UtlArray::array_remove_empty(\array_unique($liked_posts));
     //$liked_users = \array_unique($liked_users);
     $user_likes = \count($liked_posts);
     // count user likes
     if ($this->alreadyLiked()) {
         //unlike the post
         $liked_posts = \array_diff(array($this->_post_id), $liked_posts);
         // find the key
         $liked_users = \array_diff(array($this->_user_id), $liked_users);
         // find the key
         //unset($liked_posts[ $pid_key ]); // remove from array
         //unset($liked_users[ $uid_key ]); // remove from array
         $user_likes = \count($liked_posts);
         // recount user likes
         // Add user ID to post meta
         // +1 count post meta
         $post_like_count = $this->subtractionLikeCount($post_like_count);
         $this->updatePostLikeMeta($liked_users, $post_like_count);
         if (\is_multisite()) {
             // if multisite support
             // Add post ID to user meta
             // +1 count user meta
             $this->updateUserLikeOption($liked_posts, $user_likes);
         } else {
             // Add post ID to user meta
             // +1 count user meta
             $this->updateUserLikeMeta($liked_posts, $user_likes);
             //silverwp_debug_array($liked_users);
             //silverwp_debug_array($liked_posts);
         }
         // update count on front end
         $this->response(0, $post_like_count);
     } else {
         // like the post
         // Add user ID to post meta
         // +1 count post meta
         $this->updatePostLikeMeta($liked_users, ++$post_like_count);
         if (\is_multisite()) {
             // if multisite support
             // Add post ID to user meta
             // +1 count user meta
             $this->updateUserLikeOption($liked_posts, $user_likes);
         } else {
             // Add post ID to user meta
             // +1 count user meta
             $this->updateUserLikeMeta($liked_posts, $user_likes);
         }
         // update count on front end
         $this->response(1, $post_like_count);
     }
 }
示例#3
0
 /**
  *
  * Get list of edit columns displayed in lists of Post Type
  *
  *
  * list of columns displayed in dashboard list. Example
  * array(
  *       'cb' => array(
  *           'html' => '<input type="checkbox" />',
  *       ),
  *       'title' => array(
  *           'label' => 'Title',
  *       ),
  *       'category' => array(
  *            'label' => 'Categories',
  *       ),
  *       'thumbnail' => array(
  *           'label' => 'Thumbnail',
  *       ),
  *       'tag' => array(
  *           'label' => 'Tags',
  *      ),
  *      'date' => array(
  *          'label' => 'Date',
  *      ),
  *      'author' => array(
  *          'label' => 'Author',
  *      ),
  *  );
  *
  * @access protected
  * @return array
  * @todo move to CustomColumn class
  */
 protected function getEditColumns()
 {
     $columns_default = array('cb' => array('html' => '<input type="checkbox" />'), 'title' => array('label' => Translate::translate('Title')), 'thumbnail' => array('label' => Translate::translate('Thumbnail')), 'author' => array('label' => Translate::translate('Author')), 'date' => array('label' => Translate::translate('Date')));
     $columns = UtlArray::array_remove_part($columns_default, $this->exclude_columns);
     return $columns;
 }
示例#4
0
 /**
  *
  * get list of edit columns displayed in lists of Post Type
  *
  *
  * list of columns displayed in dashboard list. Example
  * array(
  *       'cb' => array(
  *           'html' => '<input type="checkbox" />',
  *       ),
  *       'title' => array(
  *           'label' => 'Title',
  *       ),
  *       'category' => array(
  *            'label' => 'Categories',
  *       ),
  *       'thumbnail' => array(
  *           'label' => 'Thumbnail',
  *       ),
  *       'tag' => array(
  *           'label' => 'Tags',
  *      ),
  *      'date' => array(
  *          'label' => 'Date',
  *      ),
  *      'author' => array(
  *          'label' => 'Author',
  *      ),
  *  );
  *
  * @access protected
  * @return array
  */
 protected function getEditColumns()
 {
     $columns_default = array('cb' => array('html' => '<input type="checkbox" />'), 'title' => array('label' => Translate::translate('Title')), 'thumbnail' => array('label' => Translate::translate('Thumbnail')), 'author' => array('label' => Translate::translate('Author')), 'date' => array('label' => Translate::translate('Date')), 'category' => array('label' => Translate::translate('Categories')), 'tag' => array('label' => Translate::translate('Tags')));
     foreach ($this->taxonomies as $name => $args) {
         if (isset($args['display_column']) && $args['display_column']) {
             $columns_default[$name]['label'] = $args['labels']['name'];
         }
     }
     $columns = UtlArray::array_remove_part($columns_default, $this->exclude_columns);
     return $columns;
 }