Follow us on
  1. Hello,
    Thanks for your amazing framework !!
    I have a stupid question, How to check if "subtest1" or "subtest2" is checked ?

    array(
     'id'      => 'test1',
     'type'    => 'checkbox',
     'title'   => 'My Title',
     'options' => array(
     'subtest1'    => 'Sub test 1',
     'subtest2'    => 'Sub test 2',
    ),
    ),CopyCopied!

    Can I simply get fields from checkbox like this:

    $var = get_option( 'test1' );
                if ( $var['subtest1'] ) {
                    // ... do something if subtest1 is checked
                }CopyCopied!

    Thanks for helping !

    Posted 3 years ago #

  2. Codestar
    Admin

    Hi,

    Welcome to support forum and thanks for purchasing.

    $options = get_option( 'your_framework_config_prefix' );
    
    if( isset( $options['test1'] && $options['test1'] == 'subtest1' ) {
      // do stuff
    }CopyCopied!

    Let me explain it more. Suppose you have this config in backend.

    if( class_exists( 'CSF' ) ) {
    
      $prefix = 'your_framework_prefix';
    
      CSF::createOptions( $prefix, array(
        'menu_title' => 'My Framework',
        'menu_slug'  => 'my-framework',
      ) );
    
      CSF::createSection( $prefix, array(
        'title'  => 'Tab Title 1',
        'fields' => array(
    
          array(
            'id'         => 'opt-checkbox-1',
            'type'       => 'checkbox',
            'title'      => 'My Title',
            'options'    => array(
              'subtest1' => 'Sub Test 1',
              'subtest2' => 'Sub Test 2',
            )
          ),
    
        )
      ) );
    
    }CopyCopied!

    And you should get checkbox value like this:

    $options = get_option( 'your_framework_prefix' );
    
    if( isset( $options['opt-checkbox-1'] && $options['opt-checkbox-1'] == 'subtest1' ) {
      // do stuff
    }CopyCopied!

    But this way is not good. Let's see the best way for get_option. Below code creating a custom function for "get_option"

    if ( ! function_exists( 'your_prefix_get_option' ) ) {
      function your_prefix_get_option( $option = '', $default = null ) {
        $options = get_option( 'my_framework_prefix' ); // Attention: Set your unique id of the framework
        return ( isset( $options[$option] ) ) ? $options[$option] : $default;
      }
    }CopyCopied!

    Usage:

    $opt_checkbox_1 = your_prefix_get_option( 'opt-checkbox-1' );
    
    if( $opt_checkbox_1 == 'subtest1' ) {
      // do stuff
    }CopyCopied!

    You got it ? Also you can get more information from documentation

    Regards, Codestar

    Posted 3 years ago #
  3. Hi! thanks for your quick answer !

    but the "output" have a array with key/value format.

    if ( ! function_exists( 'your_prefix_get_option' ) ) {
            function your_prefix_get_option( $option = '', $default = null ) {
                $options = get_option( '_aki_options' ); // Attention: Set your unique id of the framework
                return ( isset( $options[$option] ) ) ? $options[$option] : $default;
            }
        }
    
        $opt_checkbox_1 = your_prefix_get_option( 'posts_options' );
        var_dump($opt_checkbox_1);CopyCopied!

    OUTPUT:

    array(2) { [0]=> string(12) "posts_thumbs" [1]=> string(13) "posts_oddeven" }CopyCopied!

    I find a solution by doing a test but it requires me to pass 2 variables with each call

    if ( ! function_exists( 'aki_get_option' ) ) {
    			function aki_get_option( $option = '', $default = null ) {
    				$options = get_option( '_aki_options' ); // Attention: Set your unique id of the framework
    				//MULTI CHECKBOX
    				if ( $default && isset( $options[ $option ] ) ) {
    					if ( in_array( $default, $options[ $option ] ) ) {
    						return true;
    					} else {
    						return false;
    					}
    				}
    				//OTHER CASES
    				return ( isset( $options[ $option ] ) ) ? $options[ $option ] : $default;
    			}
    		}CopyCopied!

    but I would like to have direct access to the variable as in your example

    THANKS ! very much

    Posted 3 years ago #

  4. Codestar
    Admin

    Hi,

    Oh yes, I forgot. It's array output

    And yes you can use your method. Or use it as simply.

    $posts_options = aki_get_option( 'posts_options' );
    
    if( in_array( 'posts_thumbs', $posts_options ) ) {
      // do stuff
    }CopyCopied!

    Regards, Codestar

    Posted 3 years ago #
  5. It works perfectly !! thanks

    Posted 3 years ago #

  6. Codestar
    Admin

    You're welcome

    Posted 3 years ago #
  7. How to use multiple checkbox with 'dependency'? If i have 3 checkboxes 'checkbox1', 'checkbox2' and ''checkbox3'

    array(
    				'id'		=> 'my-checkbox',
    				'type'		=> 'checkbox',
    				'options'	=> array(
    					'checbox1'	=> 'Checbox 1',
    					'checbox2'	=> 'Checbox 2',
    					'checbox3'	=> 'Checbox 3'
    				),
    				'default'	=> array('checbox1', 'checbox2')
    			),CopyCopied!

    and i want to show a field if 'checkbox3' is selected from above

    array(
    				'id'		=> 'my-numbers',
    				'type'	=> 'number',
    				'default'	=> '0',
    'dependency'	=> array('my-checkbox', '==', 'checbox3')
    			),CopyCopied!

    The dependency is not working if i use it the way shown in the above example. What is the correct method for dependency check here?

    Posted 3 years ago #

  8. Codestar
    Admin

    Hi @gwtstudio,

    Did you try "any" condition ?

    'dependency' => array( 'my-checkbox', 'any', 'checbox1' ),CopyCopied!

    Regards, Codestar

    Posted 3 years ago #
  9. It works.. thanks

    Posted 3 years ago #

  10. Codestar
    Admin

    You're welcome

    Posted 3 years ago #

  11. Posted 11 months ago #

  12. Codestar
    Admin

    Hi @netmasc,

    Welcome to support forum and thanks for purchasing.

    There is a mistake in if condition. Can you update like this:

    function remove_dashboard_widgets () {
    
      $options = get_option( '_netmasc_tweaks' );
    
      $widgets = ( isset( $options['tweaks_backend_dashboard_widgets'] ) ) ? $options['tweaks_backend_dashboard_widgets'] : array();
    
      if ( in_array( 'dashboard_quick_press', $widgets ) ) ) {
        remove_meta_box('dashboard_quick_press', 'dashboard', 'side' );
      }
    
      // Another example.
      // if ( in_array( 'dashboard_activity', $widgets ) ) ) {
      //   remove_meta_box('dashboard_activity', 'dashboard', 'side' );
      // }
    
    }
    
    add_action( 'wp_dashboard_setup', 'remove_dashboard_widgets' );CopyCopied!

    So, tweaks_backend_dashboard_widgets is array. it can't condition "array == string" directly.

    Regards, Codestar

    Posted 11 months ago #
  13. Hi Codestar,

    Thank you for the fast answer.
    Unfortunately, there seems to be a problem with the query.
    The website gives the following error:

    Parse error: syntax error, unexpected variable "$options"

    The error is probably in this line:

    $widgets = ( isset( $options['tweaks_backend_dashboard_widgets'] ) ) $options['tweaks_backend_dashboard_widgets'] ? array();CopyCopied!

    Regards, netmasc

    Posted 11 months ago #

  14. Codestar
    Admin

    Hi,

    Ups sorry, just update the line:

    $widgets = ( isset( $options['tweaks_backend_dashboard_widgets'] ) ) ? $options['tweaks_backend_dashboard_widgets'] : array();CopyCopied!

    Regards, Codestar

    Posted 11 months ago #
  15. Hi @codestar,

    works great now!
    thank you very much for the help!

    Regards
    netmasc

    Posted 10 months ago #

  16. Codestar
    Admin

    You're welcome @netmasc.

    Posted 10 months ago #