Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'code'

Viewing 25 results - 5,576 through 5,600 (of 32,518 total)
  • Author
    Search Results
  • #180673
    Robin W
    Moderator

    it seems from this trac ticket that even if you have the correct code, it doesn’t work, and won’t until 2.6 is released.

    #180665

    In reply to: Form to forum

    Barry
    Participant

    Well, if you’re building on my example code you could make a few changes in order to get the information flowing back to the success message:

    # Find this line
    bbp_insert_topic( /* ... */ );
    
    # Change it: let's catch the post ID
    $topic_id = bbp_insert_topic( /* ... */ );
    
    # Find this line
    post_to_bbp_status( 'success' );
    
    # Change it: let's pass the post ID instead of 'success'
    post_to_bbp_status( $topic_id );
    
    # Find this condition
    if ( 'success' === post_to_bbp_status() )
    
    # Change it: test to see if it contains a post ID
    if ( is_numeric( post_to_bbp_status() ) )
    
    # Find the line
    return 'Thank you for your submission.';
    
    # Change it: display the new topic's permalink
    return 'Check your post: ' . get_permalink( post_to_bbp_status() );

    Note that these changes are untested, they don’t do any safety checks etc etc. However, I hope it gives you some ideas you can use to further develop your own solution 🙂

    #180659
    sally
    Participant

    Hello,

    thx for the reply.


    @Robin

    I corrected the code on Line 1, but as Participant i still cannot Trash own Posts / Topics. Role has only Edit / Reply available…


    @Pascal

    Is there already an estimated date, when the Version 2.6 will be released?

    Thx
    Regards
    Sally

    #180648
    wautersandreas
    Participant

    I’ve now gotten my forum to work by commenting the entire thing and putting

    function bbp_pre_get_posts_normalize_forum_visibility( $posts_query = null ) {
        return;
    }

    would this have fatal influences on other aspects?

    #180647
    wautersandreas
    Participant

    Hi, i had a big problem with bbpress in the sense that it crashed (fatal error) every time i tried to administrate it by clicking the “forums” tab.

    I found out that the below function was the problem, and in particular that i needed to change to:
    $post_stati = bbp_get_public_status_id();
    from
    $post_stati[] = bbp_get_public_status_id();

    for some reason the straight brackets broke everything, i don’t understand why, so i wanted to flag this for future updates. i’m a complete newb so yeah 😀

    error code:

    Fatal error: Uncaught Error: [] operator not supported for strings in /customers/f/9/9/simzone.net/httpd.www/HQ/wp-content/plugins/bbpress/includes/forums/functions.php:1800 Stack trace: #0 /customers/f/9/9/simzone.net/httpd.www/HQ/wp-includes/class-wp-hook.php(298): bbp_pre_get_posts_normalize_forum_visibility(Object(WP_Query)) #1 /customers/f/9/9/simzone.net/httpd.www/HQ/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters('', Array) #2 /customers/f/9/9/simzone.net/httpd.www/HQ/wp-includes/plugin.php(515): WP_Hook->do_action(Array) #3 /customers/f/9/9/simzone.net/httpd.www/HQ/wp-includes/class-wp-query.php(1681): do_action_ref_array('pre_get_posts', Array) #4 /customers/f/9/9/simzone.net/httpd.www/HQ/wp-includes/class-wp-query.php(3238): WP_Query->get_posts() #5 /customers/f/9/9/simzone.net/httpd.www/HQ/wp-includes/class-wp.php(617): WP_Query->query(Array) #6 /customers/f/9/9/simzone.net/httpd.www/HQ/wp-includes/class-wp.php(735): WP->query_posts() #7 /customers/f/9/9/simzone.net/httpd.www/HQ/wp-includes/functions in /customers/f/9/9/simzone.net/httpd.www/HQ/wp-content/plugins/bbpress/includes/forums/functions.php on line 1800'
    
    adjusted function: 
    
    

    function bbp_pre_get_posts_normalize_forum_visibility( $posts_query = null ) {

    // Bail if all forums are explicitly allowed
    if ( true === apply_filters( ‘bbp_include_all_forums’, false, $posts_query ) ) {
    return;
    }

    // Bail if $posts_query is not an object or of incorrect class
    if ( !is_object( $posts_query ) || !is_a( $posts_query, ‘WP_Query’ ) ) {
    return;
    }

    // Get query post types array .
    $post_types = (array) $posts_query->get( ‘post_type’ );

    // Forums
    if ( bbp_get_forum_post_type() === implode( ”, $post_types ) ) {

    // Prevent accidental wp-admin post_row override
    if ( is_admin() && isset( $_REQUEST[‘post_status’] ) ) {
    return;
    }

    /** Default ***********************************************************/

    // Get any existing post status
    $post_stati = $posts_query->get( ‘post_status’ );

    // Default to public status
    if ( empty( $post_stati ) ) {
    $post_stati = bbp_get_public_status_id();
    # $post_stati[] = bbp_get_public_status_id();

    // Split the status string
    } elseif ( is_string( $post_stati ) ) {
    $post_stati = explode( ‘,’, $post_stati );
    }

    /** Private ***********************************************************/

    // Remove bbp_get_private_status_id() if user is not capable
    if ( ! current_user_can( ‘read_private_forums’ ) ) {
    $key = array_search( bbp_get_private_status_id(), $post_stati );
    if ( !empty( $key ) ) {
    unset( $post_stati[$key] );
    }

    // …or add it if they are
    } else {
    $post_stati = bbp_get_private_status_id();
    #$post_stati[] = bbp_get_private_status_id();
    }

    /** Hidden ************************************************************/

    // Remove bbp_get_hidden_status_id() if user is not capable
    if ( ! current_user_can( ‘read_hidden_forums’ ) ) {
    $key = array_search( bbp_get_hidden_status_id(), $post_stati );
    if ( !empty( $key ) ) {
    unset( $post_stati[$key] );
    }

    // …or add it if they are
    } else {
    $post_stati = bbp_get_hidden_status_id();
    #$post_stati[] = bbp_get_hidden_status_id();
    }

    // Add the statuses
    $posts_query->set( ‘post_status’, array_unique( array_filter( $post_stati ) ) );
    }

    // Topics Or Replies
    if ( array_intersect( array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ), $post_types ) ) {

    // Get forums to exclude
    $forum_ids = bbp_exclude_forum_ids( ‘meta_query’ );

    // Bail if no forums to exclude
    if ( ! array_filter( $forum_ids ) ) {
    return;
    }

    // Get any existing meta queries
    $meta_query = $posts_query->get( ‘meta_query’ );

    // Add our meta query to existing
    $meta_query[] = $forum_ids;

    // Set the meta_query var
    $posts_query->set( ‘meta_query’, $meta_query );
    }
    }

    /**
    * Returns the forum’s topic ids
    *
    * Only topics with published and closed statuses are returned
    *
    * @since bbPress (r2908)
    *
    * @param int $forum_id Forum id
    * @uses bbp_get_topic_post_type() To get the topic post type
    * @uses bbp_get_public_child_ids() To get the topic ids
    * @uses apply_filters() Calls ‘bbp_forum_query_topic_ids’ with the topic ids
    * and forum id
    */’

    #180642
    Robin W
    Moderator

    I presume it is not as simple as changing

    /*Customize the BBPress roles to allow Participants to trash topics
    

    to

    /*Customize the BBPress roles to allow Participants to trash topics */

    on line 1, as currently the lack of a */ at the end of the line means that it just comments out all of your first function, so that function doesn’t run !

    #180640
    endomorph
    Participant

    Hi all,

    Got something I am stumpeped on. I have a site, with a child theme and I have installed BBPress.

    Created the bbpress.php template page. All pages on the forum work fine apart from the view topic page. It just outputs the content of BBpress with no theme code.

    If I switch to a parent theme, it ll works OK, it’s only happening on a child theme

    Any ideas ?

    #180639

    In reply to: New topics

    Robin W
    Moderator

    not available in bbpress, so would require code, so might as well be a plugin !

    #180632

    In reply to: Form to forum

    Barry
    Participant

    I’m sure you could do that pretty easily.

    If a call to bbp_insert_topic() is successful it returns the post ID of the newly created topic. You can in turn pass that to get_permalink() which will provide you with the URL.

    get_permalink()

    #180625
    Barry
    Participant

    Forums, topics and replies live in the posts table (typically wp_posts but the prefix might be different in your case). Something like this may help:

    UPDATE wp_posts
    SET    post_author = 1
    WHERE  post_author = 0
    AND    post_type IN ( 'reply', 'topic' )

    Essentially it finds all replies and topics where the author ID is zero and updates them to be associated with some other user (I used user ID 1 in my example, obviously modify to suit).

    #180623

    In reply to: Form to forum

    Barry
    Participant

    There is of course the [bbp-topic-form] shortcode that ships with bbPress itself … but if that’s unsuitable or if customizing it to meet your goals isn’t an option for any reason, then you could roll your own solution quite easily.

    Here is a (super simple) example of just that – it creates an extremely simple (single field!) form via the [post_to_bbp] shortcode and uses the submitted data to create a new forum topic. Of course, there is a great deal it doesn’t do that you’d probably want in place before using it in production, but it’s just an example after all 🙂

    #180618
    sally
    Participant

    Hi,

    I’m working on WP 4.7.1 and BBPress Version 2.5.12. I would like to allow Participants to Trash there own Topics and Posts. I found the following code here in the Forum and added it to my functions.php. When i register as Participant and create a new Topic I have only EDIT / REPLY available, but not TRASH.

    
    /*Customize the BBPress roles to allow Participants to trash topics
    add_filter( 'bbp_get_caps_for_role', 'ST_add_role_caps_filter', 10, 2 );
    
    function ST_add_role_caps_filter( $caps, $role ){
        // Only filter for roles we are interested in!
        if( $role == 'bbp_participant' ) {
    
    	$new_caps = array(
                    // Primary caps
                    'spectate'              => true,
                    'participate'           => true,
                    'moderate'              => false,
                    'throttle'              => false,
                    'view_trash'            => false,
    
                    // Forum caps
                    'publish_forums'        => false,
                    'edit_forums'           => false,
                    'edit_others_forums'    => false,
                    'delete_forums'         => false,
                    'delete_others_forums'  => false,
                    'read_private_forums'   => false,
                    'read_hidden_forums'    => false,
    
                    // Topic caps
                    'publish_topics'        => true,
                    'edit_topics'           => true,
                    'edit_others_topics'    => false,
                    'delete_topics'         => true,
                    'delete_others_topics'  => false,
                    'read_private_topics'   => false,
    
                    // Reply caps
                    'publish_replies'       => true,
                    'edit_replies'          => true,
                    'edit_others_replies'   => false,
                    'delete_replies'        => true,
                    'delete_others_replies' => false,
                    'read_private_replies'  => false,
    
                    // Topic tag caps
                    'manage_topic_tags'     => false,
                    'edit_topic_tags'       => false,
                    'delete_topic_tags'     => false,
                    'assign_topic_tags'     => true,
                );	
    
    	}
    
        return $new_caps;
    }
    /*Fixes an issue that only allows mods to trash topics.
    bbpress.trac.wordpress.org/changeset/5852
    bbpress.trac.wordpress.org/ticket/2685*/
    
    add_filter( 'bbp_map_reply_meta_caps', 'ST_tweak_trash_meta_caps', 11, 4 );
    add_filter( 'bbp_map_topic_meta_caps', 'ST_tweak_trash_meta_caps', 11, 4 );
    
    // tweak for replies
    function ST_tweak_trash_meta_caps( $caps, $cap, $user_id, $args ){
    
    	// apply only to delete_reply and delete_topic
    	if ( $cap == "delete_reply" || $cap == "delete_topic" ){
    		// Get the post
    		$_post = get_post( $args[0] );
    		if ( !empty( $_post ) ) {
    
    			// Get caps for post type object
    			$post_type = get_post_type_object( $_post->post_type );
    			$caps      = array();
    
    			// Add 'do_not_allow' cap if user is spam or deleted
    			if ( bbp_is_user_inactive( $user_id ) ) {
    				$caps[] = 'do_not_allow';
    
    			// Moderators can always edit forum content
    			} elseif ( user_can( $user_id, 'moderate' ) ) {
    				$caps[] = 'moderate';
    
    			// User is author so allow edit if not in admin
                } elseif ( ! is_admin() && ( (int) $user_id === (int) $_post->post_author ) ) {
                    $caps[] = $post_type->cap->delete_posts;
    
    			// Unknown so map to delete_others_posts
    			} else {
    				$caps[] = $post_type->cap->delete_others_posts;
    			}
    		}
    
    	}
    	// return the capabilities
    	return $caps;
    }
    
    

    Can someone help me with this, or has a other code snippet what is working?

    Thx
    Sally

    #180615
    sally
    Participant

    Hi Robin,

    thanks, the last Code works

    Regards
    Sally

    #180603

    In reply to: Background Color

    Robin W
    Moderator

    the code is still in your site !

    Then I’d suggest you contact your theme author who is controlling this code and ask them for help.

    Otherwise beyond my free help to work out all the code you would need.

    #180602

    In reply to: Background Color

    Robin W
    Moderator

    deleting the code will return it – close and re-open your browser to get the css to take effect

    #180601

    In reply to: Background Color

    scottwiggins17
    Participant

    that code changed all my background color for my blog and pages black when it used to be white. Now I cant see anything and deleting the code did not set it back to normal. What do I do to get my site back to the way it was?

    I use X theme and now it’s all messed up. It has black background with black font on ALL my blog posts.

    For now I changed my whole sites default background to white, the header white, and the header menu font to black so you can read it. It was the opposite, and I like the black header background better the way I had it. I don’t know what that code did, but it messed a lot of stuff up.

    #180600

    In reply to: Background Color

    scottwiggins17
    Participant

    That worked except one problem:/ It turned my main menu bar for my site white as well, turned all the background on my site to black in every area including my blog which I need to be a white background.

    I don’t want the code to override everything, JUST my forum background.

    Thanks

    #180597
    Robin W
    Moderator

    ah, found out what I have done wrong

    can you change the code to

    add_action ('bbp_theme_after_reply_author_details', 'rew_display_date');
    add_action ('bbp_theme_after_topic_author_details', 'rew_display_date'); 
    
    function rew_display_date () {
    	?>
    	<span class="bss-reply-post-date"><?php bbp_reply_post_date(); ?></span>
    	<?php
    }
    #180592
    sally
    Participant

    Hello,

    the first code to hide the bbp-topic-post-date works. Adding the second code to the functions.php and checking the topics / reply the bbp-topic-post-date is nowhere visible..

    What else can i try?

    #180591
    bjorngus
    Participant

    I copied the code from the bbpress template and it worked perfect. Thanks!

    #180590
    bjorngus
    Participant

    Oh thanks great. My bbpress version was edited so that button is not added to the form. But i guess i have to add it with some code. Thanks

    #180548
    Barry
    Participant

    Additionally, as an example of how you can add pretty much anything you want to the JSON responses returned by the REST API:

    function bbpress_rest_api_replies_extra_data( WP_REST_Response $response ) {
    	if ( ! is_array( $response->data ) ) {
    		return $response;
    	}
    
    	foreach ( $response->data as $key => $single_item ) {
    		// Only modify replies
    		if ( bbp_get_reply_post_type() !== $single_item['type'] ) {
    			continue;
    		}
    
    		// Add the author's details using a custom format
    		$author_id = get_post( $single_item['id'] )->post_author;
    		$author = get_user_by( 'ID', $author_id );
    		$response->data[ $key ]['author'] = "{$author->display_name} <{$author->user_email}>";
    	}
    
    	return $response;
    }
    
    add_filter( 'rest_request_after_callbacks', 'bbpress_rest_api_replies_extra_data' );

    You could say this is a bit of a brute force hack and although when combined with my last snippet it successfully adds the author’s display name and email address to replies (not topics), it shouldn’t really be used for that purpose “as is”: it doesn’t escape the author details, you probably don’t want to expose their email addresses, plus it’s out of alignment with how author meta is returned for other post types … However, I felt it was worth sharing an example of how you can quite quickly add arbitrary fields to REST API output.

    #180547
    Barry
    Participant

    What do you know, it worked!

    So getting back to business – thanks for catching that error in my earlier snippet, Robin. I think yours is perfectly fine (also, great links re adding author meta) but just to ‘close the circle’ on my own snippet, here’s a revision:

    function bbpress_enable_rest_api() {
    	$types = array(
    		bbp_get_reply_post_type(),
    		bbp_get_forum_post_type(),
    		bbp_get_topic_post_type(),
    	);
    
    	foreach ( $types as $slug ) {
    		$definition = (array) get_post_type_object( $slug );
    		$definition['show_in_rest'] = true;
    		$definition['rest_controller_class'] = 'WP_REST_Posts_Controller';
    		register_post_type( $slug, $definition );
    	}
    }
    
    add_action( 'bbp_register_post_types', 'bbpress_enable_rest_api', 11 );
    #180524
    Robin W
    Moderator

    to hide the date at the top, put this in your css

    .bbp-reply-post-date {
      display: none;
    }

    Then to add to the list add this to your functions file

    add_action ('bbp_theme_after_reply_author_details', 'rew_display_date');
    add_action ('bbp_theme_after_topic_author_details', 'rew_display_date'); 
    
    function rew_display_date () {
    	?>
    	<span class="bbp-reply-post-date"><?php bbp_reply_post_date(); ?></span>
    	<?php
    }
    
    #180519
    Robin W
    Moderator

    whilst in the forums list a sub private forum will not show, if the sub forum is set to public, then searches would show as the forum it belongs to is private.

    So set every forum that you wish to be private to Private

    If you don’t want the word private to appear – and I hate it showing! – then you can add this to your functions file

    add_filter('private_title_format', 'ntwb_remove_private_title');
    function ntwb_remove_private_title($title) {
    	return '%s';
    }

    or add my plugin which has this and many other features

    https://wordpress.org/plugins/bbp-style-pack/

    and set this to hide in
    dashboard>settings>bbp style pack>forum display item 4

Viewing 25 results - 5,576 through 5,600 (of 32,518 total)
Skip to toolbar