admin管理员组

文章数量:1026989

I've used the Settings API in the past to output text inputs and checkboxes but am unsure if I can use file inputs.

My add_settings_field() is:

add_settings_field( '1', 'File 1', array( $this, 'my_callback' ), 'files', 'files' );

My callback function:

public function my_callback() {     
    echo '<input type="file" name="file" />';
}

I assume the next step is to handle the image upload. My problem is how do I do this using the Settings API? I am aware I can set a callback function as the 3rd parameter in register_setting() so my guess is I can use wp_handle_upload() in that callback. I'm looking for some guidance or confirmation that this is the approach I should take. Thanks in advance.

I've used the Settings API in the past to output text inputs and checkboxes but am unsure if I can use file inputs.

My add_settings_field() is:

add_settings_field( '1', 'File 1', array( $this, 'my_callback' ), 'files', 'files' );

My callback function:

public function my_callback() {     
    echo '<input type="file" name="file" />';
}

I assume the next step is to handle the image upload. My problem is how do I do this using the Settings API? I am aware I can set a callback function as the 3rd parameter in register_setting() so my guess is I can use wp_handle_upload() in that callback. I'm looking for some guidance or confirmation that this is the approach I should take. Thanks in advance.

本文标签: phpUploading files using the Settings API