/** * Overwrites capabilities in certain scenarios. * * @since 1.0.0 * @access public * @param array $caps * @param string $cap * @param int $user_id * @param array $args * @return array */ function mb_reply_map_meta_cap($caps, $cap, $user_id, $args) { /* Checks if a user can read a specific reply. */ if ('read_post' === $cap && mb_is_reply($args[0])) { $post = get_post($args[0]); /* Only run our code if the user isn't the post author. */ if ($user_id != $post->post_author) { $topic_id = $post->post_parent; /* If we have a topic and the user can't read it, don't allow reading the reply. */ if (0 < $topic_id && !user_can($user_id, 'read_post', $topic_id)) { $caps = array('do_not_allow'); /* If the user can read the topic, check if they can read the reply. */ } else { $post_type = get_post_type_object($post->post_type); if ($post_type->cap->read !== $post_type->cap->read_others_replies) { $caps[] = $post_type->cap->read_others_replies; } else { $caps = array(); } } } else { $caps = array(); } /* Meta cap for editing a single reply. */ } elseif ('edit_post' === $cap && mb_is_reply($args[0])) { $post = get_post($args[0]); $reply_obj = get_post_type_object(mb_get_reply_post_type()); // Spam topics if (mb_is_reply_spam($args[0])) { $caps[] = $reply_obj->cap->edit_spam_replies; } /* Meta cap for spamming a single reply. */ } elseif ('spam_reply' === $cap) { $caps = array(); $caps[] = user_can($user_id, 'edit_reply', $args[0]) ? 'spam_replies' : 'do_not_allow'; /* Meta cap check for accessing the reply form. */ } elseif ('access_reply_form' === $cap) { $caps = array('create_replies'); if (mb_is_single_topic()) { $topic_id = mb_get_topic_id(); $topic_status = mb_get_topic_status($topic_id); $topic_type = mb_get_topic_type($topic_id); if (!current_user_can('read_topic', $topic_id)) { $caps[] = 'do_not_allow'; } elseif (!mb_topic_allows_replies($topic_id)) { $caps[] = 'do_not_allow'; } } elseif (mb_is_reply_edit() && !user_can($user_id, 'edit_post', mb_get_reply_id())) { $caps[] = 'do_not_allow'; } } return $caps; }
/** * Returns the reply ID. * * @since 1.0.0 * @access public * @param int $reply_id * @return int */ function mb_get_reply_id($reply_id = 0) { $mb = message_board(); if (is_numeric($reply_id) && 0 < $reply_id) { $_reply_id = $reply_id; } elseif ($mb->reply_query->in_the_loop && isset($mb->reply_query->post->ID)) { $_reply_id = $mb->reply_query->post->ID; } elseif ($mb->search_query->in_the_loop && isset($mb->search_query->post->ID) && mb_is_reply($mb->search_query->post->ID)) { $_reply_id = $mb->search_query->post->ID; } elseif (mb_is_single_reply()) { $_reply_id = get_queried_object_id(); } elseif (get_query_var('reply_id')) { $_reply_id = get_query_var('reply_id'); } else { $_reply_id = 0; } return apply_filters('mb_get_reply_id', absint($_reply_id), $reply_id); }
/** * Resets topic/reply data when the post status is changed from 'trash' to 'publish'. * * @since 1.0.0 * @access public * @param $post object * @return void */ function mb_trash_to_publish($post) { if (mb_is_topic($post->ID)) { mb_reset_topic_data($post, true); } elseif (mb_is_reply($post->ID)) { mb_reset_reply_data($post, true); } }
?> <br /> <?php mb_topic_time(); ?> </td><!-- .mb-col-datetime --> <td class="mb-col-author"> <?php mb_topic_author_profile_link(); ?> </td><!-- .mb-col-author --> </tr> <?php } elseif (mb_is_reply()) { ?> <tr <?php post_class(); ?> > <td class="mb-col-title"> <?php mb_reply_link(); ?> <div class="mb-reply-summary"> <?php the_excerpt(); ?> </div><!-- .entry-meta -->
function mb_get_thread_position($post_id = 0) { $post_id = mb_get_post_id($post_id); $position = mb_is_reply($post_id) ? mb_get_reply_position($post_id) + 1 : 1; return apply_filters('mb_get_thread_position', $position); }
/** * Filter on the post type link for replies. If the user doesn't have permission to view the reply, * return an empty string. Else, generate the reply URL based on the topic ID. * * @since 1.0.0 * @access public * @param string $link * @param object $post * @return string */ function mb_reply_post_type_link($link, $post) { /* If not viewing a reply, return the orignal URL. */ if (!mb_is_reply($post->ID)) { return $link; } /* If the user can't read the reply, return empty string. */ if (!current_user_can('read_reply', $post->ID)) { return ''; } /* Generate reply URL. */ $url = mb_generate_reply_url($post->ID); return !empty($url) ? $url : $link; }
/** * Returns a forum's last post URL. * * @since 1.0.0 * @access public * @param int $forum_id * @return string */ function mb_get_forum_last_post_url($forum_id = 0) { $forum_id = mb_get_forum_id($forum_id); $last_id = mb_get_forum_last_post_id($forum_id); $url = ''; if ($last_id) { $url = mb_is_reply($last_id) ? mb_get_reply_url($last_id) : mb_get_topic_url($last_id); } return apply_filters('mb_get_forum_last_post_url', $url, $forum_id); }
/** * Filters the edit post link for front-end editing. * * @since 1.0.0 * @access public * @param string $url * @param int $post_id */ function mb_get_edit_post_link($url, $post_id) { if (is_admin()) { return $url; } if (mb_is_forum($post_id)) { $url = add_query_arg(array('mb_action' => 'edit', 'forum_id' => $post_id), mb_get_board_home_url()); } elseif (mb_is_topic($post_id)) { $url = add_query_arg(array('mb_action' => 'edit', 'topic_id' => $post_id), mb_get_board_home_url()); } elseif (mb_is_reply($post_id)) { $url = add_query_arg(array('mb_action' => 'edit', 'reply_id' => $post_id), mb_get_board_home_url()); } return $url; }