Follow us on

Codestar Support Forum » WordPress Plugins » Codestar Framework

Profile Option Framework - Editable by only 1 user.

  1. Hi,
    I am trying to add a profile option field which will be edible by a specific user.

    I have tried this

    if( class_exists( 'CSF' ) ) {
    
    	$prefix = 'dealer_discount_override';
    
    	CSF::createProfileOptions( $prefix, array(
    	  'data_type' => 'serialize', // The type of the database save options. `serialize` or `unserialize`
    	) );
    
    	$user_id = get_current_user_id();
    
    	if( $user_id == '351' ){
    
    		CSF::createSection( $prefix, array(
    			'title'  => 'Dealer Tier Discount',
    			'description'	=> 'This discount rule will override the general tier discount rule. ',
    			'fields' => array(
    
    			array(
    				'id'    =>	'dealer-tier-discount',
    				'type'  =>	'number',
    				'title' =>	'Discount Percentage',
    				'after'	=>	'%',
    				'min'	=>	'0',
    				'max'	=>	'100'
    			)
    
    			)
    		) );
    
    	}
    
      }CopyCopied!

    But its not working.

    Can you help guiding me to correct direction.

    Kind regards

    Posted 8 months ago #
  2. I think i was able to achieve this using a filter.

    add_filter('csf_dealer_discount_override_sections', 'gem_dealer_discount_override_args');
     function gem_dealer_discount_override_args($args){
    	if( get_current_user_id() == '352' ){
    		return $args;
    	} else {
    		return false;
    	}
     }CopyCopied!
    Posted 8 months ago #

  3. Codestar
    Admin

    Hi,

    Welcome to support forum and thanks for purchasing.

    Yes, Filter way is correct. Also another way is run it in "init" action. for eg:

    function projoomexperts_dealer_discount_init() {
    
      if( class_exists( 'CSF' ) ) {
    
        $prefix = 'dealer_discount_override';
    
        CSF::createProfileOptions( $prefix, array(
          'data_type' => 'serialize', // The type of the database save options. `serialize` or `unserialize`
        ) );
    
        $user_id = get_current_user_id();
    
        if( $user_id == '1' ){
    
          CSF::createSection( $prefix, array(
            'title'  => 'Dealer Tier Discount',
            'description' => 'This discount rule will override the general tier discount rule. ',
            'fields' => array(
    
            array(
              'id'    =>  'dealer-tier-discount',
              'type'  =>  'number',
              'title' =>  'Discount Percentage',
              'after' =>  '%',
              'min' =>  '0',
              'max' =>  '100'
            )
    
            )
          ) );
    
        }
    
      }
    
    }
    add_action( 'init', 'projoomexperts_dealer_discount_init', 5 );CopyCopied!

    Regards, Codestar

    Posted 8 months ago #