最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - Uploading files using the Settings API

matteradmin5PV0评论

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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far