Skip to content

Commit

Permalink
Merge pull request #37 from threadi/feature/addSwitchOfHostingForImages
Browse files Browse the repository at this point in the history
Feature/add switch of hosting for images
  • Loading branch information
threadi authored Aug 25, 2024
2 parents d9359ad + 49b3fc7 commit e734c2e
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 15 deletions.
44 changes: 44 additions & 0 deletions admin/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,50 @@ jQuery(document).ready(function($) {
});
});

/**
* Switch the hosting of an external file.
*/
$('.button.eml-change-host').on( 'click', function(e) {
e.preventDefault();

// secure object where the text should be changed.
let obj = $(this).parent().find('span.eml-hosting-state');

// get the ID of the file
let id = $("#post_ID").val();

// send request
jQuery.ajax({
url: emlJsVars.ajax_url,
type: 'post',
data: {
id: id,
action: 'eml_switch_hosting',
nonce: emlJsVars.switch_hosting_nonce
},
success: function (response) {
let dialog_config = {
detail: {
className: 'eml',
title: emlJsVars.title_hosting_changed,
texts: [
'<p>' + emlJsVars.text_hosting_has_been_changed + '</p>'
],
buttons: [
{
'action': 'location.reload();',
'variant': 'primary',
'text': emlJsVars.lbl_ok
},
]
}
}
obj.html(response.message);
eml_create_dialog( dialog_config );
}
});
})

// save to hide transient-messages via ajax-request
$('div[data-dismissible] button.notice-dismiss').on('click',
function (event) {
Expand Down
6 changes: 4 additions & 2 deletions admin/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ body.settings_page_eml_settings .nav-tab-help:before {
vertical-align: middle;
}

#eml_recheck_availability {
.misc-pub-external-file .button {
padding: 0 1em;
vertical-align: middle;
}

#eml_recheck_availability:before {
.misc-pub-external-file .button:before {
position: relative;
left: -6px;
}

.wp-list-table.media #external_files { width: 120px }
6 changes: 3 additions & 3 deletions classes/eml/Controller/class-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Cli {
public function import( array $urls = array() ): void {
if ( ! empty( $urls ) ) {
foreach ( $urls as $url ) {
$file_obj = external_files::get_instance();
$file_obj = External_Files::get_instance();
if ( $file_obj->add_file( $url ) ) {
\WP_CLI::success( $url . ' has been saved in media library.' );
} else {
Expand All @@ -60,7 +60,7 @@ public function delete(): void {
$logs->create( 'All external files will be deleted via cli.', '', 'success', 2 );

// get external files object.
$external_files_obj = external_files::get_instance();
$external_files_obj = External_Files::get_instance();

// get all files created by this plugin in media library.
$files = $external_files_obj->get_files_in_media_library();
Expand Down Expand Up @@ -101,7 +101,7 @@ public function clear_log(): void {
*/
public function check(): void {
// get object for external files.
$external_files_obj = external_files::get_instance();
$external_files_obj = External_Files::get_instance();

// run check for all files.
$external_files_obj->check_files();
Expand Down
2 changes: 1 addition & 1 deletion classes/eml/Model/class-external-file.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public function is_image(): bool {
* @return bool
*/
public function is_locally_saved(): bool {
return (bool) get_post_meta( $this->get_id(), 'eml_locally_saved', true );
return 1 === absint( get_post_meta( $this->get_id(), 'eml_locally_saved', true ) );
}

/**
Expand Down
12 changes: 12 additions & 0 deletions classes/eml/class-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,16 @@ public static function get_content_type_from_string( string $content_type ): str
}
return $content_type;
}

/**
* Checks whether a given plugin is active.
*
* Used because WP's own function is_plugin_active() is not accessible everywhere.
*
* @param string $plugin Path to the plugin.
* @return bool
*/
public static function is_plugin_active( string $plugin ): bool {
return in_array( $plugin, (array) get_option( 'active_plugins', array() ), true );
}
}
Loading

0 comments on commit e734c2e

Please sign in to comment.