Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* this is the input field */
- ...
- <input type="file" name="MoobLogoUpload" id="MoobLogoUpload" size="40" />
- <?php if ($file = $options['MoobLogoUpload']) {
- echo "<img src='{$file['url']}' />";
- }
- ?>
- ...
- /* and this is your ajax function with the upload extra in it */
- add_action('wp_ajax_test_theme_data_save', 'test_theme_save_ajax');
- function test_theme_save_ajax() {
- check_ajax_referer('test-theme-data', 'security');
- $data = $_POST;
- unset($data['security'], $data['action']);
- /* ### upload extra */
- if ($data['MoobLogoUpload']) {
- $overrides = array('test_form' => false);
- $file = wp_handle_upload($data['MoobLogoUpload'], $overrides);
- $data['MoobLogoUpload'] = $file;
- }
- /* ### upload extra END */
- if(!is_array(get_option('test_theme'))) {
- $options = array();
- } else {
- $options = get_option('test_theme');
- }
- if(!empty($data)) {
- $diff = array_diff($options, $data);
- $diff2 = array_diff($data, $options);
- $diff = array_merge($diff, $diff2);
- } else {
- $diff = array();
- }
- if(!empty($diff)) {
- if(update_option('test_theme', $data)) {
- die('1');
- } else {
- die('0');
- }
- } else {
- die('1');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement