Search

bbPress Showcase » bbpress bbPress Chat

two question about bb_press functions

RSS

Tags:


  1. agl666
    agl666

    member
    Joined: Aug '08
    Posts: 50

    offline

    Hi! Recently I've started writing my owm plugin for customizing my forum. It's about adding some new extra personal info. Adding new meta of course is very simple. But I want to make input form with autocomplete (like in Google Suggest, or everywhere last time). So that's my problems:

    • How can I register new jQuery plugin and print them on profile page? Last night I've spent about two hours to solve this problem. (ps. I'm totally newbie in js frameworks, but I've done everything (e.g. using jQuery function) but linking scripts)
    • How can I get all usermeta records form key (mysql query would be something like that: SELECT meta_value FROM bb_usermeta WHERE meta_key = 'university' GROUP BY meta_value) using bb_press's functions? I've have no ideas except get all user_id's and $user->university. But if keep doing like this, make own query is simpler way

    Best wishes,
    Aglyamzanov Ramil

    Posted 3 months ago #
  2. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 330

    online

    I avoid jquery when possible because it's huge and bloated, therefore I have little experience with it, though I know javascript fairly well.

    (The best way to learn how to make bbPress plugins is to find a similar plugin and take it apart to see how it works)

    Jquery is already included with bbPress, I think you can get it to load with bb_enqueue_script or just doing a direct write with bb_head ie. make a function that prints out the external javascript link and then do_action('bb_head','your_header_function');

    As far as db calls, that's easy with bbPress, it's just like wordpress too.

    $results=$bbdb->get_results("SELECT meta_value FROM $bbdb->usermeta WHERE meta_key = 'university' GROUP BY meta_value");
    This is a demo of the bbPress Signatures plugin!
    If you use my plugins, please considering donating to help continue their development.
    Posted 3 months ago #
  3. agl666
    agl666

    member
    Joined: Aug '08
    Posts: 50

    offline

    Thaks a lot

    Given db call returns

    Fatal error: Call to a member function get_results() on a non-object

    Posted 3 months ago #
  4. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 330

    online

    Oh sorry. It was just example code.

    You have to do a global $bbdb; before you do any db calls in a function
    since $bbdb is a class outside of the function.

    Posted 3 months ago #
  5. agl666
    agl666

    member
    Joined: Aug '08
    Posts: 50

    offline

    oh, sorry

    one more question:

    As you said,

    Jquery is already included with bbPress, I think you can get it to load with bb_enqueue_script or just doing a direct write with bb_head ie. make a function that prints out the external javascript link and then do_action('bb_head','your_header_function');

    but when doing bb_enqueue_script() nothing happens (maybe I use wrong parameters). When trying outside the function (using outside maybe wrong)
    do_action('bb_head','your_header_function');

    Fatal error: Call to undefined function bb_get_current_user() in

    is returned
    when inside the function,

    Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/ttl79zo/public_html/forum/bb-includes/script-loader.php on line 45

    Warning: array_search() [function.array-search]: Wrong datatype for second argument in /home/ttl79zo/public_html/forum/bb-includes/script-loader.php on line 304

    Warning: Invalid argument supplied for foreach() in /home/ttl79zo/public_html/forum/bb-includes/script-loader.php on line 47

    Posted 3 months ago #
  6. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 330

    online

    bb_enqueue_script() needs parameters. Always keep a copy of bbpress handy with a search tool. I actually use the built in windows search and search for function bb_enqueue for example.

    You are trying to create very advanced scripts with a limited knowledge of bbPress. You might have to start at a more basic level.

    Autocomplete is very overrated (I find it annoying). I think there is already a bbPress plugin that does autocomplete so you might want to look at how it works. Here's someone doing it called "live search" http://www.adityanaik.com/integratepress-part-ii-live-search/

    Posted 3 months ago #
  7. agl666
    agl666

    member
    Joined: Aug '08
    Posts: 50

    offline

    bb_enqueue_script() needs parameters.

    yes, I know, but I have no idea for $deps (dependences) parameter. So I think I will stop at generating custom form for editing and custom showing on profile page

    Here's someone doing it called "live search" http://www.adityanaik.com/integratepress-part-ii-live-search/

    hm... it's not the thing I wanna do: it shows results in special place, not under input form. And changing it would take a loooot of time, so maybe later

    Anyway, thanks a lot for helping me

    Posted 3 months ago #
  8. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 330

    online

    Note you don't have to use the built in bbpress functions, you can insert anything you want into the page header very easily like this:

    function add_my_scripts() {
    if (bb_get_location()=="profile-page") {
    echo '<script type="text/javascript" src="'.bb_get_option('uri').'bb-includes/js/jquery/jquery.js">';
    }
    }
    add_action('bb_head','add_my_scripts');

    The enqueue scripts is simply meant to avoid multiple loading of the same script.

    Posted 3 months ago #
  9. agl666
    agl666

    member
    Joined: Aug '08
    Posts: 50

    offline

    Ajax autocomplete now works! Thank you _ck_! I've used hand-adding into bb_head.

    One more question about mysql querying. Is get_result() return ready-for-work-array or something more must be done? I'm inclined to the second, print $results returns nothing

    Posted 3 months ago #
  10. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 330

    online

    I am not sure if your query is valid, it looks okay.
    You know you can't just do "print $results" right?
    It's an array of objects, so you have to loop through them.

    foreach ($results as $result) {echo $result->meta_value;}

    sometimes you actually might have to do this

    foreach ($results as $result) {echo $result[0]->meta_value;}

    do a print_r($results); or var_dump($results); to see what you are dealing with..

    Posted 3 months ago #

RSS feed for this topic

Post a reply to “two question about bb_press functions” »

You must log in to post.

keep _ck_ coding >> donate $1 <<     Theme Switcher:
11 users online from  US  GB  IT  MX in the past 30 minutes. 6 bots 4 guests 1 members: _ck_
499 views today 2798 yesterday 3411 ever. Most at once 19 today 24 yesterday 19 ever. Visited today: _ck_
724 posts in 106 topics over 19 months by 146 of 676 members. Latest: nicoosuna, Wish, insightdesigns