Skip to content

Instantly share code, notes, and snippets.

View eagleyed's full-sized avatar
🏠
Working from home

Rituparna sonowal eagleyed

🏠
Working from home
  • Individual
  • Kolkata, India
View GitHub Profile
@eagleyed
eagleyed / gist:6a448125aaa1fb49b791ad7cde8162c4
Created May 15, 2019 13:25 — forked from hissy/gist:7352933
[WordPress] Add file to media library programmatically
<?php
$file = '/path/to/file.png';
$filename = basename($file);
$upload_file = wp_upload_bits($filename, null, file_get_contents($file));
if (!$upload_file['error']) {
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_parent' => $parent_post_id,