or

Insert Media from URL

$mime_type ) { if ( str_starts_with( $mime_type, 'image/' ) ) { $accepted_extensions = array_merge( $accepted_extensions, explode( '|', $ext ) ); } } return $accepted_extensions; } ); $image = media_sideload_image( esc_url( $_POST['url'] ), null, null, 'id' ); if ( is_wp_error( $image ) ) { wp_send_json_error( $image->get_error_message() ); } else { wp_send_json( array( 'success' => true, 'data' => __( 'Import Successful.', 'gl-import-external-images' ), 'image' => $image ) ); } } else { wp_send_json_error( __( 'No URL found!', 'gl-import-external-images' ) ); } wp_die(); } /** * Initialize the plugin tracker * * @return void */ function appsero_init_tracker_gl_import_external_images() { if ( ! class_exists( 'Appsero\Client' ) ) { require_once __DIR__ . '/lib/appsero/src/Client.php'; } $client = new Appsero\Client( '448732d0-52eb-41d9-b41c-8931eb5e4897', 'GL Import External Images', __FILE__ ); // Active insights $client->insights()->init(); } appsero_init_tracker_gl_import_external_images();