function wr2x_admin_init()
{
    if (isset($_POST) && isset($_POST['wr2x_pro'])) {
        wr2x_validate_pro($_POST['wr2x_pro']['subscr_id']);
    }
    $pro_status = get_option('wr2x_pro_status', "Not Pro.");
    require 'wr2x_class.settings-api.php';
    if (delete_transient('wr2x_flush_rules')) {
        global $wp_rewrite;
        wr2x_generate_rewrite_rules($wp_rewrite, true);
    }
    $sections = array(array('id' => 'wr2x_basics', 'title' => __('Basics', 'wp-retina-2x')), array('id' => 'wr2x_advanced', 'title' => __('Advanced', 'wp-retina-2x')), array('id' => 'wr2x_pro', 'title' => __('Pro', 'wp-retina-2x')));
    // Default Auto-Generate
    $auto_generate = wr2x_getoption('auto_generate', 'wr2x_basics', null);
    if ($auto_generate === null) {
        wr2x_setoption('auto_generate', 'wr2x_basics', 'on');
    }
    $wpsizes = wr2x_get_image_sizes();
    $sizes = array();
    foreach ($wpsizes as $name => $attr) {
        $sizes["{$name}"] = sprintf("<div style='float: left; text-align: right; margin-right: 5px; width: 20px;'>%s</div> <b>%s</b> <small>(Normal: %dx%d, Retina: %dx%d)</small>", wr2x_size_shortname($name), $name, $attr['width'], $attr['height'], $attr['width'] * 2, $attr['height'] * 2);
    }
    $fields = array('wr2x_basics' => array(array('name' => 'ignore_sizes', 'label' => __('Disabled Sizes', 'wp-retina-2x'), 'desc' => __('<br />The selected sizes will not have their retina equivalent generated.', 'wp-retina-2x'), 'type' => 'multicheck', 'options' => $sizes), array('name' => 'auto_generate', 'label' => __('Auto Generate', 'wp-retina-2x'), 'desc' => __('Generate retina images automatically when images are uploaded or re-generated.<br /><small>The \'Disabled Sizes\' will be skipped.</small>', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => true), array('name' => 'disable_responsive', 'label' => __('Disable Responsive<br/>(WP 4.4+)', 'wp-retina-2x'), 'desc' => __('Disable the Responsive Images feature of WordPress 4.4+.<br /><small>This feature can be quite messy for many websites as it creates a src-set automatically with all your image sizes in it. You can disable it completely here and get back control over your HTML as it is in the editor (while keeping the plugin adding Retina support, of course).</small>', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'disable_medium_large', 'label' => __('Disable Medium Large<br/>(WP 4.4+)', 'wp-retina-2x'), 'desc' => __('Disable the image size called "Medium Large" created by in WordPress 4.4+.<br /><small>You probably don\'t need this and it creates additional images. Be careful however, future themes might use it.</small>', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'full_size', 'label' => __('Full Size Retina (Pro)', 'wp-retina-2x'), 'desc' => __('Retina for the full-size image will be considered required.<br /><small>Checks for Full-Size retina will be enabled and upload features made available.</small>', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false)), 'wr2x_advanced' => array(array('name' => 'method', 'label' => __('Method', 'wp-retina-2x'), 'desc' => __('<br />In all cases (including "None"), Retina support will be added to the Responsive Images created by WP 4.4.<br />Check the <a href="http://apps.meow.fr/wp-retina-2x/retina-methods/">Retina Methods</a> page if you want to know more about those methods.', 'wp-retina-2x'), 'type' => 'radio', 'default' => 'Picturefill', 'options' => array('Picturefill' => __("Picturefill (Recommended)", 'wp-retina-2x'), 'retina.js' => __("Retina.js", 'wp-retina-2x'), 'HTML Rewrite' => __("IMG Rewrite", 'wp-retina-2x'), 'Retina-Images' => __("Retina-Images", 'wp-retina-2x'), 'none' => __("None", 'wp-retina-2x'))), array('name' => 'image_quality', 'label' => __('Quality', 'wp-retina-2x'), 'desc' => __('<br />Image Compression quality (between 0 and 100).<br />That doesn\'t always actually work depending on your hosting service.', 'wp-retina-2x'), 'type' => 'text', 'default' => 90), array('name' => 'debug', 'label' => __('Debug Mode', 'wp-retina-2x'), 'desc' => __('Retina images will be always displayed and a log file will be created. <br /><small>Please use it for testing purposes. It creates a <a href="' . plugins_url("wp-retina-2x") . '/wp-retina-2x.log">log file</a> in the plugin folder.</small>', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'cdn_domain', 'label' => __('Custom CDN Domain (Pro)', 'wp-retina-2x'), 'desc' => __('<br />If not empty, your site domain will be replaced with this CDN domain (PictureFill and HTML Rewrite only).', 'wp-retina-2x'), 'type' => 'text', 'default' => ""), array('name' => 'picture_fill', 'label' => '', 'desc' => __('<h2>For PictureFill</h2><small>Using "Keep IMG SRC" and "Use Lazysizes" is the perfect middle between SEO and Performance.<br />Since WP 4.4, the src-set is already created for post content. Those options will therefore only affect the images which are <u>not</u> in the post content.</small>', 'wp-retina-2x'), 'type' => 'html'), array('name' => 'picturefill_keep_src', 'label' => __('Keep IMG SRC (Pro)', 'wp-retina-2x'), 'desc' => __('Excellent for SEO. But Retina devices will get both normal and retina images.<br /><small>With PictureFill, <b>src</b> tags are replaced by <b>src-set</b> tags and consequently search engines might not be able to find and reference those images.</small>', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'picturefill_lazysizes', 'label' => __('Use Lazysizes (Pro)', 'wp-retina-2x'), 'desc' => __('Retina images will be loaded in a lazy way, when the visitor is getting close to them.<br /><small>HTML will be rewritten to support the lazysizes and the script will be also loaded. </small>', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'picturefill_noscript', 'label' => __('No Picturefill Script', 'wp-retina-2x'), 'desc' => __('The script for Picturefill will not be loaded.<br /><small>Only the browsers with src-set support (e.g. Chrome) will display images. You can also load the Picturefill script manually.</small>', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'admin_screens', 'label' => '', 'desc' => __('<h2>Admin Screens</h2>', 'wp-retina-2x'), 'type' => 'html'), array('name' => 'hide_retina_column', 'label' => __('Hide \'Retina\' column', 'wp-retina-2x'), 'desc' => __('Will hide the \'Retina Column\' from the Media Library.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'hide_retina_dashboard', 'label' => __('Hide Retina Dashboard', 'wp-retina-2x'), 'desc' => __('Doesn\'t show the Retina Dashboard menu and tools.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'retina_admin', 'label' => __('Admin in Retina', 'wp-retina-2x'), 'desc' => __('WordPress Admin will also be Retina.<br /><small>Some plugins (like NextGen) do not like Retina enabled in the admin.</small>', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'mobile', 'label' => '', 'desc' => __('<h2>Mobiles</h2>', 'wp-retina-2x'), 'type' => 'html'), array('name' => 'ignore_mobile', 'label' => __('Ignore Mobile', 'wp-retina-2x'), 'desc' => __('Doesn\'t deliver Retina images to mobiles.<br /><small>PictureFill doesn\'t support it and cache will also prevent it from working.</small>', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false)), 'wr2x_pro' => array(array('name' => 'pro', 'label' => '', 'desc' => __(sprintf('Status: %s<br /><br />With the Pro version, full support for the <b>Full Size Retina</b> will be added. You will also get a new and nice pop-up window with more <b>Details</b> in the Retina dashboard.', $pro_status), 'wp-retina-2x'), 'type' => 'html'), array('name' => 'subscr_id', 'label' => __('Serial', 'wp-retina-2x'), 'desc' => __('<br />Enter your serial or subscription ID here. If you don\'t have one yet, get one <a target="_blank" href="http://apps.meow.fr/wp-retina-2x/">right here</a>.', 'wp-retina-2x'), 'type' => 'text', 'default' => "")));
    global $wr2x_settings_api;
    $wr2x_settings_api = new WeDevs_Settings_API();
    $wr2x_settings_api->set_sections($sections);
    $wr2x_settings_api->set_fields($fields);
    $wr2x_settings_api->admin_init();
}
Пример #2
0
function wr2x_admin_init()
{
    if (isset($_POST) && isset($_POST['wr2x_pro'])) {
        wr2x_validate_pro($_POST['wr2x_pro']['subscr_id']);
    }
    $pro_status = get_option('wr2x_pro_status', "Not Pro.");
    require 'wr2x_class.settings-api.php';
    if (delete_transient('wr2x_flush_rules')) {
        global $wp_rewrite;
        wr2x_generate_rewrite_rules($wp_rewrite, true);
    }
    $sections = array(array('id' => 'wr2x_basics', 'title' => __('Basics', 'wp-retina-2x')), array('id' => 'wr2x_advanced', 'title' => __('Advanced', 'wp-retina-2x')), array('id' => 'wr2x_pro', 'title' => __('Pro', 'wp-retina-2x')));
    // Default Auto-Generate
    $auto_generate = wr2x_getoption('auto_generate', 'wr2x_basics', null);
    if ($auto_generate === null) {
        wr2x_setoption('auto_generate', 'wr2x_basics', 'on');
    }
    $wpsizes = wr2x_get_image_sizes();
    $sizes = array();
    foreach ($wpsizes as $name => $attr) {
        $sizes["{$name}"] = sprintf("%s (%dx%d)", $name, $attr['width'], $attr['height']);
    }
    $fields = array('wr2x_basics' => array(array('name' => 'ignore_sizes', 'label' => __('Disabled Sizes', 'wp-retina-2x'), 'desc' => __('<br />The selected sizes will not have their retina equivalent generated.', 'wp-retina-2x'), 'type' => 'multicheck', 'options' => $sizes), array('name' => 'auto_generate', 'label' => __('Auto Generate', 'wp-retina-2x'), 'desc' => __('Generate retina images automatically when images are uploaded or re-generated.<br />The \'Disabled Sizes\' will be skipped.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => true), array('name' => 'full_size', 'label' => __('Full Size Retina (Pro)', 'wp-retina-2x'), 'desc' => __('Retina for the full-size image will be considered required.<br />Checks and upload feature are available.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false)), 'wr2x_advanced' => array(array('name' => 'method', 'label' => __('Method', 'wp-retina-2x'), 'desc' => __('<br />Check the <a href="http://apps.meow.fr/wp-retina-2x/">plugin official page</a> if you want to know more about the methods to deliver the retina images.', 'wp-retina-2x'), 'type' => 'radio', 'default' => 'Picturefill', 'options' => array('Picturefill' => __("Picturefill (Recommended)", 'wp-retina-2x'), 'retina.js' => __("Retina.js", 'wp-retina-2x'), 'HTML Rewrite' => __("IMG Rewrite", 'wp-retina-2x'), 'Retina-Images' => __("Retina-Images", 'wp-retina-2x'), 'none' => __("None", 'wp-retina-2x'))), array('name' => 'image_quality', 'label' => __('Quality', 'wp-retina-2x'), 'desc' => __('<br />Image Compression quality (between 0 and 100).<br />That doesn\'t always actually work depending on your hosting service.', 'wp-retina-2x'), 'type' => 'text', 'default' => 90), array('name' => 'debug', 'label' => __('Debug Mode', 'wp-retina-2x'), 'desc' => __('If checked, the client will be always served Retina images. <br />Please use it for testing purposes. It creates a <a href="' . plugins_url("wp-retina-2x") . '/wp-retina-2x.log">log file</a> in the plugin folder.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'cdn_domain', 'label' => __('Custom CDN Domain (Pro)', 'wp-retina-2x'), 'desc' => __('<br />If not empty, your site domain will be replaced with this CDN domain (PictureFill and HTML Rewrite only).', 'wp-retina-2x'), 'type' => 'text', 'default' => ""), array('name' => 'picture_fill', 'label' => '', 'desc' => __('<h2>For PictureFill</h2>', 'wp-retina-2x'), 'type' => 'html'), array('name' => 'picturefill_keep_src', 'label' => __('Keep IMG SRC (Pro)', 'wp-retina-2x'), 'desc' => __('With PictureFill, <b>src</b> tags are replaced by <b>src-set</b> tags and consequently search engines might not be able to find and reference those images. Keeping it will load images twice for retina devices on old browsers.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'picturefill_lazysizes', 'label' => __('Use Lazysizes (Pro)', 'wp-retina-2x'), 'desc' => __('HTML will be rewritten to support the lazysizes and the script will be also loaded. The images will be loaded in a lazy way (when the visitor is getting close to them).', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'picturefill_noscript', 'label' => __('No Picturefill Script', 'wp-retina-2x'), 'desc' => __('The script for Picturefill will not be loaded. Only the browsers with src-set support (e.g. Chrome) will display images. You can also load the Picturefill script manually.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'admin_screens', 'label' => '', 'desc' => __('<h2>Admin Screens</h2>', 'wp-retina-2x'), 'type' => 'html'), array('name' => 'hide_retina_column', 'label' => __('Hide \'Retina\' column', 'wp-retina-2x'), 'desc' => __('Will hide the \'Retina Column\' from the Media Library.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'hide_retina_dashboard', 'label' => __('Hide Retina Dashboard', 'wp-retina-2x'), 'desc' => __('Doesn\'t show the Retina Dashboard menu and tools.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'retina_admin', 'label' => __('Admin in Retina', 'wp-retina-2x'), 'desc' => __('If checked, the WordPress Admin will also be Retina. Some plugins (like NextGen) do not like Retina enabled in the admin.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'mobile', 'label' => '', 'desc' => __('<h2>Mobiles</h2>', 'wp-retina-2x'), 'type' => 'html'), array('name' => 'ignore_mobile', 'label' => __('Ignore Mobile', 'wp-retina-2x'), 'desc' => __('Doesn\'t deliver Retina images to mobiles.<br />PictureFill doesn\'t support it and cache will also prevent it from working.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false)), 'wr2x_pro' => array(array('name' => 'pro', 'label' => '', 'desc' => __(sprintf('Status: %s<br /><br />With the Pro version, full support for the <b>Full Size Retina</b> will be added. You will also get a new and nice pop-up window with more <b>Details</b> in the Retina dashboard.', $pro_status), 'wp-retina-2x'), 'type' => 'html'), array('name' => 'subscr_id', 'label' => __('Serial', 'wp-retina-2x'), 'desc' => __('<br />Enter your serial or subscription ID here. If you don\'t have one yet, get one <a target="_blank" href="http://apps.meow.fr/wp-retina-2x/">right here</a>.', 'wp-retina-2x'), 'type' => 'text', 'default' => "")));
    global $wr2x_settings_api;
    $wr2x_settings_api = new WeDevs_Settings_API();
    $wr2x_settings_api->set_sections($sections);
    $wr2x_settings_api->set_fields($fields);
    $wr2x_settings_api->admin_init();
}
Пример #3
0
function wr2x_admin_init()
{
    require 'wr2x_class.settings-api.php';
    if (delete_transient('wr2x_flush_rules')) {
        global $wp_rewrite;
        wr2x_generate_rewrite_rules($wp_rewrite, true);
    }
    $sections = array(array('id' => 'wr2x_basics', 'title' => __('Basics', 'wp-retina-2x')), array('id' => 'wr2x_advanced', 'title' => __('Advanced', 'wp-retina-2x')));
    $wpsizes = wr2x_get_image_sizes();
    $sizes = array();
    foreach ($wpsizes as $name => $attr) {
        $sizes["{$name}"] = sprintf("%s (%dx%d)", $name, $attr['width'], $attr['height']);
    }
    $fields = array('wr2x_basics' => array(array('name' => 'ignore_sizes', 'label' => __('Disabled Sizes', 'wp-retina-2x'), 'desc' => __('<br />The selected sizes will not have their retina equivalent generated.', 'wp-retina-2x'), 'type' => 'multicheck', 'options' => $sizes), array('name' => 'auto_generate', 'label' => __('Auto Generate', 'wp-retina-2x'), 'desc' => __('Generate Retina images automatically when images are uploaded to the Media Library.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false)), 'wr2x_advanced' => array(array('name' => 'method', 'label' => __('Method', 'wp-retina-2x'), 'desc' => __('<br />
                        The <b>Picturefill</b> method rewrites the HTML on-the-fly in order to use the new SRCSET. Since it is not supported by the browsers yet, the JS polyfill <a href="http://scottjehl.github.io/picturefill/">Picturefill</a> is used to load the images. <b>It is now the recommended method.</b><br /><br />
                        The <b>IMG Rewrite</b> method rewrites IMG\'s SRC tags on-the-fly with the retina images directly if the device supports them. This method does not work with most caching solutions.<br /><br />
                        The <b>Retina JS</b> method is a 100% JS solution. The HTML loads the normal images, then if a retina device is detected, the retina images will be loaded. It is fail-safe but not efficient (images are loaded twice).<br /><br />                        
                        The <b>Retina-Images method</b> uses a server handler: the images will be loaded through the <a href="https://github.com/Retina-Images/Retina-Images/">Retina-Images</a> PHP handler. Your .htaccess will be modified automatically. It might be too difficult to set-up if it does not work right away.<br /><br />
                	', 'wp-retina-2x'), 'type' => 'radio', 'default' => 'retina.js', 'options' => array('Picturefill' => __("Picturefill", 'wp-retina-2x'), 'HTML Rewrite' => __("IMG Rewrite", 'wp-retina-2x'), 'retina.js' => __("Retina.js", 'wp-retina-2x'), 'Retina-Images' => __("Retina-Images", 'wp-retina-2x'), 'none' => __("None", 'wp-retina-2x'))), array('name' => 'image_quality', 'label' => __('Quality', 'wp-retina-2x'), 'desc' => __('Image Compression quality (between 0 and 100).', 'wp-retina-2x'), 'type' => 'text', 'default' => 90), array('name' => 'debug', 'label' => __('Debug Mode', 'wp-retina-2x'), 'desc' => __('If checked, the client will be always served Retina images. <br />Please use it for testing purposes. It also generates a <a href="' . plugins_url("wp-retina-2x") . '/wp-retina-2x.log">log file</a> in the plugin folder.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'hide_retina_column', 'label' => __('Hide \'Retina\' column', 'wp-retina-2x'), 'desc' => __('Will hide the \'Retina Column\' from the Media Library.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'hide_retina_dashboard', 'label' => __('Hide Retina Dashboard', 'wp-retina-2x'), 'desc' => __('Doesn\'t show the Retina Dashboard menu and tools.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'ignore_mobile', 'label' => __('Ignore Mobile', 'wp-retina-2x'), 'desc' => __('Doesn\'t deliver Retina images to mobiles.<br />Does not work with Picturefill since it is managed by an external JS.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false)));
    global $wr2x_settings_api;
    $wr2x_settings_api = new WeDevs_Settings_API();
    $wr2x_settings_api->set_sections($sections);
    $wr2x_settings_api->set_fields($fields);
    $wr2x_settings_api->admin_init();
}
Пример #4
0
function wr2x_admin_init()
{
    require 'wr2x_class.settings-api.php';
    if (delete_transient('wr2x_flush_rules')) {
        global $wp_rewrite;
        wr2x_generate_rewrite_rules($wp_rewrite, true);
    }
    $sections = array(array('id' => 'wr2x_basics', 'title' => __('Basics', 'wp-retina-2x')), array('id' => 'wr2x_advanced', 'title' => __('Advanced', 'wp-retina-2x')));
    $wpsizes = wr2x_get_image_sizes();
    $sizes = array();
    foreach ($wpsizes as $name => $attr) {
        $sizes["{$name}"] = sprintf("%s (%dx%d)", $name, $attr['width'], $attr['height']);
    }
    $fields = array('wr2x_basics' => array(array('name' => 'ignore_sizes', 'label' => __('Disabled Sizes', 'wp-retina-2x'), 'desc' => __('The checked sizes will not be generated for Retina displays.', 'wp-retina-2x'), 'type' => 'multicheck', 'options' => $sizes), array('name' => 'auto_generate', 'label' => __('Auto Generate', 'wp-retina-2x'), 'desc' => __('Generate Retina images automatically when images are uploaded to the Media Library.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false)), 'wr2x_advanced' => array(array('name' => 'method', 'label' => __('Method', 'wp-retina-2x'), 'desc' => __('<br />
                        The <b>HTML srcset method</b> is the best. The HTML will be rewritten with <a href="http://www.w3.org/html/wg/drafts/srcset/w3c-srcset/">the srcset attribute</a> added to the img tags. Works with caching. Unfortunately, not all the browsers support it yet.<br /><br />
                		The <b>HTML Rewrite method</b> is one of the best methods. It replaces the images by the retina images - if available - in the HTML directly. It\'s tricky to use HTML caching with it however.<br /><br />               		
                		The <b>Retina.js method</b> is fail-safe and only uses one <a href="https://github.com/imulus/retinajs/">JavaScript file</a>. When a Retina Display is detected, requests for every images on the page will be sent to the server and the retina images will be retrieved if available. Requires a lot of bandwidth.<br /><br />
                        The <b>Retina-Images method</b> is efficient. The images will go through the <a href="https://github.com/Retina-Images/Retina-Images/">Retina-Images</a> handler. Caching systems might be an issue.
                	', 'wp-retina-2x'), 'type' => 'radio', 'default' => 'retina.js', 'options' => array('srcset' => __("HTML srcset (W3C Draft)", 'wp-retina-2x'), 'HTML Rewrite' => __("HTML Rewrite", 'wp-retina-2x'), 'retina.js' => __("Retina.js", 'wp-retina-2x'), 'Retina-Images' => __("Retina-Images", 'wp-retina-2x'), 'none' => __("None", 'wp-retina-2x'))), array('name' => 'image_quality', 'label' => __('Quality', 'wp-retina-2x'), 'desc' => __('Image Compression quality (between 0 and 100).', 'wp-retina-2x'), 'type' => 'text', 'default' => 90), array('name' => 'debug', 'label' => __('Debug Mode', 'wp-retina-2x'), 'desc' => __('If checked, the client will be always served Retina images. Convenient for testing.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'hide_retina_column', 'label' => __('Hide \'Retina\' column', 'wp-retina-2x'), 'desc' => __('Will hide the \'Retina Column\' from the Media Library.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'hide_retina_dashboard', 'label' => __('Hide Retina Dashboard', 'wp-retina-2x'), 'desc' => __('Doesn\'t show the Retina Dashboard menu and tools.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false), array('name' => 'ignore_mobile', 'label' => __('Ignore Mobile', 'wp-retina-2x'), 'desc' => __('Doesn\'t deliver Retina images to mobiles.', 'wp-retina-2x'), 'type' => 'checkbox', 'default' => false)));
    $settings_api = wr2x_WeDevs_Settings_API::getInstance();
    $settings_api->set_sections($sections);
    $settings_api->set_fields($fields);
    $settings_api->admin_init();
}
Пример #5
0
function wr2x_generate_images($meta)
{
    require 'wr2x_vt_resize.php';
    global $_wp_additional_image_sizes;
    $sizes = wr2x_get_image_sizes();
    if (!isset($meta['file'])) {
        return;
    }
    $originalfile = $meta['file'];
    $uploads = wp_upload_dir();
    $pathinfo = pathinfo($originalfile);
    $original_basename = $pathinfo['basename'];
    $basepath = trailingslashit($uploads['basedir']) . $pathinfo['dirname'];
    $ignore = wr2x_getoption("ignore_sizes", "wr2x_basics", array());
    $issue = false;
    $id = wr2x_get_attachment_id($meta['file']);
    wr2x_log("* GENERATE RETINA FOR ATTACHMENT '{$meta['file']}'");
    wr2x_log("Full-Size is {$original_basename}.");
    foreach ($sizes as $name => $attr) {
        $normal_file = "";
        if (in_array($name, $ignore)) {
            wr2x_log("Retina for {$name} ignored (settings).");
            continue;
        }
        // Is the file related to this size there?
        $pathinfo = null;
        $retina_file = null;
        if (isset($meta['sizes'][$name]) && isset($meta['sizes'][$name]['file'])) {
            $normal_file = trailingslashit($basepath) . $meta['sizes'][$name]['file'];
            $pathinfo = pathinfo($normal_file);
            $retina_file = trailingslashit($pathinfo['dirname']) . $pathinfo['filename'] . wr2x_retina_extension() . $pathinfo['extension'];
        }
        if ($retina_file && file_exists($retina_file)) {
            wr2x_log("Base for {$name} is '{$normal_file}'.");
            wr2x_log("Retina for {$name} already exists: '{$retina_file}'.");
            continue;
        }
        if ($retina_file) {
            $originalfile = trailingslashit($pathinfo['dirname']) . $original_basename;
            if (!file_exists($originalfile)) {
                wr2x_log("[ERROR] Original file '{$originalfile}' cannot be found.");
                return $meta;
            }
            // Maybe that new image is exactly the size of the original image.
            // In that case, let's make a copy of it.
            if ($meta['sizes'][$name]['width'] * 2 == $meta['width'] && $meta['sizes'][$name]['height'] * 2 == $meta['height']) {
                copy($originalfile, $retina_file);
                wr2x_log("Retina for {$name} created: '{$retina_file}' (as a copy of the full-size).");
            } else {
                if (wr2x_are_dimensions_ok($meta['width'], $meta['height'], $meta['sizes'][$name]['width'] * 2, $meta['sizes'][$name]['height'] * 2)) {
                    // Change proposed by Nicscott01, slighlty modified by Jordy (+isset)
                    // (https://wordpress.org/support/topic/issue-with-crop-position?replies=4#post-6200271)
                    $crop = isset($_wp_additional_image_sizes[$name]) ? $_wp_additional_image_sizes[$name]['crop'] : true;
                    $customCrop = null;
                    // Support for Manual Image Crop
                    // If the size of the image was manually cropped, let's keep it.
                    if (class_exists('ManualImageCrop') && isset($meta['micSelectedArea']) && isset($meta['micSelectedArea'][$name]) && isset($meta['micSelectedArea'][$name]['scale'])) {
                        $customCrop = $meta['micSelectedArea'][$name];
                    }
                    $image = wr2x_vt_resize($originalfile, $meta['sizes'][$name]['width'] * 2, $meta['sizes'][$name]['height'] * 2, $crop, $retina_file, $customCrop);
                }
            }
            if (!file_exists($retina_file)) {
                wr2x_log("[ERROR] Retina for {$name} could not be created. Full-Size is " . $meta['width'] . "x" . $meta['height'] . " but Retina requires a file of at least " . $meta['sizes'][$name]['width'] * 2 . "x" . $meta['sizes'][$name]['height'] * 2 . ".");
                $issue = true;
            } else {
                do_action('wr2x_retina_file_added', $id, $retina_file);
                wr2x_log("Retina for {$name} created: '{$retina_file}'.");
            }
        } else {
            if (empty($normal_file)) {
                wr2x_log("[ERROR] Base file for '{$name}' does not exist.");
            } else {
                wr2x_log("[ERROR] Base file for '{$name}' cannot be found here: '{$normal_file}'.");
            }
        }
    }
    // Checks attachment ID + issues
    if (!$id) {
        return $meta;
    }
    if ($issue) {
        wr2x_add_issue($id);
    } else {
        wr2x_remove_issue($id);
    }
    return $meta;
}
function wpr2x_wp_retina_2x()
{
    $view = isset($_GET['view']) ? $_GET['view'] : 'issues';
    $paged = isset($_GET['paged']) ? $_GET['paged'] : 1;
    $s = isset($_GET['s']) ? $_GET['s'] : null;
    $issues = $count = 0;
    $sizes = wr2x_get_image_sizes();
    $posts_per_page = 15;
    // TODO: HOW TO GET THE NUMBER OF MEDIA PER PAGES? IT IS NOT get_option('posts_per_page');
    $issues = wr2x_get_issues();
    $ignored = wr2x_get_ignores();
    ?>
	<div class='wrap'>
	<?php 
    jordy_meow_donation(true);
    ?>
	<div id="icon-upload" class="icon32"><br></div>
	<h2>WP Retina 2x <?php 
    by_jordy_meow();
    ?>
</h2>

	<?php 
    if ($view == 'issues') {
        global $wpdb;
        $totalcount = $wpdb->get_var($wpdb->prepare("\n\t\t\tSELECT COUNT(*)\n\t\t\tFROM {$wpdb->posts} p\n\t\t\tWHERE post_status = 'inherit'\n\t\t\tAND post_type = 'attachment'\n\t\t\tAND post_title LIKE %s\n\t\t\tAND ( post_mime_type = 'image/jpeg' OR\n\t\t\tpost_mime_type = 'image/png' OR\n\t\t\tpost_mime_type = 'image/gif' )\n\t\t", '%' . $s . '%'));
        $postin = count($issues) < 1 ? array(-1) : $issues;
        $query = new WP_Query(array('post_status' => 'inherit', 'post_type' => 'attachment', 'post__in' => $postin, 'paged' => $paged, 'posts_per_page' => $posts_per_page, 's' => $s));
    } else {
        if ($view == 'ignored') {
            global $wpdb;
            $totalcount = $wpdb->get_var($wpdb->prepare("\n\t\t\tSELECT COUNT(*)\n\t\t\tFROM {$wpdb->posts} p\n\t\t\tWHERE post_status = 'inherit'\n\t\t\tAND post_type = 'attachment'\n\t\t\tAND post_title LIKE %s\n\t\t\tAND ( post_mime_type = 'image/jpeg' OR\n\t\t\tpost_mime_type = 'image/jpg' OR\n\t\t\tpost_mime_type = 'image/png' OR\n\t\t\tpost_mime_type = 'image/gif' )\n\t\t", '%' . $s . '%'));
            $postin = count($ignored) < 1 ? array(-1) : $ignored;
            $query = new WP_Query(array('post_status' => 'inherit', 'post_type' => 'attachment', 'post__in' => $postin, 'paged' => $paged, 'posts_per_page' => $posts_per_page, 's' => $s));
        } else {
            $query = new WP_Query(array('post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image/jpeg,image/gif,image/jpg,image/png', 'paged' => $paged, 'posts_per_page' => $posts_per_page, 's' => $s));
            //$s
            $totalcount = $query->found_posts;
        }
    }
    $issues_count = count($issues);
    // If 'search', then we need to clean-up the issues count
    if ($s && $issues_count > 0) {
        global $wpdb;
        $issues_count = $wpdb->get_var($wpdb->prepare("\n\t\t\tSELECT COUNT(*)\n\t\t\tFROM {$wpdb->posts} p\n\t\t\tWHERE id IN ( " . implode(',', $issues) . " )\n\t\t\tAND post_title LIKE %s\n\t\t", '%' . $s . '%'));
    }
    $results = array();
    $count = $query->found_posts;
    $pagescount = $query->max_num_pages;
    foreach ($query->posts as $post) {
        $info = wr2x_retina_info($post->ID);
        array_push($results, array('post' => $post, 'info' => $info));
    }
    ?>

	<div style='background: #FFF; padding: 5px; border-radius: 4px; height: 28px; box-shadow: 0px 0px 6px #C2C2C2;'>
		
		<!-- GENERATE ALL -->
		<a id='wr2x_generate_button_all' onclick='wr2x_generate_all()' class='button-primary' style='float: left;'><img style='position: relative; top: 3px; left: -2px; margin-right: 3px; width: 16px; height: 16px;' src='<?php 
    echo trailingslashit(WP_PLUGIN_URL) . trailingslashit('wp-retina-2x/img');
    ?>
photo-album--plus.png' /><?php 
    _e("Generate", 'wp-retina-2x');
    ?>
</a>
		
		<!-- SEARCH -->
		<form id="posts-filter" action="upload.php" method="get">
			<p class="search-box" style='margin-left: 5px; float: left;'>
				<input type="search" name="s" value="<?php 
    echo $s ? $s : "";
    ?>
">
				<input type="hidden" name="page" value="wp-retina-2x">
				<input type="hidden" name="view" value="<?php 
    echo $view;
    ?>
">
				<input type="hidden" name="paged" value="<?php 
    echo $paged;
    ?>
">
				<input type="submit" class="button" value="Search">
			</p>
		</form>

		<!-- REMOVE BUTTON ALL -->
		<a id='wr2x_remove_button_all' onclick='wr2x_delete_all()' class='button button-red' style='float: right;'><img style='position: relative; top: 3px; left: -2px; margin-right: 3px; width: 16px; height: 16px;' src='<?php 
    echo trailingslashit(WP_PLUGIN_URL) . trailingslashit('wp-retina-2x/img');
    ?>
burn.png' /><?php 
    _e("Delete all @2x", 'wp-retina-2x');
    ?>
</a>

		<!-- REFRESH -->
		<a id='wr2x_refresh' href='?page=wp-retina-2x&view=issues&refresh=true' class='button-primary' style='float: right; margin-right: 5px;'><img style='position: relative; top: 3px; left: -2px; margin-right: 3px; width: 16px; height: 16px;' src='<?php 
    echo trailingslashit(WP_PLUGIN_URL) . trailingslashit('wp-retina-2x/img');
    ?>
refresh.png' /><?php 
    _e("Refresh issues", 'wp-retina-2x');
    ?>
</a>

		<!-- PROGRESS -->
		<span style='margin-left: 12px; font-size: 15px; top: 5px; position: relative; color: #747474;' id='wr2x_progression'></span>
		
	</div>

	<?php 
    if (isset($_GET['refresh']) ? $_GET['refresh'] : 0) {
        echo "<div class='updated' style='margin-top: 20px;'><p>";
        _e("Issues has been refreshed.", 'wp-retina-2x');
        echo "</p></div>";
    }
    ?>
	
	<p><?php 
    _e("You can upload/replace the images by drag & drop on the grid.", 'wp-retina-2x');
    ?>
</p>

	<div id='wr2x-pages'>
	<?php 
    echo paginate_links(array('base' => '?page=wp-retina-2x&s=' . urlencode($s) . '&view=' . $view . '%_%', 'current' => $paged, 'format' => '&paged=%#%', 'total' => $pagescount, 'prev_next' => false));
    ?>
	</div>
	
	<ul class="subsubsub">
		<li class="all"><a <?php 
    if ($view == 'all') {
        echo "class='current'";
    }
    ?>
 href='?page=wp-retina-2x&s=<?php 
    echo $s;
    ?>
&view=all'><?php 
    _e("All", 'wp-retina-2x');
    ?>
</a><span class="count">(<?php 
    echo $totalcount;
    ?>
)</span></li> |
		<li class="all"><a <?php 
    if ($view == 'issues') {
        echo "class='current'";
    }
    ?>
 href='?page=wp-retina-2x&s=<?php 
    echo $s;
    ?>
&view=issues'><?php 
    _e("Issues", 'wp-retina-2x');
    ?>
</a><span class="count">(<?php 
    echo $issues_count;
    ?>
)</span></li> |
		<li class="all"><a <?php 
    if ($view == 'ignored') {
        echo "class='current'";
    }
    ?>
 href='?page=wp-retina-2x&s=<?php 
    echo $s;
    ?>
&view=ignored'><?php 
    _e("Ignored", 'wp-retina-2x');
    ?>
</a><span class="count">(<?php 
    echo count($ignored);
    ?>
)</span></li>
	</ul>
	<table class='wp-list-table widefat fixed media'>
		<thead><tr>
			<?php 
    echo "<th style='width: 64px;''></th>";
    echo "<th style='font-size: 11px; font-family: Verdana;'>" . __("Title", 'wp-retina-2x') . "</th>";
    $ignore_cols = wr2x_getoption("ignore_sizes", "wr2x_basics", array());
    foreach ($sizes as $name => $attr) {
        if (!in_array($name, $ignore_cols)) {
            echo "<th style='width: 80px; font-size: 11px; font-family: Verdana;' class='manage-column'>" . $name . "</th>";
        }
    }
    echo "<th style='font-size: 11px; font-family: Verdana; width: 88px;'>" . __("Actions", 'wp-retina-2x') . "</th>";
    echo "<th style='font-size: 11px; font-family: Verdana; width: 70px;'></th>";
    ?>
		</tr></thead>
		<tbody>
			<?php 
    foreach ($results as $index => $attr) {
        $meta = wp_get_attachment_metadata($attr['post']->ID);
        // Let's clean the issues status
        if ($view != 'issues') {
            wr2x_update_issue_status($attr['post']->ID, $issues, $attr['info']);
        }
        if (isset($meta) && isset($meta['width'])) {
            $original_width = $meta['width'];
            $original_height = $meta['height'];
        }
        $attachmentsrc = wp_get_attachment_image_src($attr['post']->ID, 'thumbnail');
        echo "<tr class='wr2x-file-row' postId='" . $attr['post']->ID . "'>";
        echo "<td class='wr2x-image'><img style='max-width: 42px; max-height: 42px;' src='" . $attachmentsrc[0] . "' /></td>";
        echo "<td class='wr2x-title'><a style='position: relative; top: -2px;' href='media.php?attachment_id=" . $attr['post']->ID . "&action=edit'>" . $attr['post']->post_title . '<br />' . "<span style='font-size: 9px; line-height: 10px; display: block;'>" . $original_width . "×" . $original_height . "</span>";
        "</a></td>";
        foreach ($sizes as $aindex => $aval) {
            if (in_array($aindex, $ignore_cols)) {
                continue;
            }
            $aval = isset($attr['info']) && isset($attr['info'][$aindex]) ? $attr['info'][$aindex] : null;
            echo "<td id='wr2x_" . $aindex . "_" . $attr['post']->ID . "'>";
            if (is_array($aval)) {
                echo "<img title='Please upload a bigger original image.' style='margin-top: 3px; width: 16px; height: 16px;' src='" . trailingslashit(WP_PLUGIN_URL) . trailingslashit('wp-retina-2x/img') . "exclamation.png' />" . "<span style='font-size: 9px; margin-left: 5px; position: relative; top: -10px;'><br />< " . $aval['width'] . "×" . $aval['height'] . "</span>";
            } else {
                if ($aval == 'EXISTS') {
                    echo "<img style='margin-top: 3px; width: 16px; height: 16px;' src='" . trailingslashit(WP_PLUGIN_URL) . trailingslashit('wp-retina-2x/img') . "tick-circle.png' />";
                } else {
                    if ($aval == 'PENDING') {
                        echo "<img title='Click on \"Generate\".' style='margin-top: 3px; width: 16px; height: 16px;' src='" . trailingslashit(WP_PLUGIN_URL) . trailingslashit('wp-retina-2x/img') . "clock.png' />";
                    } else {
                        if ($aval == 'MISSING') {
                            echo "<img title='The file related to this size is missing.' style='margin-top: 3px; width: 16px; height: 16px;' src='" . trailingslashit(WP_PLUGIN_URL) . trailingslashit('wp-retina-2x/img') . "cross-small.png' />";
                        } else {
                            if ($aval == 'IGNORED') {
                                echo "<img title='Retina disabled.' style='margin-top: 3px; width: 16px; height: 16px;' src='" . trailingslashit(WP_PLUGIN_URL) . trailingslashit('wp-retina-2x/img') . "prohibition-small.png' />";
                            } else {
                                echo "<span style='position: relative; top: 3px;'>" . $aval . "</span>";
                            }
                        }
                    }
                }
            }
            echo "</td>";
        }
        echo "<td><a style='position: relative; top: 0px;' onclick='wr2x_generate(" . $attr['post']->ID . ", true)' id='wr2x_generate_button_" . $attr['post']->ID . "' class='button-secondary'>" . __("GENERATE", 'wp-retina-2x') . "</a></td>";
        if (!wr2x_is_ignore($attr['post']->ID)) {
            echo "<td><a style='position: relative; top: 0px;' href='?page=wp-retina-2x&view=" . $view . "&paged=" . $paged . "&ignore=" . $attr['post']->ID . "' id='wr2x_generate_button_" . $attr['post']->ID . "' class='button-secondary'>" . __("IGNORE", 'wp-retina-2x') . "</a></td>";
        }
        echo "</tr>";
    }
    ?>
		</tbody>
	</table>
	</div>

	<?php 
    jordy_meow_footer();
}
Пример #7
0
function wr2x_wp_ajax_wr2x_replace()
{
    $tmpfname = wr2x_check_get_ajax_uploaded_file();
    $attachmentId = (int) $_POST['attachmentId'];
    $meta = wp_get_attachment_metadata($attachmentId);
    $current_file = get_attached_file($attachmentId);
    wr2x_delete_attachment($attachmentId);
    $pathinfo = pathinfo($current_file);
    $basepath = $pathinfo['dirname'];
    // Let's clean everything first
    if (wp_attachment_is_image($attachmentId)) {
        $sizes = wr2x_get_image_sizes();
        foreach ($sizes as $name => $attr) {
            if (isset($meta['sizes'][$name]) && isset($meta['sizes'][$name]['file']) && file_exists(trailingslashit($basepath) . $meta['sizes'][$name]['file'])) {
                $normal_file = trailingslashit($basepath) . $meta['sizes'][$name]['file'];
                $pathinfo = pathinfo($normal_file);
                $retina_file = trailingslashit($pathinfo['dirname']) . $pathinfo['filename'] . wr2x_retina_extension() . $pathinfo['extension'];
                // Test if the file exists and if it is actually a file (and not a dir)
                // Some old WordPress Media Library are sometimes broken and link to directories
                if (file_exists($normal_file) && is_file($normal_file)) {
                    unlink($normal_file);
                }
                if (file_exists($retina_file) && is_file($retina_file)) {
                    unlink($retina_file);
                }
            }
        }
    }
    if (file_exists($current_file)) {
        unlink($current_file);
    }
    // Insert the new file and delete the temporary one
    rename($tmpfname, $current_file);
    chmod($current_file, 0644);
    // Generate the images
    wp_update_attachment_metadata($attachmentId, wp_generate_attachment_metadata($attachmentId, $current_file));
    $meta = wp_get_attachment_metadata($attachmentId);
    wr2x_generate_images($meta);
    // Get the results
    $info = wr2x_retina_info($attachmentId);
    $results[$attachmentId] = wpr2x_html_get_basic_retina_info($attachmentId, $info);
    echo json_encode(array('success' => true, 'results' => $results, 'message' => __("Replaced successfully.", 'wp-retina-2x')));
    die;
}
Пример #8
0
function wr2x_generate_images($meta)
{
    require 'wr2x_vt_resize.php';
    $sizes = wr2x_get_image_sizes();
    $originalfile = $meta['file'];
    $uploads = wp_upload_dir();
    $pathinfo = pathinfo($originalfile);
    $original_basename = $pathinfo['basename'];
    $basepath = trailingslashit($uploads['basedir']) . $pathinfo['dirname'];
    $ignore = wr2x_getoption("ignore_sizes", "wr2x_basics", array());
    $issue = false;
    $id = wr2x_get_attachment_id($meta['file']);
    wr2x_log("** RETINA INFO FOR ATTACHMENT '{$meta['file']}' **");
    wr2x_log("- Original: {$original_basename}");
    foreach ($sizes as $name => $attr) {
        if (in_array($name, $ignore)) {
            wr2x_log("- {$name} => IGNORED");
            continue;
        }
        // Is the file related to this size there?
        $pathinfo = null;
        $retina_file = null;
        if (isset($meta['sizes'][$name]) && isset($meta['sizes'][$name]['file'])) {
            $normal_file = trailingslashit($basepath) . $meta['sizes'][$name]['file'];
            $pathinfo = pathinfo($normal_file);
            $retina_file = trailingslashit($pathinfo['dirname']) . $pathinfo['filename'] . wr2x_retina_extension() . $pathinfo['extension'];
        }
        if ($retina_file && file_exists($retina_file)) {
            wr2x_log("- {$name}: {$normal_file} -> {$retina_file} => EXISTS");
            continue;
        }
        if ($retina_file) {
            $originalfile = trailingslashit($pathinfo['dirname']) . $original_basename;
            if (!file_exists($originalfile)) {
                wr2x_log("- The Original File '{$originalfile}' cannot be found.");
                return $meta;
            }
            // Maybe that new image is exactly the size of the original image.
            // In that case, let's make a copy of it.
            if ($meta['sizes'][$name]['width'] * 2 == $meta['width'] && $meta['sizes'][$name]['height'] * 2 == $meta['height']) {
                wr2x_log("- {$name}: {$originalfile} -> {$retina_file} => COPY");
                copy($originalfile, $retina_file);
            } else {
                if ($meta['sizes'][$name]['width'] * 2 <= $meta['width'] && $meta['sizes'][$name]['height'] * 2 <= $meta['height']) {
                    $image = wr2x_vt_resize($originalfile, $meta['sizes'][$name]['width'] * 2, $meta['sizes'][$name]['height'] * 2, $retina_file);
                }
            }
            if (!file_exists($retina_file)) {
                wr2x_log("- {$name}: {$normal_file} -> {$retina_file} => FAIL");
                $issue = true;
            } else {
                do_action('wr2x_retina_file_added', $id, $retina_file);
                wr2x_log("- {$name}: {$normal_file} -> {$retina_file} => RESIZE");
            }
        } else {
            wr2x_log("- {$name} => MISSING");
        }
    }
    // Checks attachment ID + issues
    if (!$id) {
        return $meta;
    }
    if ($issue) {
        wr2x_add_issue($id);
    } else {
        wr2x_remove_issue($id);
    }
    return $meta;
}
Пример #9
0
function wr2x_wp_ajax_wr2x_replace()
{
    if (!current_user_can('upload_files')) {
        echo json_encode(array('success' => false, 'message' => __("You do not have permission to upload files.", 'wp-retina-2x')));
        die;
    }
    $data = $_POST['data'];
    // Create the file as a TMP
    $tmpfname = tempnam(sys_get_temp_dir(), "wpx_");
    if ($tmpfname == FALSE) {
        $tmpdir = sys_get_temp_dir();
        if (!is_writable($tmpdir)) {
            echo json_encode(array('success' => false, 'message' => __("You don't have the rights to use a temporary directory.", 'wp-retina-2x')));
        } else {
            echo json_encode(array('success' => false, 'message' => __("The temporary directory could not be created.", 'wp-retina-2x')));
        }
        die;
    }
    $handle = fopen($tmpfname, "w");
    fwrite($handle, base64_decode($data));
    fclose($handle);
    // Check if it is an image
    $file_info = getimagesize($tmpfname);
    if (empty($file_info)) {
        unlink($tmpfname);
        echo json_encode(array('success' => false, 'message' => __("The file is not an image or the upload went wrong.", 'wp-retina-2x')));
        die;
    }
    $filedata = wp_check_filetype_and_ext($tmpfname, $_POST['filename']);
    if ($filedata["ext"] == "") {
        unlink($current_file);
        echo json_encode(array('success' => false, 'message' => __("You cannot use this file (wrong extension? wrong type?).", 'wp-retina-2x')));
        die;
    }
    $attachmentId = (int) $_POST['attachmentId'];
    $meta = wp_get_attachment_metadata($attachmentId);
    $current_file = get_attached_file($attachmentId);
    wr2x_delete_attachment($attachmentId);
    $pathinfo = pathinfo($current_file);
    $basepath = $pathinfo['dirname'];
    // Let's clean everything first
    if (wp_attachment_is_image($attachmentId)) {
        $sizes = wr2x_get_image_sizes();
        foreach ($sizes as $name => $attr) {
            if (isset($meta['sizes'][$name]) && isset($meta['sizes'][$name]['file']) && file_exists(trailingslashit($basepath) . $meta['sizes'][$name]['file'])) {
                $normal_file = trailingslashit($basepath) . $meta['sizes'][$name]['file'];
                $pathinfo = pathinfo($normal_file);
                $retina_file = trailingslashit($pathinfo['dirname']) . $pathinfo['filename'] . wr2x_retina_extension() . $pathinfo['extension'];
                // Test if the file exists and if it is actually a file (and not a dir)
                // Some old WordPress Media Library are sometimes broken and link to directories
                if (file_exists($normal_file) && is_file($normal_file)) {
                    unlink($normal_file);
                }
                if (file_exists($retina_file) && is_file($retina_file)) {
                    unlink($retina_file);
                }
            }
        }
    }
    if (file_exists($current_file)) {
        unlink($current_file);
    }
    // Insert the new file and delete the temporary one
    rename($tmpfname, $current_file);
    chmod($current_file, 0644);
    // Generate the images
    wp_update_attachment_metadata($attachmentId, wp_generate_attachment_metadata($attachmentId, $current_file));
    $meta = wp_get_attachment_metadata($attachmentId);
    wr2x_generate_images($meta);
    // Get the results
    $info = wr2x_retina_info($attachmentId);
    $results[$attachmentId] = $info;
    echo json_encode(array('success' => true, 'results' => $results, 'message' => __("Replaced successfully.", 'wp-retina-2x')));
    die;
}