From 9fd8a0e20fff09812685d4001435776903626ae3 Mon Sep 17 00:00:00 2001 From: Git I Hate You Date: Thu, 14 May 2020 14:51:17 +0200 Subject: [PATCH] Temp. commit: introduced the class UserImageEdit --- classes/Optimization/UserImageEdit.php | 67 ++++++++++++++++++++++++++ inc/classes/class-imagify-plugin.php | 4 +- 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 classes/Optimization/UserImageEdit.php diff --git a/classes/Optimization/UserImageEdit.php b/classes/Optimization/UserImageEdit.php new file mode 100644 index 000000000..bc6120256 --- /dev/null +++ b/classes/Optimization/UserImageEdit.php @@ -0,0 +1,67 @@ + [ + 'default' => 0, + 'min_range' => 0, + ], + ] + ); + + $action = filter_input( INPUT_POST, 'do', FILTER_SANITIZE_STRING ); + + if ( empty( $media_id ) || 'save' !== $action ) { + return; + } + + if ( ! current_user_can( 'edit_post', $media_id ) ) { + return; + } + + if ( ! check_ajax_referer( "image_editor-$media_id", false, false ) ) { + return; + } + + $process = imagify_get_optimization_process( $media_id, 'wp' ); + + if ( ! $process->is_valid() || ! $process->get_data()->is_optimized() ) { + // Nothing to do if the media is not optimized or invalid. + return; + } + + // Work here. + } +} diff --git a/inc/classes/class-imagify-plugin.php b/inc/classes/class-imagify-plugin.php index a04a2d4b5..1b5bb6624 100644 --- a/inc/classes/class-imagify-plugin.php +++ b/inc/classes/class-imagify-plugin.php @@ -65,7 +65,9 @@ class_alias( '\\Imagify\\Traits\\InstanceGetterTrait', '\\Imagify\\Traits\\FakeS \Imagify\Imagifybeat\Actions::get_instance()->init(); } - if ( ! wp_doing_ajax() ) { + if ( wp_doing_ajax() ) { + \Imagify\Optimization\UserImageEdit::get_instance()->init(); + } else { Imagify_Assets::get_instance()->init(); }