Skip to:
Content
Pages
Categories
Search
Top
Bottom

Plugin: Default Friend 0.1

  • @nicolagreco

    Participant

    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)
  • @burtadsit

    Participant

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

    @nicolagreco

    Participant

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

    @nicolagreco

    Participant

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

    @iamzaks

    Member

    does it work?

    @nicolagreco

    Participant

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

    @jordannilsen

    Member

    @Nicola – Thanks for writing this plugin!

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

    Thanks!

    @realfam

    Member

    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.

    @hyrxx

    Participant

    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

    @ladysham

    Participant

    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.

    @realfam

    Member

    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?

    @nicolagreco

    Participant

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

    @realfam

    Member

    is this ready yet by chance?

    @djpaul

    Keymaster

    <?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');

    ?>

    @djpaul

    Keymaster

    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>";

    }

    @davidtcarson

    Participant

    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.

    @nicolagreco

    Participant

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

    @sdiggles

    Participant

    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)
  • The topic ‘Plugin: Default Friend 0.1’ is closed to new replies.
Skip to toolbar