Skip to:
Content
Pages
Categories
Search
Top
Bottom

Subscribe to all forums button

Published on October 27th, 2021 by lumisdev

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');

Forum layout

Published on October 26th, 2021 by robert-s

We would like to get a forum layout on our website almost exactly how the forums are laid out here on bbpress.org/forums

Does bbpress offer this? if not, how would I go about this?

Thanks!

Forum category not shown

Published on October 26th, 2021 by mariaat

Hello, does anyone know why the forum category is not shown? I see only topics. Many thanks if you can help me out on this

Thumbs up and down

Published on October 25th, 2021 by gnfb

I am desperately searching for a forum that has the ability to rate threads. The forum will be for promo codes and I want users to have the abilty to ad a yes working or no working comment by way of thumbs. so if one had 10 down thumbs and no up thumbs dont bother!
Is there such an abilty by way of a plugin? I cant aford the hundreds to have code written to do the job (sorry coders)

Real age verification access control?

Published on October 25th, 2021 by Tobias Claren

Hello.
Is there a real age verification for the forums?
So not just “Are you 18?”, but a control via an ID, etc..
The less work for the operator, the better.
So e.g. depending on the country automated age controls.
E.g. via the number of the state “identity card”, as it exists in many countries.
But also the least possible effort for the user.

Embedded images

Published on October 25th, 2021 by Chuckie

I have become acustomed to simply pasting a IMGUR link in my posts to emded an inline image. But now they show a warning and it has to be viewed by clicking a link. Can’t that be improved?

Child theme/ php template files

Published on October 24th, 2021 by Jan

Hi there,

I understand from this threat that the layout of search results or topic-tag pages can be customized based on the template files stored in the bbpress/templates/default/bbpress folder.

In order to retain the customization during updates of the bbpress plugin, I have created the same folder structure inside the directory of my child theme (see screenshot).

The only change I’d like to make is for the topic-tag page to look exactly like the search-result page (see screenshot) –> list of forum threats in full length rather than list of titles only.

In order to realize that I need to…

1) copy a ?-search.php file from the plugin directory into the respective subfolder of the child theme and
2) rename it into a ?-topic-tag.php file.

Is this correct? If so, which ?-search and ?-topic-tag file do I need to consider?

Many thanks for your support in advance.

Best regards,
Jan

can I make the UI cleaner for creating topics?

Published on October 24th, 2021 by midnightbangs

I was wondering if it is possible to change how the stuff in the red outline box looks like. Their are many users that have no idea what any of it means and want to make sure I keep it clean for them. Is their a way to edit what is shown.

View post on imgur.com

Cannot upload images into new forums

Published on October 23rd, 2021 by hislordshipuk

Hi – I have hit an issue where, despite roles, users cannot upload images into a new group/forum that I have created. The system accepts the image upload but does not display it. If you click on edit the image shows, and when you come off edit the image appears where it should.
This does not happen when I attempt upload to older forums on the site, all is well there.
Any ideas?

Make links short

Published on October 23rd, 2021 by ABDURHMAN

Good night …
How are you doing
How to convert forum links to digital links
https://www.xxxx.net/forums/forum/development-updates/
to :
https://www.xxxx.net/forums/forum/5

Skip to toolbar