function private_groups_check_can_user_view_post() { //uses $post_id and $post_type to get the forum ($forum_id) that the post belongs to global $wp_query; // Get Forum Id for the current post $post_id = $wp_query->post->ID; $post_type = $wp_query->get('post_type'); if (bbp_is_topic_super_sticky($post_id)) { return true; } $forum_id = private_groups_get_forum_id_from_post_id($post_id, $post_type); //then call the function that checks if the user can view this forum, and hence this post if (private_groups_can_user_view_post_id($forum_id)) { return true; } }
function firmasite_social_bbp_get_topic_class($classes, $topic_id) { $bbp = bbpress(); $count = isset($bbp->topic_query->current_post) ? $bbp->topic_query->current_post : 1; if (bbp_is_topic_sticky($topic_id, false)) { $classes[] = 'alert alert-warning panel-body'; } else { if (bbp_is_topic_super_sticky($topic_id)) { $classes[] = 'alert alert-danger panel-body'; } else { $classes[] = (int) $count % 2 ? 'panel-footer' : 'panel-body'; } } $classes[] = "clearfix"; return $classes; }
/** * Returns topic type select box (normal/sticky/super sticky) * * @since bbPress (r5059) * * @param $args This function supports these arguments: * - select_id: Select id. Defaults to bbp_stick_topic * - tab: Tabindex * - topic_id: Topic id * - selected: Override the selected option * @uses bbp_get_topic_id() To get the topic id * @uses bbp_is_single_topic() To check if we're viewing a single topic * @uses bbp_is_topic_edit() To check if it is the topic edit page * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky * @uses bbp_is_topic_sticky() To check if the topic is a sticky */ function stachestack_bbp_get_form_topic_type_dropdown($args = '') { // Parse arguments against default values $r = bbp_parse_args($args, array('select_id' => 'bbp_stick_topic', 'tab' => bbp_get_tab_index(), 'topic_id' => 0, 'selected' => false), 'topic_type_select'); // No specific selected value passed if (empty($r['selected'])) { // Post value is passed if (bbp_is_post_request() && isset($_POST[$r['select_id']])) { $r['selected'] = $_POST[$r['select_id']]; // No Post value passed } else { // Edit topic if (bbp_is_single_topic() || bbp_is_topic_edit()) { // Get current topic id $topic_id = bbp_get_topic_id($r['topic_id']); // Topic is super sticky if (bbp_is_topic_super_sticky($topic_id)) { $r['selected'] = 'super'; // Topic is sticky or normal } else { $r['selected'] = bbp_is_topic_sticky($topic_id, false) ? 'stick' : 'unstick'; } } } } // Used variables $tab = !empty($r['tab']) ? ' tabindex="' . (int) $r['tab'] . '"' : ''; // Start an output buffer, we'll finish it after the select loop ob_start(); ?> <select class="form-control" name="<?php echo esc_attr($r['select_id']); ?> " id="<?php echo esc_attr($r['select_id']); ?> _select"<?php echo $tab; ?> > <?php foreach (bbp_get_topic_types() as $key => $label) { ?> <option value="<?php echo esc_attr($key); ?> "<?php selected($key, $r['selected']); ?> ><?php echo esc_html($label); ?> </option> <?php } ?> </select> <?php // Return the results return apply_filters('bbp_get_form_topic_type_dropdown', ob_get_clean(), $r); }
/** * Repairs the relationship of sticky topics to the actual parent forum * * @since 2.3.0 bbPress (r4695) * * @uses wpdb::get_col() To run our recount sql queries * @uses is_wp_error() To check if the executed query returned {@link WP_Error} * @uses bbp_get_forum_post_type() To get the forum post type * @uses get_post_meta() To get the sticky topics * @uses bbp_is_topic_super_sticky() To check if the topic is super sticky * @uses bbp_get_topic_forum_id() To get the topics forum id * @uses update_post_meta To update the topics sticky post meta * @return array An array of the status code and the message */ function bbp_admin_repair_sticky() { // Define variables $bbp_db = bbp_db(); $statement = __('Repairing the sticky topic to the parent forum relationships… %s', 'bbpress'); $result = __('Failed!', 'bbpress'); $forums = $bbp_db->get_col("SELECT ID FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_forum_post_type() . "';"); // Bail if no forums found if (empty($forums) || is_wp_error($forums)) { return array(1, sprintf($statement, $result)); } // Loop through forums and get their sticky topics foreach ($forums as $forum) { $forum_stickies[$forum] = get_post_meta($forum, '_bbp_sticky_topics', true); } // Cleanup unset($forums, $forum); // Loop through each forum with sticky topics foreach ($forum_stickies as $forum_id => $stickies) { // Skip if no stickies if (empty($stickies)) { continue; } // Loop through each sticky topic foreach ($stickies as $id => $topic_id) { // If the topic is not a super sticky, and the forum ID does not // match the topic's forum ID, unset the forum's sticky meta. if (!bbp_is_topic_super_sticky($topic_id) && $forum_id !== bbp_get_topic_forum_id($topic_id)) { unset($forum_stickies[$forum_id][$id]); } } // Get sticky topic ID's, or use empty string $stickers = empty($forum_stickies[$forum_id]) ? '' : array_values($forum_stickies[$forum_id]); // Update the forum's sticky topics meta update_post_meta($forum_id, '_bbp_sticky_topics', $stickers); } // Complete results return array(0, sprintf($statement, __('Complete!', 'bbpress'))); }
/** * Unsticks a topic both from front and it's forum * * @since bbPress (r2754) * * @param int $topic_id Optional. Topic id * @uses bbp_get_topic_id() To get the topic id * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky * @uses bbp_get_topic_forum_id() To get the topic forum id * @uses bbp_get_stickies() To get the forum stickies * @uses do_action() Calls 'bbp_unstick_topic' with the topic id * @uses delete_option() To delete the super stickies option * @uses update_option() To update the super stickies option * @uses delete_post_meta() To delete the forum stickies meta * @uses update_post_meta() To update the forum stickies meta * @uses do_action() Calls 'bbp_unsticked_topic' with the topic id and success * @return bool Always true. */ function bbp_unstick_topic($topic_id = 0) { $topic_id = bbp_get_topic_id($topic_id); $super = bbp_is_topic_super_sticky($topic_id); $forum_id = empty($super) ? bbp_get_topic_forum_id($topic_id) : 0; $stickies = bbp_get_stickies($forum_id); $offset = array_search($topic_id, $stickies); do_action('bbp_unstick_topic', $topic_id); if (empty($stickies)) { $success = true; } elseif (!in_array($topic_id, $stickies)) { $success = true; } elseif (false === $offset) { $success = true; } else { array_splice($stickies, $offset, 1); if (empty($stickies)) { $success = !empty($super) ? delete_option('_bbp_super_sticky_topics') : delete_post_meta($forum_id, '_bbp_sticky_topics'); } else { $success = !empty($super) ? update_option('_bbp_super_sticky_topics', $stickies) : update_post_meta($forum_id, '_bbp_sticky_topics', $stickies); } } do_action('bbp_unsticked_topic', $topic_id, $success); return (bool) $success; }
/** * Displays topic type select box (normal/sticky/super sticky) * * @since bbPress (r2784) * * @param $args This function supports these arguments: * - stick_text: Sticky text * - super_text: Super Sticky text * - unstick_text: Unstick (normal) text * - select_id: Select id. Defaults to bbp_stick_topic * - tab: Tabindex * - topic_id: Topic id * @uses bbp_get_topic_id() To get the topic id * @uses bbp_is_single_topic() To check if we're viewing a single topic * @uses bbp_is_topic_edit() To check if it is the topic edit page * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky * @uses bbp_is_topic_sticky() To check if the topic is a sticky */ function bbp_topic_type_select($args = '') { $defaults = array('unstick_text' => __('Normal', 'bbpress'), 'stick_text' => __('Sticky', 'bbpress'), 'super_text' => __('Super Sticky', 'bbpress'), 'select_id' => 'bbp_stick_topic', 'tab' => bbp_get_tab_index(), 'topic_id' => 0); $r = bbp_parse_args($args, $defaults, 'topic_type_select'); extract($r); // Edit topic if (bbp_is_single_topic() || bbp_is_topic_edit()) { // Get current topic id $topic_id = bbp_get_topic_id($topic_id); // Post value is passed if ('post' == strtolower($_SERVER['REQUEST_METHOD']) && isset($_POST[$select_id])) { $sticky_current = $_POST[$select_id]; // Topic is super sticky } elseif (bbp_is_topic_super_sticky($topic_id)) { $sticky_current = 'super'; // Topic is sticky or normal } else { $sticky_current = bbp_is_topic_sticky($topic_id, false) ? 'stick' : 'unstick'; } // New topic } else { // Post value is passed if ('post' == strtolower($_SERVER['REQUEST_METHOD']) && isset($_POST[$select_id])) { $sticky_current = $_POST[$select_id]; // Default to unstick } else { $sticky_current = 'unstick'; } } // Used variables $tab = !empty($tab) ? ' tabindex="' . $tab . '"' : ''; $select_id = esc_attr($select_id); $sticky_statuses = array('unstick' => $unstick_text, 'stick' => $stick_text, 'super' => $super_text); ?> <select name="<?php echo $select_id; ?> " id="<?php echo $select_id; ?> "<?php echo $tab; ?> > <?php foreach ($sticky_statuses as $sticky_status => $label) { ?> <option value="<?php echo $sticky_status; ?> "<?php selected($sticky_current, $sticky_status); ?> ><?php echo $label; ?> </option> <?php } ?> </select> <?php }
function apoc_topic_header_class($topic_id = 0) { $topic_id = bbp_get_topic_id($topic_id); // Generate some classes $classes = array(); $classes[] = 'page-header-' . rand(1, 6); $classes[] = bbp_is_topic_sticky($topic_id, false) ? 'sticky' : ''; $classes[] = bbp_is_topic_super_sticky($topic_id) ? 'super-sticky' : ''; $classes[] = 'status-' . get_post_status($topic_id); // Output it echo join(' ', $classes); }
* * @package bbPress * @subpackage Theme */ ?> <li class="list-group-item bbp-body bbp-topic-list-group-item"> <ul id="bbp-topic-<?php bbp_topic_id(); ?> " <?php bbp_topic_class(); ?> > <li class="bbp-topic-title"> <?php if (bbp_is_topic_sticky() || bbp_is_topic_super_sticky()) { ?> <span class="pull-left bbp-sticky-icon bbp-topic-icon text-muted"> <span class="glyphicon ipt-icon-pushpin"></span> </span> <?php } elseif (bbp_is_topic_closed()) { ?> <span class="pull-left bbp-sticky-icon bbp-topic-icon text-muted"> <span class="glyphicon ipt-icon-bubbles3"></span> </span> <?php } else { ?> <span class="pull-left bbp-sticky-icon bbp-topic-icon text-muted"> <span class="glyphicon ipt-icon-bubbles4"></span>