1 | <?php |
---|
2 | |
---|
3 | add_action('admin_menu', 'register_my_custom_submenu_page'); |
---|
4 | |
---|
5 | function register_my_custom_submenu_page() { |
---|
6 | add_menu_page( 'Sideload test', 'Sideload test', 'manage_options', 'sideload-test', 'sideload_test' ); |
---|
7 | } |
---|
8 | |
---|
9 | function sideload_test() { |
---|
10 | $urls = array( |
---|
11 | 'http://adamharley.co.uk/sideload-test/unencoded space.jpg', |
---|
12 | 'http://adamharley.co.uk/sideload-test/unencoded%20space.jpg', |
---|
13 | 'http://adamharley.co.uk/sideload-test/encoded%20space.jpg', |
---|
14 | 'http://adamharley.co.uk/sideload-test/encoded%2520space.jpg', |
---|
15 | 'http://adamharley.co.uk/sideload-test/plus+space.jpg', |
---|
16 | 'http://adamharley.co.uk/sideload-test/and&space.jpg', |
---|
17 | 'http://adamharley.co.uk/sideload-test/and%26space.jpg', |
---|
18 | 'http://adamharley.co.uk/sideload-test/question?mark.jpg', |
---|
19 | 'http://adamharley.co.uk/sideload-test/question%3Fmark.jpg', |
---|
20 | 'http://adamharley.co.uk/sideload-test/question%3Fmark.jpg?', |
---|
21 | 'http://adamharley.co.uk/sideload-test/am&persand.jpg', |
---|
22 | 'http://adamharley.co.uk/sideload-test/am%26persand.jpg', |
---|
23 | 'http://adamharley.co.uk/sideload-test/per%cent.jpg', |
---|
24 | 'http://adamharley.co.uk/sideload-test/per%25cent.jpg', |
---|
25 | ); |
---|
26 | |
---|
27 | echo '<div class="wrap">'; |
---|
28 | |
---|
29 | foreach ( $urls as $url ) { |
---|
30 | echo '<p><strong>' . basename($url) . ':</strong> '; |
---|
31 | |
---|
32 | $r = media_sideload_image( $url, 0 ); |
---|
33 | |
---|
34 | if ( is_wp_error( $r ) ) { |
---|
35 | echo 'Encountered an error: ' . $r->get_error_message(); |
---|
36 | } else { |
---|
37 | echo 'Downloaded successfully'; |
---|
38 | } |
---|
39 | |
---|
40 | echo '</p>'; |
---|
41 | } |
---|
42 | |
---|
43 | echo '<p> </p><p><a href="' . admin_url('upload.php') . '" target="_blank">See results</a></p></div>'; |
---|
44 | } |
---|