-
Notifications
You must be signed in to change notification settings - Fork 0
/
prism-data-media.php
68 lines (47 loc) · 1.42 KB
/
prism-data-media.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* Plugin Name: Prism | Media Data
* Description: Activate to load sample 'Media' data
* Author: Casey Patrick Driscoll
* Author URI: https://caseypatrickdriscoll.com
*/
class Prism_Media_Data {
static function init() {
register_activation_hook( __FILE__, array( __CLASS__, 'install' ) );
add_filter( 'prism_branches', array( __CLASS__, 'add_branches' ), 100 );
}
public static function add_branches( $branches ) {
$media_branch = array(
array(
'title' => 'Media',
'slug' => array(
'plural' => 'media',
'single' => 'media'
),
'icon' => 'fa-image',
'connections' => array()
),
);
return array_merge( $branches, $media_branch );
}
public static function install() {
// MEDIA
// http://lorempixel.com/500/500/
//
// BOOM:
// https://codex.wordpress.org/Function_Reference/media_sideload_image
$url = 'http://lorempixel.com/500/500/';
$tmp = plugin_dir_path( __FILE__ ) . 'images/';
if ( ! file_exists( $tmp ) ) {
mkdir( $tmp , 0660, true );
}
for ( $i = 0; $i < 50; $i++) {
$name = 'image_' . $i . '.jpg';
if ( ! file_exists( $tmp . $name ) )
file_put_contents( $tmp . $name, file_get_contents( $url ) );
$file_array = array( 'tmp_name' => $tmp . $name, 'name' => $name );
media_handle_sideload( $file_array, false );
}
}
}
Prism_Media_Data::init();