WordPress.org

Ready to get started?Download WordPress

Forums

help please: check box function for input options on option page of plugin (1 post)

  1. Alex.R
    Member
    Posted 1 year ago #

    Hey guys, can someone help me with this function..

    function jraba_checkbox( $main, $jobs, $resume ) { 
    
    $opts = get_option( 'add_jobroller_dashboard_bar_menu_options' );
    $opts = get_option( 'add_jobroller_jobs_bar_menu' );
    $opts = get_option( 'add_jobroller_resume_bar_menu' );
    
    $checked = '';
    
    if ( isset($opts[$main]) && isset($opts[$jobs]) && isset($opts[$resume]) ) {
    if ($opts[$main] == 1 || $opts[$jobs] == 1 || $opts[$resume] == 1 ) { $checked = ' checked="checked"'; } }
    
    echo '<input id="'. esc_attr( $main ) .'" name="add_jobroller_dashboard_bar_menu_options['. esc_attr( $main ) .']" type="checkbox" value="1"'. $checked .' />';
    echo '<input id="'. esc_attr( $jobs ) .'" name="add_jobroller_jobs_bar_menu['. esc_attr( $jobs ) .']" type="checkbox" value="1"'. $checked .' />';
    echo '<input id="'. esc_attr( $resume ) .'" name="add_jobroller_resume_bar_menu['. esc_attr( $resume ) .']" type="checkbox" value="1"'. $checked .' />';
    
    }

    I'm getting the following error.. Warning: Missing argument 2 for jraba_checkbox() in E:\wamp\www\wordpress\wp-content\plugins\jraba\functions.php on line 270

    So I added function jraba_checkbox( $main='', $jobs='', $resume='' ) {

    ..and the error went away, but now the check boxes are not showing up.. what am I doing wrong?..

    ---------------------

    Basically I have 3 forms with check box options to enable or disable menu items on the option page of my plugin.. I'm trying to make the check box options work...

    <form  action="options.php" method="post" enctype="multipart/form-data">
    <?php settings_fields( 'add_jobroller_dashboard_bar_menu_options', 'jraba' ); do_settings_sections( 'jraba_jobroller_menu_settings' );?>
    <p class="submit"><input type="submit" name="updateoption" value="<?php _e('Update »') ?>" /></p>
    </form>
    
    <form  action="options.php" method="post" enctype="multipart/form-data">
    <?php settings_fields( 'add_jobroller_jobs_bar_menu', 'jraba' ); do_settings_sections( 'jraba_jobroller_jobs_menu_settings' );?>
    <p class="submit"><input type="submit" name="updateoption" value="<?php _e('Update »') ?>" /></p>
    </form>
    
    <form  action="options.php" method="post" enctype="multipart/form-data">
    <?php settings_fields( 'add_jobroller_resume_bar_menu', 'jraba' ); do_settings_sections( 'jraba_jobroller_resume_menu_settings' );?>
    <p class="submit"><input type="submit" name="updateoption" value="<?php _e('Update »') ?>" /></p>
    </form>

    Now if I have all 3 functions separated in my functions.php file, it works perfectly..

    Example:

    // checkbox 1
    function jraba_checkbox_1( $arg ) {	$opts = get_option( 'add_jobroller_dashboard_bar_menu_options' );
    
    	$checked = '';
    	if ( isset( $opts[$arg] ) ) { if ( $opts[$arg] == 1 ) { $checked = ' checked="checked"'; } }
    
    	echo '<input id="'. esc_attr( $arg ) .'" name="add_jobroller_dashboard_bar_menu_options['. esc_attr( $arg ) .']" type="checkbox" value="1"'. $checked .' />';
    }
    
    // checkbox 2
    function jraba_checkbox_2( $arg ) { $opts = get_option( 'add_jobroller_jobs_bar_menu' );
    
    	$checked = '';
    	if ( isset( $opts[$arg] ) ) { if ( $opts[$arg] == 1 ) { $checked = ' checked="checked"'; } }
    
    	echo '<input id="'. esc_attr( $arg ) .'" name="add_jobroller_jobs_bar_menu['. esc_attr( $arg ) .']" type="checkbox" value="1"'. $checked .' />';
    }
    
    // checkbox 3
    function jraba_checkbox_3( $arg ) { $opts = get_option( 'add_jobroller_resume_bar_menu' );
    
    	$checked = '';
    	if ( isset( $opts[$arg] ) ) { if ( $opts[$arg] == 1 ) { $checked = ' checked="checked"'; } }
    
    	echo '<input id="'. esc_attr( $arg ) .'" name="add_jobroller_resume_bar_menu['. esc_attr( $arg ) .']" type="checkbox" value="1"'. $checked .' />';
    }

    But I'm thinking this might be the wrong way of doing things, and so I would like to ask your help on merging them into one function..

    I have my validation function, my activation function, deactivation function, and all the field settings and sections in place.. everything is good to go, I just cant seem to make these 3 functions work as one.. or should they be separated?..

    all my add_settings_field codex options have separate calls for individual check box functions..

    add_settings_field( 'jraba_jobroller_dashboard', 'Dashboard:', 'jraba_checkbox_1', 'jraba_jobroller_menu_settings_1', 'jraba_jobroller_menu_checks_1', 'jraba_jobroller_dashboard' );
    
    add_settings_field( 'jraba_jobroller_job_listing', 'Jobs:', 'jraba_checkbox_2', 'jraba_jobroller_jobs_menu_settings', 'jraba_jobroller_menu_checks_2', 'jraba_jobroller_job_listing' );
    
    add_settings_field( 'jraba_jobroller_resume_listing', 'Resumes:', 'jraba_checkbox_3', 'jraba_jobroller_resume_menu_settings_1', 'jraba_jobroller_menu_checks_3', 'jraba_jobroller_resume_listing' );

    If you could help me with this, I would really appreciate this. I apologize for my English and the Long Post in advance, I'm Russian, and English is my 5th language, so sometimes I have a hard time expressing myself correctly.

    [ Please do not bump, that's not permitted here. ]

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.