Skip to:
Content
Pages
Categories
Search
Top
Bottom

Trying to run some code based on a field with there user id


  • Tosh
    Participant

    @xberserker

    if( $bp->loggedin_user->id = get_option(‘bp_spammer_cp_bp’)){

    run code for spammer

    } else {

    run this if they are not marked as a spammer.

    }

    The get_option(‘bp_spammer_cp_bp’) is a field in the admin where they put in a user ID.
    I have in the field a user ID of 59 and tried from 2 different accounts. Both are treated as spam … what am I doing wrong.

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

  • thekmen
    Participant

    @thekmen

    you are missing an =, should be:
    if( $bp->loggedin_user->id == get_option(‘bp_spammer_cp_bp’)){


    Tosh
    Participant

    @xberserker

    Tried that but now it treats the spammer and the person not marked as spam. As spam free.


    thekmen
    Participant

    @thekmen

    did you try
    if( $bp->loggedin_user->id == '59' ){
    just to see if it works without the get_option(‘bp_spammer_cp_bp’) bit?


    Tosh
    Participant

    @xberserker

    I did actually, still shows the spammer as spam free.


    thekmen
    Participant

    @thekmen

    have you added global $bp; to your function?


    Tosh
    Participant

    @xberserker

    Is this right?
    global $bp;
    if( $bp->loggedin_user->id == ’59’ ){


    thekmen
    Participant

    @thekmen

    yeah, looks correct to me.


    Tosh
    Participant

    @xberserker

    No go, very odd ..


    Tosh
    Participant

    @xberserker

    @thekmen @r-a-y

    Tried going about this another way. Still not working correctly. Says user id 59 is not a spammer, but that user is marked as so. Any ideas?

    I tried to echo it out. Nothing comes out for the user id ..
    echo(‘User ID: ‘ . $bp->loggedin_user->id . “n”);

    /* *********************** START Spammmer! ********************************* */
    global $bp;
    // 59 for testing
    // if( $bp->loggedin_user->id == get_option(‘bp_spammer_cp_bp’)){

    global $current_user;
    global $user_id;

    if ($userinfo->ID == 59) {

    function my_bp_update_post_add_cppoints() {
    if( function_exists(‘cp_alterPoints’) && is_user_logged_in() ){
    cp_alterPoints(cp_currentUser(), 0 );
    cp_log(‘Comment’, cp_currentUser(), 0, BuddyPress);
    echo ‘spammer
    ‘;
    echo(‘User ID: ‘ . $user_info->ID . “n”);
    }
    }
    add_action(‘bp_activity_posted_update’,’my_bp_update_post_add_cppoints’);

    } else {

    // Add Points for a update
    function my_bp_update_post_add_cppoints() {
    if( function_exists(‘cp_alterPoints’) && is_user_logged_in() ){
    cp_alterPoints(cp_currentUser(), get_option(‘bp_update_post_add_cp_bp’) );
    cp_log(‘Comment’, cp_currentUser(), get_option(‘bp_update_post_add_cp_bp’), BuddyPress);
    echo ‘spam free
    ‘;
    echo(‘User ID: ‘ . $user_info->ID . “n”);
    }
    }
    add_action(‘bp_activity_posted_update’,’my_bp_update_post_add_cppoints’);

    }
    /* *********************** END Spammmer! ********************************* */


    r-a-y
    Keymaster

    @r-a-y

    Why are you separating the functions for the same action?

    Look how cleaner this is:
    http://pastebin.com/XUZuS7k8


    Tosh
    Participant

    @xberserker

    Cuz I’m still learning PHP, sorry :/ I’m really grateful for your help btw!That did work! :)
    If a admin where to put in more than one user id separated by a comma like:

    59, 120, 33

    etc. How would I accomplish that from the input field on the admin backend.


    r-a-y
    Keymaster

    @r-a-y

    Yeah sorry, didn’t mean to sound harsh! We all start out somewhere!

    You’d have to “explode” the input variable. Look up “php explode” on Google.

    Then you’ll have to run a cool foreach loop… good thing about building a plugin is you learn! :)


    Tosh
    Participant

    @xberserker

    @r-a-y This is what I came up with and the echo prints out this “Banned Users: Array” am I even close? lol

    function my_bp_update_post_add_cppoints() {
    global $bp;
    $bpcpspam = array($bpcpspamlist);

    $getspamlist = get_option( ‘bp_spammer_cp_bp’ );
    $bpcpspamlist = explode(“,”, $getspamlist);

    echo(‘Banned Users: ‘ . $bpcpspamlist . “
    “);

    if ($bp->loggedin_user->id != get_option( ‘bp_spammer_cp_bp’ ) ) {
    foreach ($bpcpspam as $bpcpspamlist) {
    if( function_exists(‘cp_alterPoints’) ){
    cp_alterPoints($bp->loggedin_user->id, get_option(‘bp_update_post_add_cp_bp’) );
    cp_log(‘Comment’, $bp->loggedin_user->id, get_option(‘bp_update_post_add_cp_bp’), BuddyPress);
    }
    }
    }
    }
    add_action(‘bp_activity_posted_update’,’my_bp_update_post_add_cppoints’);


    r-a-y
    Keymaster

    @r-a-y

    Almost! ;)

    Check this out:
    http://pastebin.com/JXpucxwa (commented the code so hopefully you can learn from it!)


    Tosh
    Participant

    @xberserker

    ^ Exciting :D


    r-a-y
    Keymaster

    @r-a-y

    @xberserker – I’ve updated the code with comments, so check the previous post for the updated link!


    Tosh
    Participant

    @xberserker

    @r-a-y Thanks for that! :) Getting some errors.

    This shows in the admin

    Warning: Invalid argument supplied for foreach() in /home/me/public_html/mysite/wp-content/plugins/cubepoints-buddypress-integration/cubepointsBP.php on line 74

    This shows on the front end when I go to the activity page

    Warning: Invalid argument supplied for foreach() in /home/me/public_html/mysite/wp-content/plugins/cubepoints-buddypress-integration/cubepointsBP.php on line 74

    Line 74 is:
    foreach ( $bpcpspamlist as $spammer_id ) {

    This is what I put in.

    http://pastebin.com/5qDXuCvv


    r-a-y
    Keymaster

    @r-a-y

    Please post the full function on Pastebin.com to post code snippets!


    Tosh
    Participant

    @xberserker

    Edited my post with that now. Opps


    r-a-y
    Keymaster

    @r-a-y

    I see you simply copied and pasted my previous code without adding the rest of the function!

    Here’s the full function:
    http://pastebin.com/5Pb5VpSz (updated to check if spamlist is filled in)

    I think I’ve written the majority of your plugin! lol


    Tosh
    Participant

    @xberserker

    Doh! I’m an idiot, lol. I’ll add you as a contributor to the plugin if you’d like?

    Seems to be working, I’ll do a more tests when I get home. Thank you sooo much r-a-y!


    r-a-y
    Keymaster

    @r-a-y

    Glad it works!

    re: contributor – It’s up to you if you want to add me as a contributor; though if you add me, you should add thekmen too!

Viewing 22 replies - 1 through 22 (of 22 total)
  • The topic ‘Trying to run some code based on a field with there user id’ is closed to new replies.
Skip to toolbar