Commit 68e4e49d authored by Felix Ender's avatar Felix Ender

- found permanent workaround for wordpress page editor bug

- fixed some issues with htaccess generation and rule order
- disabled focuspoint setting for multi image select
parent 0b48688b
......@@ -2,12 +2,15 @@
class ecImageAdmin {
private static $deactivation = false;
public static function init () {
add_action( 'init', array(ecImageAdmin, 'onInit') );
add_action( 'after_setup_theme', array(ecImageAdmin, 'registerImageSizes'));
add_action( 'wp_get_attachment_metadata', array(ecImageAdmin, 'attachmentMetadataHook'), 10, 2);
add_action( 'ecimage_license_cron', array(ecImageLicense, 'cron') );
add_action( 'mod_rewrite_rules', array(ecImageAdmin, 'modRewriteRulesHook'));
if ( is_admin() ) {
self::initAdmin();
......@@ -56,20 +59,13 @@ class ecImageAdmin {
}
public static function onActivation () {
global $wp_version;
if (!self::updateHtaccess()) {
error_log('ecimage: htaccess write Failed');
}
if ( version_compare( $wp_version, '5.0', '>=' ) ) {
update_option('ecimage_wa_sizes_select', 1, false);
}
save_mod_rewrite_rules();
wp_schedule_event(time(), 'daily', 'ecimage_license_cron');
}
public static function onDeactivation () {
if (!self::clearHtaccess()) {
error_log('ecimage: htaccess write Failed');
}
self::$deactivation = true;
save_mod_rewrite_rules();
self::clearCache();
wp_clear_scheduled_hook( 'ecimage_license_cron' );
}
......@@ -183,7 +179,7 @@ class ecImageAdmin {
continue;
}
add_image_size( 'ecimage_'.$size->taxonomie, $size->width, $size->height, array('ecimage',$size->ID));
add_image_size( 'ecimage_'.$size->taxonomie, $size->width, $size->height, false);
}
......@@ -191,11 +187,6 @@ class ecImageAdmin {
public static function imageSizeNamesChooseHook ( $sizes ) {
if (!empty(get_option( 'ecimage_wa_sizes_select', 0 ))) {
// if sizes are disabled in settings due to en bug in the new page editor.
return $sizes;
}
$mySizes = array();
foreach (self::getSizesList() AS $taxonomie => $label ) {
......@@ -254,6 +245,21 @@ class ecImageAdmin {
}
public static function modRewriteRulesHook ($rules) {
if (self::$deactivation) {
return $rules;
}
$rules_arr = explode( "\n", $rules );
$new = array();
foreach ($rules_arr AS $r) {
$new[] = $r;
if ($r == 'RewriteRule ^index\.php$ - [L]') {
$new = array_merge($new, self::getHtaccessLines());
}
}
return implode("\n", $new);
}
public static function editMediaCustomField ($fields, $post) {
if (!in_array($post->post_mime_type, ecImageProvider::SUPPORTED_MIMETYPE)) {
return;
......
......@@ -33,17 +33,15 @@ class ecImageDatabase {
}
public static function getSizeIDs () {
global $wpdb;
$data = array();
$args = array( 'post_type' => ecImageSize::$post_type);
$result = new WP_Query( $args );
while ( $result->have_posts() ) {
$result->the_post();
$data[] = get_the_ID();
$sizes = $wpdb->get_results( $sql = $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_type = '%s'", ecImageSize::$post_type ) );
foreach ($sizes AS $size) {
$data[] = $size->ID;
}
wp_reset_postdata();
return $data;
......
......@@ -34,7 +34,6 @@ class ecImageI18n {
private static $label_cachesize = 'Cache Size';
private static $label_clearcache = 'Clear Cache';
private static $label_overrides = 'Overrides';
private static $label_wa_sizes_select = 'Sizes Bug Workaround';
private static $label_overrides_tabel_size = 'size';
private static $label_overrides_tabel_nogen = 'prevent generation';
private static $label_overrides_tabel_override = 'override size';
......@@ -62,7 +61,6 @@ class ecImageI18n {
/* help texts */
private static $help_focus = 'Set the Point the Image should be cropped to.';
private static $help_clearcache = 'Select this to Clear the Cache on save.';
private static $help_workaround_sizes = 'This is a Workaround for a Bug inside the new Page Editor.<br>If you add your custom Image Sizes to the size names array you will get a blank page for the site editor.<br>If you check this, I will not add the custom Sizes to the array so you can use the Editor.<br>There is an Plugin called "Classic Editor" that will let you use the classic editor without this bug.';
private static $help_taxonomie = 'Must be unique as it is used as a suffix to identify the image size';
private static $help_checklicense = 'Select this to Check license on save.';
......
......@@ -45,8 +45,6 @@ class ecImageSettings {
}
public static function registerSettingsWorkaround () {
register_setting( 'ecimage_settings', 'ecimage_wa_sizes_select', array('type' => 'boolean') );
ecImageSettingsFields::addSettingsField('wa_sizes_select', ecImageI18n::get('label_wa_sizes_select'), 'settings', 'general');
}
/*
......
......@@ -103,14 +103,4 @@ class ecImageSettingsFields {
}
public static function printWa_sizes_select () {
$val = esc_html(get_option( 'ecimage_wa_sizes_select', 0 ));
$checked = '';
if ( !empty($val) ) {
$checked = 'checked="checked"';
}
print '<input type="hidden" name="ecimage_wa_sizes_select" value="0"><input type="checkbox" name="ecimage_wa_sizes_select" value="1" '.$checked.'>'.
'<p class="help"><i style="color:red;">'.ecImageI18n::get('snippet_important').'</i>: '.ecImageI18n::get('help_workaround_sizes').'</p>';
}
}
<?php
/**
* @package ec_image
* @version 0.1.0
* @version 0.1.1
*/
/*
* Plugin Name: ec Image
......@@ -9,7 +9,7 @@
* Plugin URI:
* Description: Managing and Optimizing your Imagesizes easy, fast and on demand
* Author: Felix Ender
* Version: 0.1.0
* Version: 0.1.1
* Author URI: http://ender.center/
*/
......@@ -21,7 +21,7 @@ if ( is_admin() ) {
$uploadDir['baseurl_parsed'] = parse_url($uploadDir['baseurl']);
define('ecImage_base_dir', plugin_dir_path(__FILE__));
define('ecImage_base_url', plugins_url('ec-image/'));
define('ecImage_base_url', plugins_url( basename(dirname(__FILE__)) . '/' ));
define('ecImage_upload_dir', $uploadDir['basedir'] . '/ec-image/');
define('ecImage_tmp_dir', $uploadDir['basedir'] . '/ec-image/tmp/');
......
......@@ -73,6 +73,11 @@ jQuery(function(){
inputX.parents('form').submit();
};
var hide = function () {
reset();
jQuery('.compat-field-ecimage-focus').addClass('hidden');
};
var reset = function () {
elCont = null;
elX = null;
......@@ -84,11 +89,15 @@ jQuery(function(){
this.init = function () {
reset();
jQuery('.ecimage-crosshair-switch').removeClass('hidden');
jQuery('.ecimage-crosshair-switch input').on('change', onCrosshairSwitch);
elImg = jQuery('.edit-attachment-frame .attachment-media-view .details-image');
if (elImg.length === 0) {
hide();
return;
}
inputX = jQuery('.ecimage-focus-form input.ecimage-focus-x').on('change',onInputChange);
inputY = jQuery('.ecimage-focus-form input.ecimage-focus-y').on('change',onInputChange);
jQuery('.ecimage-crosshair-switch').removeClass('hidden');
jQuery('.ecimage-crosshair-switch input').on('change', onCrosshairSwitch);
if (firstTime) {
jQuery(window).on('resize', setCrosshairPos);
} else if (elImg.parent().is('.ecimage-has-crosshair')) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment