Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
rhondaramadge

Radio Button Save Inline

I have added a custom field radio button in edit user which is fine on the edit user page but shows as a text field in inline editing. I have used the following code. Saves fine on the edit user page but not in inline editing. Can you tell me what I’m doing wrong.
This is my code:

/**
 * Change inline eit for a specific custom field to a prefilled drop down
 *
 * @param $data array
 * @param $column AC\Column
 *
 * @return mixed
 */


function my_acp_custom_field_editing_selectbox( $data, $column ) {

	if ( $column instanceof ACP\Column\CustomField ) {

		if ( 'fees-paid' === $column->get_meta_key() ) {
			$data['type'] = 'select';
			$data['options'] = array(
				'yes' => 'Yes',
				'no' => 'No',

			);
	       if ( 'grade' === $column->get_meta_key() ) {
			$data['type'] = 'select';
			$data['options'] = array(
				'a' => 'A',
				'ab' => 'AB',
                                'b' => 'B',
			);
		}
	

		}

	}

	return $data;
}
5 years, 1 month ago
Stefan van den Dungen Gronovius
Developer

Hi
Just to be sure, I don’t see the actual call to your function.
Did you also added the actual hook to call it?
https://www.admincolumns.com/documentation/filter-reference/acp-editing-view_settings/
add_filter( 'acp/editing/view_settings', 'my_acp_custom_field_editing_selectbox', 10, 2 );

If so, do you see the change reflected to the overview page? Do you see that inline edit now give you the select box for editing? Or is it still a text field? Based on your code, I believe that your code should work for a Custom Field column with meta key is ‘fees_paid’ or ‘grade’.

Or is is just the saving that does not store the correct values?

5 years, 1 month ago
rhondaramadge

This is my current code:

<?php
   /*
   Plugin Name: Extra user profile fields
   Plugin URI: http://gcps.org.au
   description: >-
  a plugin to Edit a Users Profile
   Version: 1.0
   Author: Rhonda Ramadge
   Author URI: http://rhondaramadge.com
   License: GPL2
   */
//add_action( 'show_user_profile', 'extra_user_profile_fields' );
add_action( 'edit_user_profile', 'extra_user_profile_fields' );

function extra_user_profile_fields( $user ) { ?>
    <h3><?php _e("Extra profile information", "blank"); ?></h3>

    <table class="form-table">
	<tr>
        <th><label for="pin"><?php _e("Pin"); ?></label></th>
        <td>
            <input type="text" name="pin" id="pin" value="<?php echo esc_attr( get_the_author_meta( 'pin', $user->ID ) ); ?>" class="regular-text" /><br />
            <span class="description"><?php _e("Pin Number."); ?></span>
        </td>
    </tr>	
    <tr>
    <th><label FOR="grade">Grade</label></th>
    <td>
        <?php $status = get_the_author_meta( 'grade', $user->ID ); ?>
        <input TYPE="radio" name="grade" value="A" <?php checked( $status, 'a' ); ?> /> A<br />
        <input TYPE="radio" name="grade" value="AB" <?php checked( $status, 'ab' ); ?> /> AB<br />
        <input TYPE="radio" name="grade" value="B" <?php checked( $status, 'b' ); ?> /> B<br />
        <span CLASS="description">Grade</span>
    </td>
</tr> 
    <tr>
        <th><label for="street-address"><?php _e("Street-Address"); ?></label></th>
        <td>
            <input type="text" name="street-address" id="street-address" value="<?php echo esc_attr( get_the_author_meta( 'street-address', $user->ID ) ); ?>" class="regular-text" /><br />
            <span class="description"><?php _e("Street address."); ?></span>
        </td>
    </tr>
	 <tr>
        <th><label for="suburb"><?php _e("Suburb"); ?></label></th>
        <td>
            <input type="text" name="suburb" id="suburb" value="<?php echo esc_attr( get_the_author_meta( 'suburb', $user->ID ) ); ?>" class="regular-text" /><br />
            <span class="description"><?php _e("Suburb."); ?></span>
        </td>
    </tr>
	<tr>
        <th><label for="postcode"><?php _e("Postcode"); ?></label></th>
        <td>
            <input type="text" name="postcode" id="postcode" value="<?php echo esc_attr( get_the_author_meta( 'postcode', $user->ID ) ); ?>" class="regular-text" /><br />
            <span class="description"><?php _e("Postcode."); ?></span>
        </td>
    </tr>
    <tr>
        <th><label for="phone"><?php _e("Phone"); ?></label></th>
        <td>
            <input type="text" name="phone" id="phone" value="<?php echo esc_attr( get_the_author_meta( 'phone', $user->ID ) ); ?>" class="regular-text" /><br />
            <span class="description"><?php _e("Phone Number."); ?></span>
        </td>
    </tr>
     <tr>
        <th><label for="mobile"><?php _e("Mobile"); ?></label></th>
        <td>
            <input type="text" name="mobile" id="mobile" value="<?php echo esc_attr( get_the_author_meta( 'mobile', $user->ID ) ); ?>" class="regular-text" /><br />
            <span class="description"><?php _e("Mobile number."); ?></span>
        </td>
    </tr>
    <tr>
    <th><label for="president-year"><?php _e("President-year"); ?></label></th>
        <td>
            <input type="text" name="president-year" id="president-year" value="<?php echo esc_attr( get_the_author_meta( 'president-year', $user->ID ) ); ?>" class="regular-text" /><br />
            <span class="description"><?php _e("President Year."); ?></span>
        </td>
    </tr>
	
	<tr>
    <th><label for="secretary-year"><?php _e("Secretary-year"); ?></label></th>
        <td>
            <input type="text" name="secretary-year" id="secretary-year" value="<?php echo esc_attr( get_the_author_meta( 'secretary-year', $user->ID ) ); ?>" class="regular-text" /><br />
            <span class="description"><?php _e("Secretary Year."); ?></span>
        </td>
    </tr>

<tr>
    <th><label for="competition-secretary-year"><?php _e("Competition-secretary-year"); ?></label></th>
        <td>
            <input type="text" name="competition-secretary-year" id="competition-secretary-year" value="<?php echo esc_attr( get_the_author_meta( 'competition-secretary-year', $user->ID ) ); ?>" class="regular-text" /><br />
            <span class="description"><?php _e("Competition Secretary Year."); ?></span>
        </td>
    </tr>

<tr>
    <th><label for="treasurer-year"><?php _e("Treasurer-year"); ?></label></th>
        <td>
            <input type="text" name="treasurer-year" id="treasurer-year" value="<?php echo esc_attr( get_the_author_meta( 'treasurer-year', $user->ID ) ); ?>" class="regular-text" /><br />
            <span class="description"><?php _e("Treasurer Year."); ?></span>
        </td>
    </tr>

<tr>
    <th><label for="committee-member-year"><?php _e("Committee-member-year"); ?></label></th>
        <td>
            <input type="text" name="committee-member-year" id="committee-member-year" value="<?php echo esc_attr( get_the_author_meta( 'committee-member-year', $user->ID ) ); ?>" class="regular-text" /><br />
            <span class="description"><?php _e("Committee Member Year."); ?></span>
        </td>
    </tr>
<tr>
    <th><label for="other-roles"><?php _e("Other-Roles"); ?></label></th>
        <td>
            <textarea type="text" name="other-roles" id="other-roles" class="regular-text"><?php echo esc_attr( get_the_author_meta( 'other-roles', $user->ID ) ); ?></textarea><br />
            <span class="description"><?php _e("Other Roles."); ?></span>
        </td>
    </tr>
	<tr>
        <th><label for="joining-date"><?php _e("Joining-date"); ?></label></th>
        <td>
            <input type="text" name="joining-date" id="joining-date" value="<?php echo esc_attr( get_the_author_meta( 'joining-date', $user->ID ) ); ?>" class="regular-text" /><br />
            <span class="description"><?php _e("Joining Date Must be entered as yearmonthday (no spaces,/ or.) e.g. 29/6/2018 entered as 20180629"); ?></span>
        </td>
    </tr>	
<tr>
        <th><label for="year-left"><?php _e("Year left"); ?></label></th>
        <td>
            <input type="text" name="year-left" id="year-left" value="<?php echo esc_attr( get_the_author_meta( 'year-left', $user->ID ) ); ?>" class="regular-text" /><br />
            <span class="description"><?php _e("Year Left"); ?></span>
        </td>
    </tr>	
<tr>
    <th><label FOR="fees-paid">Are Fees Paid</label></th>
    <td>
        <?php $status = get_the_author_meta( 'fees-paid', $user->ID ); ?>
        <input TYPE="radio" name="fees-paid" value="yes" <?php checked( $status, 'yes' ); ?> /> Yes<br />
        <input TYPE="radio" name="fees-paid" value="no" <?php checked( $status, 'no' ); ?> /> No<br />
        <span CLASS="description">Have fees been paid.</span>
    </td>
</tr> 
<tr>
        <th><label for="life-member"><?php _e("Life Member"); ?></label></th>
        <td>
           <input type="checkbox" name="life-member" id=" life-member " value="yes" <?php if (esc_attr( get_the_author_meta( "life-member", $user->ID )) == "yes") echo "checked"; ?> /><label for="life-member "><?php _e("Life Member"); ?></label><br />

        </td>
    </tr>	

<tr>
    <th><label for="comments"><?php _e("Comments"); ?></label></th>
        <td>
            <textarea type="text" name="comments" id="comments" class="regular-text"><?php echo esc_attr( get_the_author_meta( 'comments', $user->ID ) ); ?></textarea><br />

            <span class="description"><?php _e("Comments."); ?></span>
        </td>
    </tr>
 
 
    </table>
<?php }

add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );

function save_extra_user_profile_fields( $user_id ) {
    if ( !current_user_can( 'edit_user', $user_id ) ) { 
        return false; 
    }
	update_user_meta( $user_id, 'pin', $_POST['pin'] );
    update_user_meta( $user_id, 'grade', $_POST['grade'] );
    update_user_meta( $user_id, 'street-address', $_POST['street-address'] );
    update_user_meta( $user_id, 'suburb', $_POST['suburb'] );
    update_user_meta( $user_id, 'postcode', $_POST['postcode'] );
    update_user_meta( $user_id, 'phone', $_POST['phone'] );
    update_user_meta( $user_id, 'mobile', $_POST['mobile'] );
    update_user_meta( $user_id, 'president-year', $_POST['president-year'] );
    update_user_meta( $user_id, 'secretary-year', $_POST['secretary-year'] );
    update_user_meta( $user_id, 'competition-secretary-year', $_POST['competition-secretary-year'] );
    update_user_meta( $user_id, 'treasurer-year', $_POST['treasurer-year'] );
    update_user_meta( $user_id, 'committee-member-year', $_POST['committee-member-year'] );   
    update_user_meta( $user_id, 'joining-date', $_POST['joining-date'] );
    update_user_meta( $user_id, 'fees-paid', $_POST['fees-paid'] );
    update_user_meta( $user_id, 'life-member', $_POST['life-member'] );
    update_user_meta( $user_id, 'comments', $_POST['comments'] );
    update_user_meta( $user_id, 'other-roles', $_POST['other-roles'] );
    update_user_meta( $user_id, 'year-left', $_POST['year-left'] );

}

/**
 * Change inline eit for a specific custom field to a prefilled drop down
 *
 * @param $data array
 * @param $column AC\Column
 *
 * @return mixed
 */
function my_acp_custom_field_editing_selectbox( $data, $column ) {

	if ( $column instanceof ACP\Column\CustomField ) {
        
			        
				if ( 'fees-paid' === $column->get_meta_key() ) {
			$data['type'] = 'select';
			$data['options'] = array(
				'yes' => 'Yes',
				'no' => 'No',

			);
	       if ( 'grade' === $column->get_meta_key() ) {
			$data['type'] = 'select';
			$data['options'] = array(
				'a' => 'A',
				'ab' => 'AB',
                                'b' => 'B',
			);
		}

		}

	}

	return $data;
}
add_filter( 'acp/editing/view_settings', 'my_acp_custom_field_editing_selectbox', 10, 2 );

The fees paid works fine. With the grade the Radio buttons appear on the edit user screen and save ok but the buttons are blank after saving.
I just get a textarea and not a drop down on the users list when trying to save inline. Saves ok inline but doesn’t show in radio buttons on the edit user screen.

5 years, 1 month ago
Stefan van den Dungen Gronovius
Developer

Ok the grade check in your hook is wrapped inside the feed conditional
You’ll need to place it outside the check and it should work or grade as well.

function my_acp_custom_field_editing_selectbox2( $data, $column ) {
	if ( $column instanceof ACP\Column\CustomField ) {
		if ( 'fees-paid' === $column->get_meta_key() ) {
			$data['type'] = 'select';
			$data['options'] = array(
				'yes' => 'Yes',
				'no'  => 'No',

			);
		}
		if ( 'grade' === $column->get_meta_key() ) {
			$data['type'] = 'select';
			$data['options'] = array(
				'a'  => 'A',
				'ab' => 'AB',
				'b'  => 'B',
			);
		}
	}
	return $data;
}
5 years, 1 month ago
rhondaramadge

I tried your code but had no inline editing. Changed function my_acp_custom_field_editing_selectbox2( $data, $column ) { to function my_acp_custom_field_editing_selectbox( $data, $column ) { Now have inline editing and both fees paid and grade have the drop down when inline editing. The fees paid works fine. With grade inline editing works fine but doesn’t show up on the edit user screen All radio buttons are blank. If I try to save from the edit user screen the buttons stay blank but it shows the correct value in the list users screen. If I use selectbox2 it saves fine the the edit user screen but I have no inline editing available for anything on the list screen. Thank you for your help, hope my explanation is not too confusing.

5 years, 1 month ago
Stefan van den Dungen Gronovius
Developer

Sorry, the name of the method was indeed incorrect. I had to rename it on my local environment since I already had the method.

The issue for grade is that you use both uppercase and lowercase checks in your code.
The drop down in your code has uppercase values while you check for lowercase. Please make sure that those are the same and also change it in your hook accordingly.

5 years, 1 month ago
rhondaramadge

Thank you so much. All working perfectly now.

5 years, 1 month ago

You must be logged in to reply to this topic.