Plugin Directory

Changeset 3066362


Ignore:
Timestamp:
04/07/2024 04:07:47 PM (2 years ago)
Author:
prashantvatsh
Message:

Releasing version 1.0.4

Location:
bp-custom-functionalities
Files:
8 added
4 edited

Legend:

Unmodified
Added
Removed
  • bp-custom-functionalities/trunk/bp-custom-functionalities.php

    r2091807 r3066362  
    11<?php
    22defined( 'ABSPATH' ) || exit;
     3
    34add_action( 'admin_menu', 'bp_cfunc_plugin_menu' );
    4 
    55function bp_cfunc_plugin_menu() {
    6     add_options_page( 
     6    add_options_page(
    77        'BP Custom Functionalities',
    88        'BP Custom Functionalities',
     
    1313}
    1414
    15 function bp_cfunc_plugin_func(){
    16     $lock = get_option('ps_lock_bp', true);
    17     $exclevels = get_option('ps_exclude_levels', true);
     15function bp_cfunc_plugin_func() {
     16    $lock = get_option( 'ps_lock_bp', true );
     17    $exclevels = get_option( 'ps_exclude_levels', true );
    1818    global $wp_roles;
    19     $roles = $wp_roles->get_names();
    20     $excroles = get_option('ps_exclude_roles', true);
    21     $restrict_member = get_option('ps_restrict_member', true);
    22     $lock_bb = get_option('ps_lock_bb', true);
     19    $roles = $wp_roles->get_names();
     20    $excroles = get_option( 'ps_exclude_roles', true );
     21    $restrict_member = get_option( 'ps_restrict_member', true );
     22    $lock_bb = get_option( 'ps_lock_bb', true );
    2323    ?>
    2424    <div class="wrap">
    25         <h2><?php _e('BP Custom Functionalities Settings','bp-custom-functionalities');?></h2>
     25        <h2><?php _e( 'BP Custom Functionalities Settings', 'bp-custom-functionalities' ); ?></h2>
    2626        <hr/>
    2727        <form method="post">
    28             <?php wp_nonce_field( basename(__FILE__), 'bp_cfunc_settings' );?>
     28            <?php wp_nonce_field( basename( __FILE__ ), 'bp_cfunc_settings' ); ?>
    2929            <table class="form-table">
    3030                <tr>
    31                     <th scope="row"><?php _e('Lock BuddyPress For Guest Users','bp-custom-functionalities');?></th>
    32                     <td><input type="checkbox" name="ps_lock_bp" value="1" <?php if($lock): ?> checked <?php endif; ?>/></td>
     31                    <th scope="row"><?php _e( 'Lock BuddyPress For Guest Users', 'bp-custom-functionalities' );?></th>
     32                    <td><input type="checkbox" name="ps_lock_bp" value="1" <?php if ( $lock ) : ?> checked <?php endif; ?>/></td>
     33                </tr>
     34                <?php if ( class_exists( 'bbPress' ) ) : ?>
     35                <tr>
     36                    <th scope="row"><?php _e( 'Lock bbPress For Guest Users', 'bp-custom-functionalities' ); ?></th>
     37                    <td><input type="checkbox" name="ps_lock_bb" value="1" <?php if ( $lock_bb ) : ?> checked <?php endif; ?>/></td>
    3338                   
    3439                </tr>
    35                 <?php if ( class_exists( 'bbPress' ) ) :?>
     40                <?php endif; ?>
     41                <?php
     42                global $membership_levels;
     43                if ( $membership_levels ) :
     44                    ?>
     45                    <tr>
     46                        <th scope="row"><?php _e( 'Restrict BuddyPress To Certain Membership levels', 'bp-custom-functionalities' ); ?></th>
     47                        <td>
     48                            <select style="width: 25%; font: inherit;" size="<?php echo count( $membership_levels ) + 1; ?>" name="ps_exclude_levels[]" multiple>
     49                                <option>--SELECT LEVELS--</option>
     50                                <?php foreach ( $membership_levels as $keys => $level ) { ?>
     51                                    <option value="<?php echo $level->id; ?>" <?php if ( ! empty( $exclevels ) && is_array( $exclevels ) && in_array( $level->id, $exclevels ) ) : ?> selected <?php endif; ?>>
     52                                        <?php echo $level->name; ?>
     53                                    </option>
     54                                <?php } ?>
     55                            </select>
     56                        </td>
     57                    </tr>
     58                    <?php
     59                    endif;
     60                ?>
    3661                <tr>
    37                     <th scope="row"><?php _e('Lock bbPress For Guest Users','bp-custom-functionalities');?></th>
    38                     <td><input type="checkbox" name="ps_lock_bb" value="1" <?php if($lock_bb): ?> checked <?php endif; ?>/></td>
    39                    
    40                 </tr>
    41                 <?php endif;?>
    42                 <?php
    43                 global $membership_levels;
    44                 if($membership_levels):
    45                 ?>
    46                 <tr>
    47                     <th scope="row"><?php _e('Restrict BuddyPress To Certain Membership levels','bp-custom-functionalities');?></th>
     62                    <th scope="row"><?php _e( 'Restrict Members From Viewing Other Members Profile', 'bp-custom-functionalities' ); ?></th>
    4863                    <td>
    49                         <select style="width: 25%; font: inherit;" size="<?php echo count($membership_levels)+1;?>" name="ps_exclude_levels[]" multiple>
    50                             <option>--SELECT LEVELS--</option>
    51                             <?php foreach($membership_levels as $keys => $level)  { ?>
    52                                 <option value="<?php echo $level->id;?>" <?php if( !empty($exclevels) && in_array($level->id, $exclevels)):?> selected <?php endif;?>>
    53                                     <?php echo $level->name;?>
    54                                 </option>
    55                             <?php }?>
    56                         </select>
    57                     </td>
    58                 </tr>
    59             <?php endif;?>
    60                 <tr>
    61                     <th scope="row"><?php _e('Restrict Members From Viewing Other Members Profile','bp-custom-functionalities');?></th>
    62                     <td>
    63                         <input type="checkbox" name="ps_restrict_member" value="1" <?php if($restrict_member): ?> checked <?php endif; ?>/>
     64                        <input type="checkbox" name="ps_restrict_member" value="1" <?php if ( $restrict_member ): ?> checked <?php endif; ?>/>
    6465                    </td>
    6566                </tr>
    6667
    6768                <tr>
    68                     <th scope="row"><?php _e('Exclude Roles From Members Directory','bp-custom-functionalities');?></th>
     69                    <th scope="row"><?php _e( 'Exclude Roles From Members Directory', 'bp-custom-functionalities' ); ?></th>
    6970                    <td>
    70                         <select style="width: 25%; font: inherit;" size="<?php echo count($roles)+1;?>" name="ps_exclude_roles[]" multiple>
     71                        <select style="width: 25%; font: inherit;" size="<?php echo count( $roles ) + 1; ?>" name="ps_exclude_roles[]" multiple>
    7172                            <option>--SELECT ROLES--</option>
    72                             <?php foreach($roles as $key => $role) { ?>
    73                                 <option value="<?php echo $key;?>" <?php if( !empty($excroles) && is_array($excroles) && in_array($key, $excroles)):?> selected <?php endif;?>>
    74                                     <?php echo $role;?>
     73                            <?php foreach ( $roles as $key => $role ) { ?>
     74                                <option value="<?php echo $key; ?>" <?php if ( ! empty( $excroles ) && is_array( $excroles ) && in_array( $key, $excroles ) ): ?> selected <?php endif; ?>>
     75                                    <?php echo $role; ?>
    7576                                </option>
    76                             <?php }?>
     77                            <?php } ?>
    7778                        </select>
    7879                    </td>
     
    8586}
    8687
    87 add_action('admin_init','bp_cfunc_save_settings');
    88 function bp_cfunc_save_settings(){
    89     if(current_user_can('manage_options')){
    90         if(isset($_POST['save_ps_settings'])){
    91             if ( empty($_POST['bp_cfunc_settings']) || !wp_verify_nonce( $_POST['bp_cfunc_settings'], basename(__FILE__) ) ) return;
     88add_action( 'admin_init', 'bp_cfunc_save_settings' );
     89function bp_cfunc_save_settings() {
     90    if ( current_user_can( 'manage_options' ) ) {
     91        if ( isset( $_POST['save_ps_settings'] ) ) {
     92            if ( empty( $_POST['bp_cfunc_settings'] ) || ! wp_verify_nonce( $_POST[ 'bp_cfunc_settings' ], basename( __FILE__ ) ) ) return;
     93            $lockbp = isset( $_POST['ps_lock_bp'] ) ? '1' : '0';
     94            update_option( 'ps_lock_bp', $lockbp, true );
    9295
    93             $lockbp = isset($_POST['ps_lock_bp']) ? '1' : '0';
    94             update_option('ps_lock_bp',$lockbp,true);
     96            $lockbb = isset( $_POST['ps_lock_bb'] ) ? '1' : '0';
     97            update_option( 'ps_lock_bb', $lockbb, true );
    9598
    96             $lockbb = isset($_POST['ps_lock_bb']) ? '1' : '0';
    97             update_option('ps_lock_bb',$lockbb,true);
     99            $retrict_levels = isset( $_POST['ps_exclude_levels'] ) ? array_map( 'sanitize_text_field', $_POST['ps_exclude_levels'] ) : '';
    98100
    99             $retrict_levels = isset($_POST['ps_exclude_levels']) ? array_map( 'sanitize_text_field', $_POST['ps_exclude_levels'] ) : '';
     101            update_option( 'ps_exclude_levels', $retrict_levels, true );
    100102
    101             update_option('ps_exclude_levels',$retrict_levels ,true );
     103            $exclude_members = isset( $_POST['ps_exclude_roles'] ) ? array_map( 'sanitize_text_field', $_POST['ps_exclude_roles'] ) : '';
    102104
    103             $exclude_members = isset($_POST['ps_exclude_roles']) ? array_map( 'sanitize_text_field', $_POST['ps_exclude_roles']) : '';
     105            update_option( 'ps_exclude_roles', $exclude_members, true );
    104106
    105             update_option('ps_exclude_roles',$exclude_members,true);
    106 
    107             $restrict_members = isset($_POST['ps_restrict_member']) ? '1' : '0';
    108             update_option('ps_restrict_member',$restrict_members,true);
     107            $restrict_members = isset( $_POST['ps_restrict_member'] ) ? '1' : '0';
     108            update_option( 'ps_restrict_member', $restrict_members, true );
    109109        }
    110110    }
    111111}
    112 ?>
  • bp-custom-functionalities/trunk/languages/bp-custom-functionalities.pot

    r1955356 r3066362  
    33msgstr ""
    44"Project-Id-Version: BP Custom Functionalities 1.0.0\n"
    5 "POT-Creation-Date: 2018-10-09 04:07+0530\n"
     5"POT-Creation-Date: 2024-04-07 21:33+0530\n"
    66"PO-Revision-Date: 2018-10-08 04:18+0530\n"
    77"Last-Translator: \n"
     
    1111"Content-Type: text/plain; charset=UTF-8\n"
    1212"Content-Transfer-Encoding: 8bit\n"
    13 "X-Generator: Poedit 2.1.1\n"
     13"Plural-Forms: nplurals=2; plural=(n != 1);\n"
     14"X-Generator: Poedit 3.4.2\n"
    1415"X-Poedit-Basepath: ..\n"
    15 "Plural-Forms: nplurals=2; plural=(n != 1);\n"
    1616"X-Poedit-SourceCharset: UTF-8\n"
    1717"X-Poedit-KeywordsList: __;_e\n"
    1818"X-Poedit-SearchPath-0: .\n"
    1919
    20 #: bp-custom-functionalities.php:24
     20#: bp-custom-functionalities.php:25
    2121msgid "BP Custom Functionalities Settings"
    2222msgstr ""
    2323
    24 #: bp-custom-functionalities.php:29
     24#: bp-custom-functionalities.php:31
    2525msgid "Lock BuddyPress For Guest Users"
    2626msgstr ""
    2727
    28 #: bp-custom-functionalities.php:38
     28#: bp-custom-functionalities.php:36
     29msgid "Lock bbPress For Guest Users"
     30msgstr ""
     31
     32#: bp-custom-functionalities.php:46
    2933msgid "Restrict BuddyPress To Certain Membership levels"
    3034msgstr ""
    3135
    32 #: bp-custom-functionalities.php:52
     36#: bp-custom-functionalities.php:62
    3337msgid "Restrict Members From Viewing Other Members Profile"
    3438msgstr ""
    3539
    36 #: bp-custom-functionalities.php:59
     40#: bp-custom-functionalities.php:69
    3741msgid "Exclude Roles From Members Directory"
    3842msgstr ""
    3943
    40 #: bp-custom-functionalities.php:74
    41 msgid "For any custom development or support you can contact at <a href=\"https://prashantdev.wordpress.com/contact\">https://prashantdev.wordpress.com/contact</a>."
    42 msgstr ""
    43 
    44 #: loader.php:27
     44#: loader.php:26
    4545msgid "BP Custom Functionalities requires BuddyPress to be active and running."
    4646msgstr ""
  • bp-custom-functionalities/trunk/loader.php

    r2170237 r3066362  
    66 * Author:      Prashant Singh
    77 * Author URI:  https://profiles.wordpress.org/prashantvatsh
    8  * Version:     1.0.3
     8 * Version:     1.0.4
    99 * Text Domain: bp-custom-functionalities
    1010 * License:     GPLv2 or later
     
    1313defined( 'ABSPATH' ) || exit;
    1414
    15 
    16 add_action('plugins_loaded','bp_cfunc_check_is_buddypress');
    17 function bp_cfunc_check_is_buddypress(){
    18     if ( function_exists('bp_is_active') ) {
     15add_action( 'plugins_loaded', 'bp_cfunc_check_is_buddypress' );
     16function bp_cfunc_check_is_buddypress() {
     17    if ( function_exists( 'bp_is_active' ) ) {
    1918        require( dirname( __FILE__ ) . '/bp-custom-functionalities.php' );
    20     }else{
     19    } else {
    2120        add_action( 'admin_notices', 'bp_cfunc_buddypress_inactive__error' );
    2221    }
    2322}
    2423
    25 function bp_cfunc_buddypress_inactive__error(){
     24function bp_cfunc_buddypress_inactive__error() {
    2625    $class = 'notice notice-error';
    2726    $message = __( 'BP Custom Functionalities requires BuddyPress to be active and running.', 'bp-custom-functionalities' );
    28     printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) ); 
     27    printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
    2928}
    3029
    31 // Restrict BuddyPress
     30// Restrict BuddyPress.
    3231function bp_cfunc_guest_redirect() {
    33     $lock = get_option('ps_lock_bp', true);
    34     if($lock){
     32    $lock = get_option( 'ps_lock_bp', true );
     33    if ( $lock ) {
    3534        global $bp;
    3635        if ( is_buddypress() || bp_is_user() ) {
    37             if(!is_user_logged_in()) {
    38                 wp_redirect(site_url());
     36            if ( ! is_user_logged_in() ) {
     37                wp_redirect( site_url() );
    3938                exit;
    40             }
    41         }
     39            }
     40        }
    4241    }
    43     $lockbb = get_option('ps_lock_bb', true);
    44     if($lockbb){
     42
     43    $lockbb = get_option( 'ps_lock_bb', true );
     44    if ( $lockbb ) {
    4545        if ( is_bbpress() ) {
    46             if(!is_user_logged_in()) {
    47                 wp_redirect(site_url());
     46            if ( ! is_user_logged_in() ) {
     47                wp_redirect( site_url() );
    4848                exit;
    49             }
    50         }
     49            }
     50        }
    5151    }
    5252}
    53 add_filter('get_header','bp_cfunc_guest_redirect',1);
     53add_action( 'wp', 'bp_cfunc_guest_redirect', 1 );
    5454
    5555
    5656
    57 //Restrict Member's Profile
     57// Restrict Member's Profile.
    5858add_action( 'wp', 'bp_cfunc_member_redirect' );
    59 function bp_cfunc_member_redirect(){
    60     $restrict_profile = get_option('ps_restrict_member', true);
    61     if($restrict_profile && bp_is_user()){
     59function bp_cfunc_member_redirect() {
     60    $restrict_profile = get_option( 'ps_restrict_member', true );
     61    if ( $restrict_profile && bp_is_user() ) {
    6262        global $bp;
    63         $current_user_id = (int) trim($bp->loggedin_user->id);
    64         $member_id  = (int) trim($bp->displayed_user->id);
    65         if (!current_user_can('manage_options') && $current_user_id !== $member_id)
    66         {
    67             wp_redirect(site_url());
    68             exit;
    69         }
     63        $current_user_id = (int) trim( $bp->loggedin_user->id );
     64        $member_id  = (int) trim( $bp->displayed_user->id );
     65        if ( ! current_user_can( 'manage_options' ) && $current_user_id !== $member_id ) {
     66            wp_redirect( site_url() );
     67            exit;
     68        }
    7069    }
    7170}
    7271
    73 //Exclude User Roles From Member Directory
    74 add_action('bp_ajax_querystring','bp_cfunc_exclude_roles_members_dir',20,2);
    75 function bp_cfunc_exclude_roles_members_dir($ps=false,$object=false){
    76     $exc_roles = get_option('ps_exclude_roles', true);
    77     $users=array();
     72// Exclude User Roles From Member Directory.
     73add_action( 'bp_ajax_querystring', 'bp_cfunc_exclude_roles_members_dir', 20, 2 );
     74function bp_cfunc_exclude_roles_members_dir( $ps = false, $object_name = false ) {
     75    $exc_roles = get_option( 'ps_exclude_roles', true );
     76    $users = array();
    7877
    79     if(!empty($exc_roles)){
    80         foreach ($exc_roles as $key => $value) {
    81             $roles[] = $value;
     78    if ( ! empty( $exc_roles ) && is_array( $exc_roles ) ) {
     79        foreach ( $exc_roles as $key => $value ) {
     80            $roles[] = $value;
    8281        }
    8382        $users = get_users( array( 'role__in' => $roles, 'fields' => 'ID' ) );
    8483    }
    8584
    86     if($users){
     85    if ( $users ) {
     86        if ( $object_name != 'members' )
     87            return $ps;
    8788
    88         if($object!='members')
    89             return $ps;
    90            
    91         $excluded_user = implode(',',$users);
    92      
    93         $args=wp_parse_args($ps);
    94        
    95         if(!empty($args['user_id']))
    96             return $ps;
    97        
    98         if(!empty($args['exclude']))
    99             $args['exclude']=$args['exclude'].','.$excluded_user;
    100         else
    101             $args['exclude']=$excluded_user;
    102          
    103         $ps=build_query($args);
    104        
    105     }
    106     return $ps;
     89        $excluded_user = implode( ',', $users );
     90        $args = wp_parse_args( $ps );
     91
     92        if ( ! empty( $args['user_id'] ) )
     93            return $ps;
     94
     95        if ( ! empty( $args['exclude'] ) )
     96            $args['exclude'] = $args['exclude'] . ',' . $excluded_user;
     97        else
     98            $args['exclude'] = $excluded_user;
     99
     100        $ps = build_query( $args );
     101    }
     102    return $ps;
    107103}
    108104
     105// Restrict Membership levels From BuddyPress.
     106add_action( 'wp', 'bp_cfunc_restrict_levels' );
     107function bp_cfunc_restrict_levels() {
     108    global $bp, $membership_levels;
     109    $exc_levels = get_option( 'ps_exclude_levels', true );
     110    if ( is_user_logged_in() && ! empty( $membership_levels ) && ! current_user_can( 'manage_options' ) ) {
     111        if ( is_buddypress() || bp_is_user() ) {
     112            global $current_user;
     113            $current_user_membership_level = pmpro_getMembershipLevelForUser( $current_user->ID );
     114            if ( empty( $current_user_membership_level ) ) {
     115                wp_redirect( site_url() );
     116                exit;
     117            }
     118        }
     119    }
    109120
    110 //Restrict Membership levels From BuddyPress
    111 add_action('get_header','bp_cfunc_restrict_levels');
    112 function bp_cfunc_restrict_levels(){
    113     global $bp, $membership_levels;
    114     $exc_levels = get_option('ps_exclude_levels', true);
    115     if( is_user_logged_in() && !empty($membership_levels) && !current_user_can('manage_options')){
    116 
    117         if ( is_buddypress() || bp_is_user() ) {
    118             global $current_user;
    119             $current_user_membership_level = pmpro_getMembershipLevelForUser($current_user->ID);
    120             if(empty($current_user_membership_level)){
    121                 wp_redirect(site_url());
    122                 exit;
    123             }
    124         }
    125 
    126     }
    127 
    128     if(!empty($exc_levels) && !empty($membership_levels)){
    129 
     121    if ( ! empty( $exc_levels ) && ! empty( $membership_levels ) && is_array( $exc_levels ) ) {
    130122        if ( is_buddypress() || bp_is_user() ) {
    131             if(is_user_logged_in() && !current_user_can('manage_options')){
    132                 global $current_user;
    133                 $current_user_membership_level = pmpro_getMembershipLevelForUser($current_user->ID);
    134                 if(in_array($current_user_membership_level->ID, $exc_levels) ){
    135                     wp_redirect(site_url());
     123            if ( is_user_logged_in() && ! current_user_can( 'manage_options' ) ) {
     124                global $current_user;
     125                $current_user_membership_level = pmpro_getMembershipLevelForUser( $current_user->ID );
     126                if ( in_array( $current_user_membership_level->ID, $exc_levels ) ) {
     127                    wp_redirect( site_url() );
    136128                    exit;
    137                 }
    138             }
     129                }
     130            }
    139131        }
    140 
    141132    }
    142133}
    143134
    144 // Manage Members Count After Role Exclusion
    145 function bp_cfunc_hide_get_total_filter($count){
    146     $exc_roles = get_option('ps_exclude_roles', true);
    147     $users=array();
     135// Manage Members Count After Role Exclusion.
     136function bp_cfunc_hide_get_total_filter( $count ) {
     137    $exc_roles = get_option( 'ps_exclude_roles', true );
     138    $users = array();
     139    $roles = array();
    148140
    149     if(!empty($exc_roles)){
    150         foreach ($exc_roles as $key => $value) {
    151             $roles[] = $value;
     141    if ( ! empty( $exc_roles ) && is_array( $exc_roles ) ) {
     142        foreach ( $exc_roles as $key => $value ) {
     143            $roles[] = $value;
    152144        }
    153145        $users = get_users( array( 'role__in' => $roles, 'fields' => 'ID' ) );
    154146    }
    155147
    156     if($users){
    157         $users_count = count($users);
    158         $count = $count-$users_count;
     148    if ( $users ) {
     149        $users_count = count( $users );
     150        $count = $count - $users_count;
    159151    }
    160     return $count;
     152    return $count;
    161153}
    162 add_filter('bp_get_total_member_count','bp_cfunc_hide_get_total_filter');
    163 ?>
     154add_filter( 'bp_get_total_member_count', 'bp_cfunc_hide_get_total_filter' );
  • bp-custom-functionalities/trunk/readme.txt

    r2170237 r3066362  
    11=== BP Custom Functionalities ===
    22Contributors: prashantvatsh
    3 Tags: buddypress, members directory, guest user restriction, bp lock, membership level buddypress restriction, pmpro, pmpro membership level, private profile, paid membership pro, lock bbpress, restrict buddypress, exclude member roles
     3Tags: guest user restriction, pmpro membership level buddypress restriction, private profile, lock bbpress, exclude member roles
    44Requires at least: 4.9.0
    5 Tested up to: 5.2.3
    6 Stable tag: 1.0.3
     5Tested up to: 6.5
     6Stable tag: 1.0.4
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6969Fixed All Members Count Issue
    7070
     71= 1.0.4 =
     72Fixed comaptibility issues
     73
    7174== Upgrade Notice ==
    7275= Initial Release =
Note: See TracChangeset for help on using the changeset viewer.