Skip to content

Instantly share code, notes, and snippets.

@RadGH
RadGH / rs_upload_from_url.php
Last active May 7, 2024 14:26
Upload a file from a URL to the WordPress media gallery. Supports images, PDFs, and other file types.
<?php
/**
* This function uploads a file from a URL to the media library, designed to be placed in your own theme or plugin.
* Metadata will be generated and images will generate thumbnails automatically.
*
* HOW TO USE:
* 1. Add the function below to your theme or plugin
* 2. Call the function and provide the URL to an image or other file.
* 3. If successful, the attachment ID will be returned.
@sohelrana820
sohelrana820 / sort_multidimensional_array_by_time.php
Last active February 7, 2023 16:51
How to sort PHP multidimensional array by timestamp
// Feeds array with title and time
$feeds = array(
array(
'title' => 'Some Feeds.',
'time' => '2015-03-31 13:06:00'
),
array(
'title' => 'And another.',
'time' => '2015-03-23 13:06:00'
),