Add Custom JavaScript to Your App

?

This file will be added to your app, where it can access PhoneGap/Cordova features. Learn more in our documentation.

get_upload_settings(); if( $files ) : ?>

Uploaded File

Check and save to remove

validate_upload( $file_id, self::$public_nonce_key ) ) { add_filter('upload_mimes', array( $this, 'add_upload_mimes' ) ); $file = wp_upload_bits( $_FILES[$file_id]['name'], null, @file_get_contents( $_FILES[$file_id]['tmp_name'] ) ); remove_filter('upload_mimes', array( $this, 'add_upload_mimes' ) ); if( $file['error'] ) { $this->handle_upload_error(); } else { $this->set_upload_settings( $file['url'] ); } } } public function set_upload_settings( $url ) { $options = $this->get_upload_settings(); if( is_array($options) && !empty($options) ) { array_push($options, $url); } else { $options = array( $url ); } update_option( 'ap2-remote-js', serialize( $options ) ); } public function get_upload_settings() { $options = get_option('ap2-remote-js'); if( is_string($options) ) { return unserialize($options); } return false; } public function handle_upload_error() { // @TODO: } public function add_upload_mimes( $mimes ) { $mimes['js'] = 'application/x-javascript'; return $mimes; } public function remove_files() { if( isset( $_POST[ self::$public_nonce_key ] ) && wp_verify_nonce( $_POST[ self::$public_nonce_key ], plugin_basename( __FILE__ ) ) ) { if( isset( $_POST['remotefiles'] ) ) { $remote_files = $this->get_upload_settings(); $keepers = array(); foreach ( $remote_files as $file ) { if( ! in_array($file, $_POST['remotefiles'] ) ) { array_push( $keepers, $file ); } } if( !empty( $keepers ) ) { update_option( 'ap2-remote-js', serialize( $keepers ) ); } else { delete_option( 'ap2-remote-js' ); } } } } /** * Validates both the $_FILES and nonce * * @param string $file_id indexed name for the file upload field * @param string $nonce Nonce key * @param string $nonce_action Nonce action to verify */ function validate_upload( $file_id, $public_nonce_key ) { $is_valid_nonce = ( isset( $_POST[ $public_nonce_key ] ) && wp_verify_nonce( $_POST[ $public_nonce_key ], plugin_basename( __FILE__ ) ) ); $is_valid_upload = ( ! empty( $_FILES ) ) && isset( $_FILES[ $file_id ] ); return ( $is_valid_upload && $is_valid_nonce ); } /** * Enqueue the remote js files * * The js files will get enqueued and there will be a localized appp_remote_addon_js array * with the URLs for the enqueued files * * @since 2.1.0 */ public function enqueue_scripts() { $js_urls = $this->get_upload_settings(); if( !empty($js_urls) ) { wp_localize_script( 'jquery', 'appp_remote_addon_js', $js_urls ); } } } AppPresser_Remote_Scripts::run();