Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'code'

Viewing 25 results - 9,351 through 9,375 (of 32,519 total)
  • Author
    Search Results
  • #159111

    In reply to: Add Custom User Roles

    Robin W
    Moderator

    it’s also great when you come back to the code two months later and can’t remember what it does !

    #159110

    In reply to: Add Custom User Roles

    Alice Kaye
    Participant

    You know, I kept seeing that throughout the code and thought that was pretty awesome. I will definitely make use of that! It’s a lot easier and cleaner looking and 9 times out of 10, I don’t need two lines.

    Thank you for the tip! πŸ˜€

    #159109

    In reply to: Add Custom User Roles

    Robin W
    Moderator

    don’t forget you can use

    /* xxx */ or
    //

    to make comments throughout your code

    // only does a single line

    /* this
    does
    multiple lines
    */

    so you can have

    //Add the Artisan role
    $bbp_roles['my_custom_role5'] = array(
    'name' => 'Artisan',
    'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() ) // the same capabilities as keymaster
    );
    // Rename the Moderator role
    $moderator = bbp_get_moderator_role() ;
    $bbp_roles[$moderator] = array(
    'name' => 'Councilman',
    'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() ) // the same capabilities as keymaster
    );
    );
    
    
    #159103

    In reply to: Add Custom User Roles

    Alice Kaye
    Participant

    So, follow-up question to that then…

    Would it have been wrong to modify them to say bbp_craftsman, bbp_journeyman, rather than my-custom-role-1, my-custom-role-2? Does this have some bearing on the code, aside from a name, that I’m not understanding?

    I saw that you had used the original code with my-custom-role-1/2/3/etc, and modified them back to the bbp_name, thinking it was simply just a name. If it’s more than that, I’d love to know.

    #159102

    In reply to: Add Custom User Roles

    Robin W
    Moderator

    Hope I’m grasping that correctly.

    nearly

    I scrapped part 2, then

    what I actually did was take the final three roles form your original part 1 (I moved the participant one down to make it consistent)

    so if you look at the councilman role

    Then where you had

    $bbp_roles['my_custom_role6'] = array(
    'name' => 'Councilman',
    'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() ) // the same capabilities as keymaster
    );
    
    

    This will set a role called my-custom-role-6 to the name and capabilities, and if that role doesn’t exist will create it. WordPress generally doesn’t worry about whether something already exists, if it does it overwrites it, and if it doesn’t it creates it.

    Now I could have simply changed ‘my_custom_roles_6 to bbp_keymaster, and it would have changed the existing role bbp_keymaster name and capabilities to what was in that line

    But for reasons I won’t bore you with, it is better to call a function which gets that role

    hence the new line before

    $keymaster = bbp_get_keymaster_role() ;
    
    

    Then you just use that $keymaster variable set in the line before

    #159101

    In reply to: Add Custom User Roles

    Alice Kaye
    Participant

    It’s really great to know that you’ve learned this much in two years. I have hope for me yet of understanding this!

    What I see that you did was move return $bbp_roles; from the middle of the code, down to the bottom, while also removing the secondary and unnecessary function and filter, keeping only the 'add_custom_role' portion of the function/filter.

    I am definitely curious as to how it’s working without the 'ntwb_bbpress_custom_role_names' filter, for the renaming of the roles? As I write this, I’m not even sure how to explain the question I have. Haha.

    But I thank you for all of your help. You’ve been absolutely fantastic and I appreciate all of the information.

    This was actually a ton of fun, despite my code not working out without your help. As someone who has a deep interest in web design (I do it for a living, without the code-end of things), I think this has fueled me into wanting to learn more about how this works and delve deeper! πŸ˜€

    #159100

    In reply to: Add Custom User Roles

    Robin W
    Moderator

    well worth getting into php if you plan to do customisation, and yes have a look and see if you can work out what I did.

    The key is that a function can only have one ‘return’ command. The WHOLE of the second functioj is one long return command (it starts with it). so I just amended the first one from of creating the final three roles, to calling up the existing roles and then overwriting them

    Have fun, and come back with any queries – it was only two years ago that I wrote my first line of php code, and I only do this very part time!

    #159099

    In reply to: Add Custom User Roles

    Alice Kaye
    Participant

    So basically, am I to understand correctly that you simply removed:

    /* bbPress Custom Role Names */
    add_filter( 'bbp_get_dynamic_roles', 'ntwb_bbpress_custom_role_names' );
    
    function ntwb_bbpress_custom_role_names() {
    	return array(

    Which then left you with one function and one filter, but due to the way the code is written for the base three roles (keymaster, moderator and participants), that code is changing their name, regardless of the function and filter?

    Hope I’m grasping that correctly.

    #159098

    In reply to: Add Custom User Roles

    Alice Kaye
    Participant

    Oh wow, you got that written up fast! I re-wrote my response to you about 10 times while you were modifying that. I’m going to look through and see what you changed, so that I can learn the differences between the two pieces of code.

    Thank you so much for modifying it! I’ll add it now and see how it pans out.

    #159097

    In reply to: Add Custom User Roles

    Alice Kaye
    Participant

    Hi Robin,

    Thank you for that link. It does answer some questions, but presents many more, probably since I don’t have any foundation (personally) in PHP. This is the first time I’ve ever tried to write/modify something in PHP and actually have it work.

    I understand having one filter and one function and that they’re essentially both trying to grab the attention of bbp_get_dynamic_roles if both are present. I also now understand that by trying to merge them, that’s impossible because it needs to be 1 v 1, not 1 v 2. But if I can only have 1 function and 1 filter, I’m then left wondering if this can be written in some way to encompass both things that I’m trying to accomplish.

    #159096
    Robin W
    Moderator

    oops, yes I should code it to go to that, I’ll do an amend !

    #159095

    In reply to: Add Custom User Roles

    Robin W
    Moderator

    ok, so the following combines what the first does with what the second does and achieves what you want

    /* bbPress Custom Roles */
    function add_custom_role( $bbp_roles ) {
     
    
    $bbp_roles['my_custom_role2'] = array(
    'name' => 'Craftsman',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    $bbp_roles['my_custom_role3'] = array(
    'name' => 'Journeyman',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    $bbp_roles['my_custom_role4'] = array(
    'name' => 'Adept',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    $bbp_roles['my_custom_role5'] = array(
    'name' => 'Artisan',
    'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() ) // the same capabilities as keymaster
    );
    $moderator = bbp_get_moderator_role() ;
    $bbp_roles[$moderator] = array(
    'name' => 'Councilman',
    'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() ) // the same capabilities as keymaster
    );
    $keymaster = bbp_get_keymaster_role() ;
    $bbp_roles[$keymaster] = array(
    'name' => 'Advisor',
    'capabilities' => bbp_get_caps_for_role( bbp_get_keymaster_role() ) // the same capabilities as keymaster
    );
    $apprentice = bbp_get_participant_role() ;
    $bbp_roles[$apprentice] = array(
    'name' => 'Apprentice',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    return $bbp_roles;
    }
    add_filter( 'bbp_get_dynamic_roles', 'add_custom_role', 1 );
    #159094

    In reply to: Add Custom User Roles

    Robin W
    Moderator

    ok, quick answers and I’ll come back in a short while

    a filter is a way to alter core code without having to change the core files. In effect if a function on the core is called ‘fred’ and writes the word ‘fred’ to your screen, then (as long as the function author has left the right code in there) you can write a filter to change ‘fred’ to ‘bert’ by adding a function (say a function called Bert) that writes ‘bert’ and then ‘add filter(‘fred’,’bert’) tells the system to ignore the fred function and put in the bert function, so it writes bert.

    Now you have two filters which are overwriting what the core code in ‘bbp_get_dynamic_roles’ does, so in your original code you only had one filter so was fine.

    In your second version, the first filter did the new roles, but the second filter to the same code overwrites the first (thus nullifying it) , so you were just left with the second one working.

    bit like

    original says write Fred
    First filter says write Bert
    Second filter says write Harry

    So the code writes only Harry

    BUT simply combining the two won’t work either as a filter has to return something and only one thing, so the code will quite as soon as it encounters a ‘return’ command.

    Since the first half has ‘return $bbp_roles; ‘ it quits at that point and the second half isn’t exectuted.

    So we need one function with one return and one filter (you actually can have more than one filter, but that’s more advanced!) – I’ll now go and look at it

    see also

    Step by step guide to setting up a bbPress forum – part 5

    #159093

    In reply to: Add Custom User Roles

    Alice Kaye
    Participant

    Okay, so I tried to modify the function, to merge the two and that didn’t work, so I have a few questions:

    From this:

    add_filter( 'bbp_get_dynamic_roles', 'add_custom_role', 1 );
    
    add_filter( 'bbp_get_dynamic_roles', 'ntwb_bbpress_custom_role_names' );

    To this:
    add_filter( 'bbp_get_dynamic_roles', 'add_custom_role', 'ntwb_bbpress_custom_role_names' 1 );

    But that didn’t work at all, wound up immediately getting an error.

    Should I perhaps be placing the renaming of the base three roles, before the creation of the new four roles? The filter for the creation of the roles comes after all of them are created but the filter for the role name change comes before the changes, so I wonder if the two filters would still conflict if I moved them around?

    These are really newbie questions, I know, but I am not 100% sure as to how to change these to work in tandem.

    Thanks in advance for any help you can provide!

    #159091

    In reply to: Add Custom User Roles

    Alice Kaye
    Participant

    Hi Robin,

    Thanks for replying and pointing out the issue for me. Woot! I see the two filters, in post 2. I’ll try to merge the two filters together, remove the second filter entirely and hopefully with the merge, it will work the way I’m intending. (This is literally the first time I’ve ever tried my hand at understanding PHP, so I’m totally new to this).

    The first bit of code (post 1) is simply just making new roles entirely.

    Post 2 is what I need to have. I want to change the name of the main three roles, and then add the others. Reason being, for starters, I think it will confuse my users to have those three the we won’t use, and I can’t seem to change my admit account from Keymaster to one I create.

    Thanks so much! πŸ™‚

    #159088

    In reply to: Add Custom User Roles

    Robin W
    Moderator

    there are two filters in the second example, and the second one wipes out the first !

    I tried your original code and it works fine, suggest you post it back and try it again, you may just have missed a character in the copy/paste.

    #159083
    Robkk
    Moderator

    @atlantis1525

    on the backend of wordpress you can see a menu item called toward the bottom-left called settings, from there , there is more settings for things like discussion , writing , and permalinks.

    here is what it looks like

    https://codex.wordpress.org/Settings_Permalinks_Screen

    #159082
    Robkk
    Moderator

    @jaydd

    was bbPress working fine for awhile then this error came out of nowhere??

    did this error come after you imported forums into bbPress??

    do you have a large number of topics/replies??

    have you followed these two guides for developing your child theme for bbPress??

    https://codex.bbpress.org/theme-compatibility/getting-started-in-modifying-the-main-bbpress-template/
    https://codex.bbpress.org/theme-compatibility/

    are your permalinks set to post-name??

    also could you paste an example url of the original topic url and the url you get when you have a 404 error.

    #159081
    Robkk
    Moderator

    i think you can bring information from another page using an iframe , which some lightbox scripts could use. Or you could just hide it with inline CSS then whenever the button/link with the class/id used for the lightbox is clicked it would display whatever you hid.

    you could use the shortcode like i said , because i think there is some modal popup form plugins that could just make life easier and you could input that shortcode and maybe place a template tag/use a shortcode in the template to show the popup for the reply form.

    you could use <?php bbp_get_template_part( β€˜form’, β€˜reply’ ); ?> in a template then configure your lightbox/popup code around that but you also need the PHP if statments so it doesnt show it to all users logged in or not.

    other then what i sorta told you its still custom development , and you would need to hire a custom developer.

    if you do have some ideas on what to use or code that you have been using but are quite not there you can try posting it and see if i can find some other information to help you or another developer from here can pick this up.

    #159079

    In reply to: Add Custom User Roles

    Alice Kaye
    Participant

    Secondary Update:

    After making aforementioned changes, while I was able to change the name of the three major roles (Keymaster > Advisor, Moderator > Councilman, Participant > Apprentice), I’ve found that the newly added roles are no longer operational (nor showing).

    Screenshot: http://screencast.com/t/p28WJahSY4NU

    Can someone please take a look at my code and maybe provide some insight as to where I have gone wrong?

    Thanks in advance!

    Edit: I have tried modifying the newly added roles to the following:

    From:

    $bbp_roles['bbp_craftsman'] = array(
    'name' => 'Craftsman',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );

    To:

    $bbp_roles['bbp_craftsman'] = array(
    'name' => 'Craftsman',
    'capabilities' => bbp_get_caps_for_role( bbp_get_apprentice_role() ) // the same capabilities as participants
    );

    Which gave me immediate errors after re-uploading the function.php. If I leave it as is, I do not get any errors, they just simply don’t show.

    #159078

    In reply to: Add Custom User Roles

    Alice Kaye
    Participant

    Update – I managed to get it to work and managed to change the name of the defaults, to make things easier.

    This is the code in case anyone needs it for reference in the future:

    /* bbPress Custom Roles */
    function add_custom_role( $bbp_roles ) {
     
    $bbp_roles['bbp_craftsman'] = array(
    'name' => 'Craftsman',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    $bbp_roles['bbp_journeyman'] = array(
    'name' => 'Journeyman',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    $bbp_roles['bbp_adept'] = array(
    'name' => 'Adept',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    $bbp_roles['bbp_artisan'] = array(
    'name' => 'Artisan',
    'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() ) // the same capabilities as moderator
    );
    return $bbp_roles;
    }
    add_filter( 'bbp_get_dynamic_roles', 'add_custom_role', 1 );
    /* bbPress Custom Roles */
    
    /* bbPress Custom Role Names */
    add_filter( 'bbp_get_dynamic_roles', 'ntwb_bbpress_custom_role_names' );
    
    function ntwb_bbpress_custom_role_names() {
    	return array(
    
    		// Keymaster - Advisor
    		bbp_get_keymaster_role() => array(
    			'name'         => 'Advisor',
    			'capabilities' => bbp_get_caps_for_role( bbp_get_keymaster_role() )
    		),
    
    		// Moderator - Moderator
    		bbp_get_moderator_role() => array(
    			'name'         => 'Councilman',
    			'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() )
    		),
    
    		// Participant - Apprentice
    		bbp_get_participant_role() => array(
    			'name'         => 'Apprentice',
    			'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() )
    		),
    	);
    }
    /* bbPress Custom Role Names */
    #159077
    eVersatile
    Participant

    Makes since, but since it needs to be auto generated it needs to be php script within the template. Isn’t working out so well so far.
    What about if the form was on a different page with the shortcode, is there a way to show only the forums that the current user created in the dropdown menu?

    #159076
    Alice Kaye
    Participant

    Hi everyone,

    I’m working on creating some custom user roles and I was wondering if I could get assistance with it, because the code I modified kind of killed my site (so I took it out and it’s working fine again).

    I’m running a guild website, so we have specific titles (in order from left to right for hierarchy):
    Advisor (Keymaster) > Councilman (Moderator) > Artisan (Moderator) > Adept (Participant) > Journeyman (Participant) > Craftsman (Participant) > Apprentice (Participant)

    I was trying to follow this guide: http://codex.bbpress.org/custom-capabilities/

    /* bbPress Custom Roles */
    function add_custom_role( $bbp_roles ) {
     
    $bbp_roles['my_custom_role1'] = array(
    'name' => 'Apprentice',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    $bbp_roles['my_custom_role2'] = array(
    'name' => 'Craftsman',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    $bbp_roles['my_custom_role3'] = array(
    'name' => 'Journeyman',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    $bbp_roles['my_custom_role4'] = array(
    'name' => 'Adept',
    'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
    );
    $bbp_roles['my_custom_role5'] = array(
    'name' => 'Artisan',
    'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() ) // the same capabilities as keymaster
    );
    $bbp_roles['my_custom_role6'] = array(
    'name' => 'Councilman',
    'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() ) // the same capabilities as keymaster
    );
    $bbp_roles['my_custom_role7'] = array(
    'name' => 'Advisor',
    'capabilities' => bbp_get_caps_for_role( bbp_get_keymaster_role() ) // the same capabilities as keymaster
    );
    return $bbp_roles;
    }
    add_filter( 'bbp_get_dynamic_roles', 'add_custom_role', 1 );
    /* bbPress Custom Roles */

    Can someone tell me where I might have gone wrong?

    Thanks in advance! πŸ˜€

    #159074
    Robin W
    Moderator

    ok, try

    https://wordpress.org/plugins/widget-logic/

    use

    is_bbpress()where you want a widget displayed on bbpress pages and
    !is_bbpress() where you don’t

    #159039
    Robin W
    Moderator

    ok,

    1. not possible with bbpress as far as I know
    2. only admin/keymasters get this priviledge
    3. https://codex.buddypress.org/getting-started/installing-group-and-sitewide-forums/
    4. If I understand the question correctly, normal users – that is the default ie participants can create topics and replies, but not forums or categories. If you meant something different then come back

Viewing 25 results - 9,351 through 9,375 (of 32,519 total)
Skip to toolbar