Skip to content

Instantly share code, notes, and snippets.

@polevaultweb
Last active February 19, 2016 14:46
Show Gist options
  • Select an option

  • Save polevaultweb/a05a76bbd1103fdb003d to your computer and use it in GitHub Desktop.

Select an option

Save polevaultweb/a05a76bbd1103fdb003d to your computer and use it in GitHub Desktop.
oEmbed Library Addon for WP Offload S3
<?php
/*
Plugin Name: WP Offload S3 - oEmbed Library Addon
*/
/**
* OEmbed in Library
* https://wordpress.org/plugins/oembed-in-library/
*/
function wpos3_oembed_lib_init() {
if ( ! class_exists( 'Amazon_S3_And_CloudFront_Pro' ) ) {
return;
}
add_filter( 'as3cf_ignored_mime_types', 'wpos3_oembed_lib_ignore_mime_types' );
}
add_action( 'init', 'wpos3_oembed_lib_init' );
/**
* Ignore certain mime types from get_attachments_to_upload()
*
* @param array $ignored_mime_types
*
* @return array
*/
function wpos3_oembed_lib_ignore_mime_types( $ignored_mime_types = array() ) {
$ignored_mime_types = is_array( $ignored_mime_types ) ? $ignored_mime_types : array();
if ( class_exists( 'OEmbedInLibrary' ) ) {
$saved_mime_types = get_site_transient( 'wpos3_oembed_lib_ignored_mime_types' );
if ( ! $saved_mime_types || ! is_array( $saved_mime_types ) ) {
global $wpdb;
$mime_types = $wpdb->get_results( "SELECT post_mime_type FROM $wpdb->posts WHERE `post_mime_type` LIKE '%oembed/%'", ARRAY_A );
if ( is_array( $mime_types ) ) {
$mime_types_to_ignore = wp_list_pluck( $mime_types, 'post_mime_type' );
$ignored_mime_types = array_unique( array_merge( $mime_types_to_ignore, $ignored_mime_types ) );
}
set_site_transient( 'wpos3_oembed_lib_ignored_mime_types', $ignored_mime_types, DAY_IN_SECONDS );
} else {
$ignored_mime_types = array_unique( array_merge( $saved_mime_types, $ignored_mime_types ) );
}
}
return $ignored_mime_types;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment