Skip to:
Content
Pages
Categories
Search
Top
Bottom

Plugin: Default Friend 0.1

  • Avatar of Nicola Greco
    nicolagreco
    Participant

    @nicolagreco

    I’ve developed that plugin as promised.

    It add automatically a friend to new registred user,

    I haven’t tried it yet but i think it works, so don’t be angry and against me if it doesn’t work, i wrote this code in 15 minutes while i was having breakfast :P

    <?php
    /*
    Plugin Name: BP Default Friend
    Description: Automatically add a specified user as friend after SignUp
    Plugin URI: http://notsecurity.com/default-friend
    Author: Nicola Greco
    Author URI: http://notsecurity.com
    Version: 0.1
    */

    function default_friend() {
    global $wpdb, $bp;
    $wpdb->query("INSERT INTO " . $bp['friends']['table_name'] . " ( initiator_user_id, friend_user_id, is_confirmed, is_limited, date_created ) VALUES (".bp_current_user_id().", ".get_option('bp-default-friend-id').", 1, 0, NOW())");

    }
    function default_friend_control() {
    add_submenu_page("wpmu-admin.php", 'Default Friend', 'Default Friend', 8, 'default-friend', 'default_friend_options');
    }
    function default_friend_options() {
    if(isset($_POST['submitted'])) {
    $default_friend_id = $_POST['bp-default-friend-id'];
    update_option( 'bp-default-friend-id', $default_friend_id );
    echo "<div id="message" class="updated fade"><strong>Options updated.</strong>
    </div>";
    }
    ?>

    <div class="wrap">

    <h2><?php _e( 'Default Friend', 'buddypress' ) ?></h2>

    <form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" id="options">

    <table class="form-table">
    <tbody>
    <tr>
    <th scope="row">Default Friend ID:</th>
    <td><input name="bp-default-friend-id" id="bp-default-friend-id" value="<?php echo get_option('bp-default-friend-id') ?>" />
    </td>
    </tr>
    </tbody>
    </table>

    <p class="submit">
    <input name="submitted" type="hidden" value="yes" />
    <input type="submit" name="bp-default-friend" id="bp-default-friend" value="<?php _e( 'Save Settings', 'buddypress' ) ?>"/>

    <?php wp_nonce_field( 'bp-default-friend') ?>

    </form>

    </div>

    <?php
    }
    add_action( 'wpmu_activate_user', 'default_friend' );
    add_action('admin_menu', 'default_friend_control');
    ?>

    Install this plug in in /wp-content/mu-plugins and activate it, then in the Site Admin Menu will appear a new voice “Default Friend”, and write there the id of the default friend ;)

    I post that code quickly because i think community will do better

Viewing 17 replies - 1 through 17 (of 17 total)
  • Avatar of Burt Adsit
    Burt Adsit
    Participant

    @burtadsit

    Thanks nicola. They teaching php in school in Italy now? :)

    Avatar of Nicola Greco
    nicolagreco
    Participant

    @nicolagreco

    No, it’s my passion and my work ;)

    Avatar of Nicola Greco
    nicolagreco
    Participant

    @nicolagreco

    i think that it doesn’t work, i don’t know why :S

    does it work?

    Avatar of Nicola Greco
    nicolagreco
    Participant

    @nicolagreco

    If at the beginning you add require_once( 'bp-core.php' ); it should work

    Avatar of Jordannilsen
    jordannilsen
    Member

    @jordannilsen

    @Nicola – Thanks for writing this plugin!

    Would you please post the complete .php plugin code so I may add to my site.

    Thanks!

    Does this work? I tried it just now and its not adding a friend to already existing members profiles. Does it only add to members who sign up after this is installed? Its not doing that for me either. I copied the PHP, added the line at the top that is needed, saved it and popped it in mu-plugins and the option shows up and it says its successful when I add the user ID, but nothing really happens on the front end.

    Avatar of Hyrxx
    hyrxx
    Participant

    @hyrxx

    i created the file for this directly on ssh and saved it and then added my id in the bit

    i did add that other little line but still as reported above it doesnt work, i would like it to work and have everyone become my friend when they sign up but i think something better would be to allow the admin to force freindships so that i dont have to wait for them to accept

    any help with a plugin like this would be appricated

    Avatar of Ladysham
    ladysham
    Participant

    @ladysham

    I uploaded this plugin and activated it, put in the id of the “default friend” and then signed up again as a new user. No default friend was added.

    I agree on these points. It would be great to have a plugin that forces a default friend on every member who is signed up and all new mwmbers who sign up….just like “Tom” on Myspace. That should not be too difficult for someone who has good coding experience, but I am not an expert with code. Anyone else want to see this feature?

    Avatar of Nicola Greco
    nicolagreco
    Participant

    @nicolagreco

    I think after releasing BPDEV-FLICKR and BPDEV-YOUTUBE i think i’ll rewrite this plugin..

    is this ready yet by chance?

    <?php

    /*

    Plugin Name: BP Default Friend

    Author: DJPaul

    Author URI: djpaul@gmail.com

    Original Author: Nicola Greco

    Original Author URI: http://notsecurity.com

    Description: Automatically add a specified user as friend after SignUp

    Plugin URI: http://djpaul.dangerous-minds.org

    Version: 0.2

    */

    require_once(WP_CONTENT_DIR . '/mu-plugins/bp-core.php');

    function default_friend($user_id) {

    global $wpdb, $bp;

    $wpdb->query("INSERT INTO " . $bp . " ( initiator_user_id, friend_user_id, is_confirmed, is_limited, date_created ) VALUES (".$user_id.", ".get_option('bp-default-friend-id').", 1, 0, NOW())");

    }

    function default_friend_control() {

    add_submenu_page("wpmu-admin.php", 'Default Friend', 'Default Friend', 8, 'bp-default-friend', 'default_friend_options');

    }

    function default_friend_options() {

    if(isset($_POST)) {

    $default_friend_id = $_POST;

    update_option( 'bp-default-friend-id', $default_friend_id );

    echo "<div id="message" class="updated fade">Options updated.</div>";

    }

    ?>

    <div class="wrap">

    <h2><?php _e( 'Default Friend', 'buddypress' ) ?></h2>

    <form action="<?php $_SERVER ?>" method="post" id="options">

    <table class="form-table">

    <tbody>

    <tr>

    <th scope="row">Default Friend ID:</th>

    <td><input name="bp-default-friend-id" id="bp-default-friend-id" value="<?php echo get_option('bp-default-friend-id') ?>" />

    </td>

    </tr>

    </tbody>

    </table>

    <p class="submit">

    <input name="submitted" type="hidden" value="yes" />

    <input type="submit" name="bp-default-friend" id="bp-default-friend" value="<?php _e( 'Save Settings', 'buddypress' ) ?>"/>

    <?php wp_nonce_field( 'bp-default-friend') ?>

    </form>

    </div>

    <?php

    }

    add_action('wpmu_activate_user', 'default_friend', 1, 1);

    add_action('admin_menu', 'default_friend_control');

    ?>

    FYI security bug in the above: see below for the change.

    function default_friend_options() {

    if(isset($_POST)) {

    check_admin_referer('bp-default-friend');

    $default_friend_id = $_POST;

    update_option( 'bp-default-friend-id', $default_friend_id );

    echo "<div id="message" class="updated fade">Options updated.</div>";

    }

    Avatar of David Carson
    David Carson
    Participant

    @davidtcarson

    Is this still working for everyone else?

    I’m using BP trunk and, although the option for default friend appears in my admin section, the default friend is no longer being added upon new user registration.

    Avatar of Nicola Greco
    nicolagreco
    Participant

    @nicolagreco

    when i’ll have time i hope i’ll help you, right now make this plugin is simpler you think :)

    Avatar of Sdiggles
    sdiggles
    Participant

    @sdiggles

    Did you guys ever get this sorted out? I put DJPaul’s plugin on my site and under the ticket where the field for the default friend would be, it is just blank…

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

You must be logged in to reply to this topic.