Plugin Directory

Changeset 2228618


Ignore:
Timestamp:
01/16/2020 04:56:08 PM (6 years ago)
Author:
Knighthawk
Message:

Fixed bug: potential for empty string in foreach
Edit: moved check if $content is null earlier to skip doing extra work

Location:
vi-member-content/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • vi-member-content/trunk/readme.txt

    r2205433 r2228618  
    55Requires at least: ?
    66Tested up to: 5.3
    7 Version: 9.1.191203
     7Version: 9.1.200115
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl.html
     
    5252== Changelog ==
    5353
     54= 9.1.200115 =
     55* Fixed bug: potential for empty string in foreach
     56* Edit: moved check if $content is null earlier to skip doing extra work
     57
    5458= 9.1.191203 =
    5559* Fixed bug: missing parameter
  • vi-member-content/trunk/vi_member_content.php

    r2205421 r2228618  
    44Plugin URI: https://neathawk.com/2019/plugin-member-content/
    55Description: A collection of generic functions that separate content by visitor/member/ member of type
    6 Version: 9.1.191203
     6Version: 9.1.200115
    77Author: Joseph Neathawk
    88Author URI: http://Neathawk.com
     
    8787     *
    8888     * @link
    89      * @version 9.1.1028
     89     * @version 9.1.200115
    9090     * @since 0.1.181213
    9191     */
    9292    public static function member_content( $attr, $content = null )
    9393    {
    94 
    95         extract( shortcode_atts( array( 'type' => 'read' ), $attr ) );
    96         //remove spaces
    97         $type = str_replace(" ", "", $type);
    98         $ability = explode(",", $type);
     94        //default is no access
    9995        $access_allowed = false;
    10096
    101         //not NULL and user is at least logged in
    102         if ( !is_null( $content ) && is_user_logged_in() )
     97        if ( !is_null( $content ) )
    10398        {
    104             //targetted users get this content
    105             foreach( $ability as $item )
     99            extract( shortcode_atts( array( 'type' => 'read' ), $attr ) );
     100            //remove spaces
     101            $type = str_replace(" ", "", $type);
     102            $ability = explode(",", $type);
     103
     104            //make absolutely sure $ability isn't empty
     105            if( !is_array($ability) )
    106106            {
    107                 if( strtolower($item) === 'any' )
     107                $ability[] = 'read';
     108            }
     109
     110            //not NULL and user is at least logged in
     111            if ( is_user_logged_in() )
     112            {
     113                //targetted users get this content
     114                foreach( $ability as $item )
    108115                {
    109                     //ACTION
    110                     $access_allowed = true;
    111                 }
    112                 else if( self::is_user_in_role( get_current_user_id(), $item ) || current_user_can( $item ) )
    113                 {
    114                     //ACTION
    115                     $access_allowed = true;
     116                    if( strtolower($item) === 'any' )
     117                    {
     118                        //ACTION
     119                        $access_allowed = true;
     120                    }
     121                    else if( self::is_user_in_role( get_current_user_id(), $item ) || current_user_can( $item ) )
     122                    {
     123                        //ACTION
     124                        $access_allowed = true;
     125                    }
    116126                }
    117127            }
Note: See TracChangeset for help on using the changeset viewer.