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(); }