Uploading Picture in Custom Panel
-
Hi..
I’m writing a custom setting panel for the theme I’m developing. I could not do a picture on the panel anyway.
The image I selected is saved in the database, but the image is not uploaded to the uploads folder.
The code for the panel is below. How can I solve this problem.
functions.php
/* * Option Page Image Upload */ function load_wp_media_files() { wp_enqueue_media(); } add_action( 'admin_enqueue_scripts', 'load_wp_media_files' ); function handle_file_upload($file) { if(!empty($_FILES[$file]["tmp_name"])) { $urls = wp_handle_upload($_FILES[$file], array('test_form' => FALSE)); $temp = $urls["url"]; return $temp; } return $option; }
theme-options.page
public function page_init() { register_setting( 'firma_settings_group', // Option group 'nivotheme_firma_settings', // Option name array( $this, 'sanitize' ) // Sanitize ); add_settings_section( 'firma_page_section', // ID __('Firma Bilgileri', 'nivothemes'), // Title array( $this, 'firma_page_section' ), // Callback 'firma-settings-page' // Page ); add_settings_field( 'firma_logo', // ID __('Firma Logosu', 'nivothemes'), // Label array( $this, 'firma_logo_html' ), // Callback 'firma-settings-page', // Page 'firma_page_section' // Section ); //...other codes } public function sanitize( $input ) { $sanitized_input= array(); if( isset( $input['firma_logo'] ) ) : $sanitized_input['firma_logo'] = sanitize_text_field( $input['firma_logo'] ); handle_file_upload('firma_logo'); endif; //...other codes } public function firma_logo_html() { printf( '<input type="file" id="firma_logo" name="nivotheme_firma_settings[firma_logo]" />' //isset( $this->firma['firma_logo'] ) ? esc_attr( $this->firma['firma_logo']) : '' ); }
Thanks..
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Uploading Picture in Custom Panel’ is closed to new replies.