Changeset 2567475
- Timestamp:
- 07/19/2021 05:10:56 PM (5 years ago)
- Location:
- social-media-library/trunk
- Files:
-
- 3 added
- 5 edited
-
assets (added)
-
assets/js (added)
-
assets/js/media-filter.js (added)
-
index.php (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
-
src/Image.php (modified) (3 diffs)
-
src/MediaUploads.php (modified) (1 diff)
-
src/RemoteUserMedia.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
social-media-library/trunk/index.php
r2560071 r2567475 4 4 * Plugin URI: https://github.com/wpmotto/wp-instagram-media-library 5 5 * Description: Save images from a public Instagram account to your WordPress library. 6 * Version: 1. 0.16 * Version: 1.1.0 7 7 * Requires at least: 5.2 8 8 * Requires PHP: 7.2 … … 28 28 $remote = new RemoteUserMedia( $settings ); 29 29 30 /** 31 * Setup Cron Job 32 */ 30 33 add_action( 31 34 'igml_cron_hook', [$remote, 'uploadUnsavedMedia'] 35 ); 36 37 /** 38 * Initial Run when settings are updated. 39 */ 40 add_action( 41 'update_option_igml_settings', [$remote, 'uploadUnsavedMedia'] 32 42 ); 33 43 … … 55 65 return $where; 56 66 }, 10, 2 ); 67 68 69 add_action( 'wp_enqueue_media', function() { 70 wp_enqueue_script( 71 'media-library-taxonomy-filter', 72 plugin_dir_url(__FILE__) . 'assets/js/media-filter.js', 73 ['media-editor', 'media-views'] 74 ); 75 // Load 'terms' into a JavaScript variable that collection-filter.js has access to 76 wp_localize_script( 'media-library-taxonomy-filter', 'MediaLibraryTaxonomyFilterData', array( 77 'terms' => get_terms( 'social_media_attachments', array( 'hide_empty' => false ) ), 78 ) ); 79 // Overrides code styling to accommodate for a third dropdown filter 80 add_action( 'admin_footer', function(){ 81 ?> 82 <style> 83 .media-modal-content .media-frame select.attachment-filters { 84 max-width: -webkit-calc(33% - 12px); 85 max-width: calc(33% - 12px); 86 } 87 </style> 88 <?php 89 }); 90 }); 91 92 add_action( 'init', function() { 93 register_taxonomy('social_media_attachments', ['attachment'], [ 94 'hierarchical' => false, 95 'show_ui' => false, 96 'show_in_nav_menus' => false, 97 'query_var' => is_admin(), 98 'rewrite' => false, 99 'public' => false, 100 'label' => _x( 'Social Media Attachment', 'Taxonomy name', 'motto-igml' ), 101 ]); 102 }, 0 ); 103 -
social-media-library/trunk/readme.txt
r2560071 r2567475 4 4 Donate link: https://motto.ca 5 5 Requires at least: 4.8 6 Tested up to: 5. 76 Tested up to: 5.8 7 7 Requires PHP: 7.2 8 Stable tag: 1. 0.18 Stable tag: 1.1.0 9 9 License: GPLv2 10 10 License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html … … 24 24 == Changelog == 25 25 26 = 1.1 = 27 * Moved social network meta from post content to attachment meta. 28 * Added filter in Media Library to view by network. 29 26 30 = 1.0 = 27 31 * First version. -
social-media-library/trunk/src/Image.php
r2560071 r2567475 8 8 9 9 protected $post; 10 protected $social; 10 11 11 12 public function __construct( WP_Post $post ) 12 13 { 13 14 $this->post = $post; 15 $this->social = wp_get_attachment_metadata( $this->post->ID )['social']; 14 16 } 15 17 … … 24 26 } 25 27 28 public function social( $prop = null ) 29 { 30 if( isset($this->social[$prop]) ) 31 return $this->social[$prop]; 32 33 return $this->social; 34 } 35 26 36 public function html( $size = 'full' ) 27 37 { … … 29 39 } 30 40 31 public function src( $size = 'full' )41 public function src( $size = 'full', $array = false ) 32 42 { 33 return wp_get_attachment_image_src($this->post->ID, $size); 43 $img = wp_get_attachment_image_src($this->post->ID, $size); 44 if( $array ) 45 return $img; 46 47 return $img[0]; 34 48 } 35 49 } -
social-media-library/trunk/src/MediaUploads.php
r2555949 r2567475 18 18 'posts_per_page' => 10, 19 19 'post_status' => 'inherit', 20 'guid_ends_with' => '_ig_media.jpg' 20 'tax_query' => [ 21 [ 22 'taxonomy' => 'social_media_attachments', 23 'field' => 'slug', 24 'terms' => 'instagram', 25 ], 26 ], 21 27 ], $args); 22 28 } -
social-media-library/trunk/src/RemoteUserMedia.php
r2555949 r2567475 40 40 'post_date' => date('Y-m-d H:i:s', $media->getCreatedTime()), 41 41 'post_name' => $media->getId(), 42 'post_content' => serialize($media),43 42 'post_status' => 'inherit', 44 43 'guid' => $upload_file['url'], 45 44 ); 46 45 46 47 47 $attachment_id = wp_insert_attachment( $attachment, $upload_file['file'], $parent_post_id ); 48 48 if (!is_wp_error($attachment_id)) { 49 49 require_once(ABSPATH . "wp-admin" . '/includes/image.php'); 50 50 $attachment_data = wp_generate_attachment_metadata( $attachment_id, $upload_file['file'] ); 51 $attachment_data['social'] = $this->socialMeta($media); 51 52 wp_update_attachment_metadata( $attachment_id, $attachment_data ); 53 54 // Set Terms 55 wp_set_object_terms( 56 $attachment_id, 'instagram', 'social_media_attachments' 57 ); 52 58 } 53 59 } else { … … 61 67 $query = "SELECT COUNT(*) FROM {$wpdb->posts} WHERE `post_name` = $id"; 62 68 return !empty(intval($wpdb->get_var($query))); 69 } 70 71 private function socialMeta( Media $media ) 72 { 73 return [ 74 'id' => $media->getId(), 75 'created' => $media->getCreatedTime(), 76 'shortcode' => $media->getShortcode(), 77 'link' => $media->getLink(), 78 'thumb_tiny_url' => $media->getImageLowResolutionUrl(), 79 'thumb_url' => $media->getImageStandardResolutionUrl(), 80 'thumb_hires_url' => $media->getImageHighResolutionUrl(), 81 'square_images' => $media->getSquareImages(), 82 'likes_count' => $media->getLikesCount(), 83 ]; 63 84 } 64 85
Note: See TracChangeset
for help on using the changeset viewer.