false, 'data' => $temp_file->get_error_message(), ); } // Array based on $_FILE as seen in PHP file uploads. $file_args = array( 'name' => basename( $file ), 'tmp_name' => $temp_file, 'error' => 0, 'size' => filesize( $temp_file ), ); $overrides = array( // Tells WordPress to not look for the POST form // fields that would normally be present as // we downloaded the file from a remote server, so there // will be no form fields // Default is true. 'test_form' => false, // Setting this to false lets WordPress allow empty files, not recommended. // Default is true. 'test_size' => true, // A properly uploaded file will pass this test. There should be no reason to override this one. 'test_upload' => true, ); // Move the temporary file into the uploads directory. $results = wp_handle_sideload( $file_args, $overrides ); if ( isset( $results['error'] ) ) { return array( 'success' => false, 'data' => $results, ); } // Success! return array( 'success' => true, 'data' => $results, ); } } /** * Kicking this off by calling 'get_instance()' method */ Astra_Sites_Helper::get_instance(); endif;