to_translate = array( "Here's your uploaded media URI:", "Error occured while processing your file. Please try again.", "upload", "choose file", "remove", "Extension \"%s\" not allowed. Allowed extensions are \"%s\"", "Maximum file size \"%s\" KB breached. Your file size was \"%s\" KB", "You must be logged-in to upload", "Permissions don't allow you to upload", "Error occured while processing your file" ); $AJAX_file_upload = new AJAX_file_upload(); $this->translations = array(); foreach( $this->to_translate as $i => $string ) { $this->translations[$i] = $AJAX_file_upload->translate( $string ); } } public function _init() { add_action('admin_menu', array( &$this, 'admin_menu' ) ); add_filter( "ajax_file_upload_settings", array( &$this, "filter_settings" ), 0 ); add_filter( "admin_init", array( &$this, "redirect" ) ); } public static function init() { $class = null == self::$instance ? new self : self::$instance; return $class->_init(); } public function admin_menu() { add_options_page( 'AJAX file upload', 'AJAX file upload', 'manage_options', 'ajax-file-upload', array( &$this, 'screen' ) ); add_submenu_page( '', "Welcome to AJAX File Upload", '', 'manage_options', 'afu-about', array( &$this, 'about_screen' ) ); } public function about_screen() { require 'afu-about.php'; } public function update() { if( ! isset( $_POST['_afu_nonce'] ) || !wp_verify_nonce( $_POST['_afu_nonce'], '_afu_nonce' ) ) { return; } $settings = isset( $_POST["settings"] ) ? $_POST["settings"] : array(); if( ! empty( $settings["max"] ) ) { if( (int) $settings["max"] > 0 ) { $settings["max"] = (int) $settings["max"]; } } if( ! empty( $settings["ext"] ) ) { $settings["ext"] = explode( ",", $settings["ext"] ); foreach( $settings["ext"] as $i => $ext ) { $settings["ext"][$i] = preg_replace('/\s+/', '', $ext); } } if( empty( $settings["permission"] ) ) { unset( $settings["permission"] ); } else { $settings["permission"] = sanitize_text_field( $settings["permission"] ); } update_option( "afu_settings", json_encode( $settings ) ); if( ! empty( $_POST["translate"] ) ) { $object = array(); foreach( $_POST["translate"] as $i => $string ) { $object[ $this->to_translate[$i] ] = sanitize_text_field( str_replace( "\"", """, $string ) ); } update_option( "afu_transaltions", base64_encode( json_encode( $object ) ) ); wp_redirect( "options-general.php?page=ajax-file-upload&updated=true" ); exit; } echo '
Settings saved successfully.