Skip to content

Commit

Permalink
Merge pull request #39 from mwks-jg/mwks-csv-support
Browse files Browse the repository at this point in the history
Support for csv files
  • Loading branch information
jdashley27 authored Jul 20, 2022
2 parents 8737b77 + 2a0d5d5 commit b2075a1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/scripts/admin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions lib/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,16 @@ public function add_image_to_library(): void {
}
}

if ( 'generic' === $asset_data['type'] ) {
// check generic file extension and apply correct mimetype.
if ( 'csv' === $asset_data['ext'] ) {
$asset_data['mime_type'] = 'text/csv';
}
if ( 'xml' === $asset_data['ext'] ) {
$asset_data['mime_type'] = 'application/xml';
}
}

if ( 'video' === $asset_data['type'] ) {
if ( 'MPEG4' === $asset_data['format'] ) {
$asset_data['mime_type'] = 'video/mp4';
Expand Down
6 changes: 3 additions & 3 deletions lib/Admin/tiles/generic_binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ class="tile__image blur-up lazyload"
<div class="tile__button-wrapper">
<button
class="button add-to-library"
data-type="office"
data-type="generic"
data-ext="<?php echo esc_attr( $file_ext ); ?>"
data-id="<?php echo esc_attr( $pdf_id ); ?>"
data-filename="<?php echo esc_attr( $pdf_filename ); ?>"
data-id="<?php echo esc_attr( $file_id ); ?>"
data-filename="<?php echo esc_attr( $file_filename ); ?>"
data-description="<?php echo esc_attr( $description ); ?>"
data-url="<?php echo esc_attr( $original_url ); ?>"
data-templated-url="<?php echo esc_attr( Util::sanitize_image_url( $templated_url ) ); ?>"
Expand Down
1 change: 1 addition & 0 deletions lib/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ private function define_admin_hooks(): void {
$this->loader->add_action( 'wp_ajax_widen_media_add_audio_to_library', $plugin_admin, 'add_audio_to_library' );
$this->loader->add_action( 'wp_ajax_widen_media_add_pdf_to_library', $plugin_admin, 'add_pdf_to_library' );
$this->loader->add_action( 'wp_ajax_widen_media_add_office_file_to_library', $plugin_admin, 'add_image_to_library' );
$this->loader->add_action( 'wp_ajax_widen_media_add_generic_file_to_library', $plugin_admin, 'add_image_to_library' );
$this->loader->add_action( 'wp_ajax_widen_media_add_video_to_library', $plugin_admin, 'add_image_to_library' );
$this->loader->add_action( 'wp_ajax_widen_media_save_collection', $plugin_admin, 'save_collection' );
$this->loader->add_filter( 'post_row_actions', $plugin_admin, 'remove_collections_quick_edit', 10, 2 );
Expand Down
15 changes: 15 additions & 0 deletions src/scripts/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ import '../styles/admin.scss';
fields,
}
break
case 'generic':
data = {
action: 'widen_media_add_generic_file_to_library',
nonce: widen_media.ajax_nonce,
type,
ext,
id,
filename,
description,
url,
templatedUrl,
thumbnailUrl,
fields,
}
break
case 'video':
data = {
action: 'widen_media_add_video_to_library',
Expand Down

0 comments on commit b2075a1

Please sign in to comment.