Search Results for 'code'
-
Search Results
-
Hello everyone!
I’m a new user of bbpress and I’m looking for a way for logged in users to subscribe/unsubscribe to all forums by clicking a button.
I’ve managed to do it by myself, but I’d like to know if there is an easier way to do it.
Here is the code in my loop-forums.php file:
<?php /** * Forums Loop * * @package bbPress * @subpackage Theme */ // Exit if accessed directly defined('ABSPATH') || exit; do_action('bbp_template_before_forums_loop'); ?> <?php $current_user = get_userdata(get_current_user_id()); if (isset($current_user) && $current_user->ID > 0) : $user_subscribed_forum_ids = bbp_get_user_subscribed_forum_ids($current_user->ID); $forum_ids_list = array(); while (bbp_forums()) : bbp_the_forum(); if (bbp_get_forum_type() === 'category') : foreach (bbp_forum_get_subforums() as $subforum) : $forum_ids_list[] = $subforum->ID; endforeach; else : $forum_ids_list[] = bbp_get_forum_id(); endif; endwhile; $check = sizeof($forum_ids_list) === sizeof($user_subscribed_forum_ids); $bbp_action = $check ? "bbp_unsubscribe" : 'bbp_subscribe'; $label = $check ? "Unsubscribe of all forums" : "Subscribe of all forums"; $label .= bbp_get_forum_type() === 'category' ? " of this category" : ""; if (isset($_POST) && $_POST['action']) : foreach ($forum_ids_list as $forum_id) : $q_args = array( 'action' => $bbp_action, 'object_id' => $forum_id, 'object_type' => 'post' ); $permalink = bbp_get_forum_permalink($forum_id); $wp_nonce_url = esc_url(wp_nonce_url(add_query_arg($q_args), 'toggle-subscription_' . $forum_id)); $wp_nonce_url = substr($wp_nonce_url, strlen('/')); $url = html_entity_decode($permalink . $wp_nonce_url); $ch = curl_init($url); curl_setopt($ch, CURLOPT_COOKIE, LOGGED_IN_COOKIE . '=' . $_COOKIE[LOGGED_IN_COOKIE]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $response = curl_exec($ch); curl_close($ch); endforeach; $user_subscribed_forum_ids = bbp_get_user_subscribed_forum_ids($current_user->ID); $check = sizeof($forum_ids_list) === sizeof($user_subscribed_forum_ids); $bbp_action = $check ? "bbp_unsubscribe" : 'bbp_subscribe'; $label = $check ? "Unsubscribe of all forums" : "Subscribe of all forums"; $label .= bbp_get_forum_type() === 'category' ? " of this category" : ""; endif; // isset($_POST) && $_POST['action'] endif; // isset($current_user) && $current_user->ID > 0 ?> <?php if (isset($_POST) && $_POST['action']) : ?> <script id="prevent-form-resubmission-when-page-is-refreshed" type="text/javascript"> // source: https://stackoverflow.com/questions/6320113/how-to-prevent-form-resubmission-when-page-is-refreshed-f5-ctrlr if (window.history.replaceState) { window.history.replaceState(null, null, window.location.href); document.getElementById('prevent-form-resubmission-when-page-is-refreshed').remove(); } </script> <?php endif; ?> <?php if (isset($current_user) && $current_user->ID > 0 && !bbp_is_single_user()) : ?> <form action="" method="POST"> <input type="hidden" name="action" value="<?= $bbp_action ?>"> <button type="submit" style="color: black;"><?= __($label, 'ls') ?></button> </form> <?php endif; ?> <table id="forums-list-<?php bbp_forum_id(); ?>" class="table table-bordered forums-list"> <thead> <tr> <th class="forum-title-column"> <?php esc_html_e('Forum', 'ls'); ?> </th> <th class="posts-count-column"> <?php bbp_show_lead_topic() ? esc_html_e('Replies', 'ls') : esc_html_e('Posts', 'ls'); ?> </th> <th class="last-post-column"> <?php esc_html_e('Last Post', 'ls'); ?> </th> </tr> </thead> <tbody> <?php while (bbp_forums()) : bbp_the_forum(); ?> <?php bbp_get_template_part('loop', 'single-forum'); ?> <?php endwhile; ?> </tbody> </table> <?php do_action('bbp_template_after_forums_loop');
Topic: Thumbs up and down
Topic: Force Sticky Post Order
Hello, this is a request I have to force the order of two sticky posts so that they don’t change when a new comment is added.
Sticky 1
Sticky 2Sticky 2 will move above Sticky one with a new comment, and vice-versa.
Any way in the code to force that sticky order to stay the same all the time.
Thanks in advance.
Topic: Creating new custom role
It seems to be a real struggle to create a new custom role for bbpress ๐
I’ve been trying out all the different solutions I’ve found online but nothing is working.
All I want to do is to be able to assign the role of Naturopath to some of my forum participants. They would have the same capabilities as the Participant role, just have Naturopath instead of Participant showing under their name in the Forum. The rest of the Participants can continue to show “Participant”.
Can anyone here maybe write the code for me as a paid job?
I have WP 5.8.1
bPress 2.6.6