Skip to:
Content
Pages
Categories
Search
Top
Bottom

No Filters or Actions ??


  • kevinjohngallagher
    Member

    @kevinjohngallagher

    Hello folks,

    I was hoping that someone could point me in the direction of an ACTION that occurs on the following pages so that I can hook my plugin into them without hacking the core:

    bb-edit.php

    I have a plugin that needs to be fired when someone edits a post.

    Forum layout update

    In the backend we do it all through AJAX (how wonderful), except we call the following page bb-admin/admin-ajax.php and the following sections (via a switch statement): add-forums and order-forums.

    Except, no actions there to call either. And yes, to the best of my ability, I’ve stuck with the code the whole way through all the functions they call. I’ve yet to find a pluggable one.

    ===============================================================================

    I realise that my phrasing is sometimes considered combative, and I apologise for that, but are we seriously suggesting that at no point is the ability to add/edit/control/order our forum pluggable in anyway; and the same for the editing of a forum post??

    I’m more than happy to be wrong here, because right now I’m having one of those “bbPress moments” where you’re not quite sure if you’re losing your marbles or if whoever decided to make these not pluggable is.

    Thanks for the help

Viewing 7 replies - 1 through 7 (of 7 total)

  • zaerl
    Participant

    @zaerl

    I have a plugin that needs to be fired when someone edits a post.

    bb_update_post, bb_new_post respectively. Post ID is passed.

    Now beware of the magic (?) hack. Given case 'order-forums' : you can use the the action fired by bb_check_ajax_referer:

    do_action('bb_check_ajax_referer', $action, $result);

    if $action == 'order-forums' then you are in that particular case.

    Now you can read $_POST or accessing other actions. What do you want to do?

    p.s. at least in this way God doesn’t kill a kitten.


    kevinjohngallagher
    Member

    @kevinjohngallagher

    Wonderful Zaerl mate.

    Issue 1:

    bb_new_post and bb_new_topic actually cause me a world of issues, because they’re fired before all of the SQL/PHP is fired. It took me about 2 days to work out my copy and pasted SQL was producing different results in the PHP and the actual database.

    In the end, I had to move those functions to add_action('bb-post.php') and then test if a topic was passed or not.

    (I’m guessing a little that this might have something to do with the wp_cache functions, as in certain places we call wp_cache_flush and wp_cache_delete before the bb_new_post actions)

    bb_update_post though seems like its exactly what I want, though am a tad concerned that the same thing will happen – at least if I have access to $_POST I can hack it.

    I’m basically wanting to know when someone changes the name/title of a topic. Which seems very simple to me (in theory).

    ==========================================================

    The second one is a bit more tricky.

    I basically have a (half-baked) plugin that deals with the geneology of a forum, with true parent/child n-to-n relationships. For my non-flat websites, this (again half-hacked) plugin has really made my life easier.

    Before I release it, I want to make sure I’m covering as many bases as possible, and these have been outstanding bugs for about a year now.

    Whenever someone reorders their forums, or adds a new forum, or marks a forum as hidden; I’d like my plugin to know about it. Basically, I want my plugin to be fired AFTER the core has finished what it’s doing, and we’ve no action for that.

    But there’s no action or pluggable function that gets called after, thre is only bb_check_ajax_referer and thats called before any processing.

    I really apprecaite your help Zaerl mate, if you can think of anyhing else – please shout!


    zaerl
    Participant

    @zaerl

    I’m basically wanting to know when someone changes the name/title of a topic. Which seems very simple to me (in theory).

    do_action( 'bb_update_topic', $topic_id ); actually is fired after all the db stuff and not before. Given the code of bb_insert_topic we have:

    db update

    bb_update_topic

    bb_insert_topic

    in that order. If you intercept bb_update_topic the db must be already updated. At least if there isn’t something evil inside wp_cache_*

    If you want something that works before the database is updated. See this:

    add_filter('pre_topic_title', 'foo', 10, 2);

    function foo($topic_title, $topic_id)
    {
    global $bb_post;

    if($bb_post) echo "You changed me. How dare you.";

    return $topic_title;
    }

    but keep in mind that I’m not proud of this code nor I have run it. What actions do you want to take when a topic is renamed? You want to filter away the new title, changing the slug or what?


    kevinjohngallagher
    Member

    @kevinjohngallagher

    do_action( ‘bb_update_topic’, $topic_id ); actually is fired after all the db stuff and not before. Given the code of bb_insert_topic we have:

    You’re a Legend.

    Once again, Thank You.

    I thought it might, but thats at least me down to 4 non-supported major features in my code:

    1) Update family tree upon adding/removing forums or changing forums order

    (the code is there, the trigger isn’t – right now I’ve just got a reminder in the readme and added it to the daily cron job on my servers)

    2) Gives accurate counting for parent child relationship in terms of “total” forums/topics/posts/voices.

    (Again, code is there and working, and runs on “recount”, but should also be activated upon adding/removing forums or changing forums order)

    3) Addition of “Groups” instead of categories. Again, this is written and working, but I’d need to come up with some form of changeover script.

    (Apparently to group forums together, you need to make it’s parent read only. But if you want to make a forum read only but not a ‘header/category/group’ you can’t. Don’t get me wrong it was a great hack by _ck_ when 0.8.3 came out, but man, why roll it into the core without any actual thought!! 0.8.3 was 3 years ago.)

    4) Rewrite hooks for moderation to comply with other plugins (specifically to play nice and read yours and Nightgunner5’s), as right now it only natively reads my own plugins, which is daft.


    zaerl
    Participant

    @zaerl

    So you need to hook bb_new_forum, bb_update_forum and bb_delete_forum. There is no way to set hooks after the db stuff. Or at least this is what I think after 20 mins of studying the core.


    kevinjohngallagher
    Member

    @kevinjohngallagher

    ooooh bb_update_forum. Awesome find.

    thats the difference between someone who can actually code PHP and someon like me.

    I’ll have to play with it though, and might ask you for some help, as in some re-ordering will fire that once for each forum is manually updated by an admin. I mean that won’t happen often ofc, but it’s (number of SQL calls my function makes * each function affected).

    Currently, and in no way overly optimized, the “forum_family_tree_setup” script uses 2 + (3 * parent) SQL calls per per forum.

    Even on my large football forum, (large in terms of number of forums) which has quite deep relationships, this is far less intensive than a recount. If this was to be multiplied by 3 or 4 times though (depending on how many forums are updated with a move), that might cause a hic-up.

    I’ll do some benchmarks after the weekend – I’ve got 31 non-England teams to support in the World Cup this weekend ;-)

    Cheers bro!


    zaerl
    Participant

    @zaerl

    bb_update_forum is a function, not a hook. Like I said there is no way to fire custom actions when a forum is added/modified/deleted.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Skip to toolbar