Plugin Directory

Changeset 3342989


Ignore:
Timestamp:
08/11/2025 03:59:50 PM (8 months ago)
Author:
marceljm
Message:

Fixing translation

Location:
featured-image-from-url/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • featured-image-from-url/trunk/admin/dimensions.php

    r3341179 r3342989  
    2626    "https://cdn.diariodeavisos.com",
    2727    "https://i.guim.co.uk",
     28    "https://www.liveaction.org",
    2829]);
    2930
  • featured-image-from-url/trunk/admin/html/js/column.js

    r3341179 r3342989  
    8585        if (is_variable) {
    8686            let variable_box = `
    87                 <div style="background: white; padding: 10px; border-radius: 1em;">
     87                <div data-variable-product="1" style="background: white; padding: 10px; border-radius: 1em;">
    8888                    <div style="background-color:#32373c; text-align:center; width:100%; color:white; padding:6px; border-radius:5px;">
    8989                        ${fifuColumnVars.labelVariable}
     
    143143        let DISPLAY_NONE = 'display:none';
    144144        let EMPTY = '';
     145        // Detect if this click originated inside the variable modal as well
     146        const inVariableContext = jQuery(this).closest('[data-variable-product="1"]').length > 0;
     147        const isVariableProduct = !!is_variable || inVariableContext;
     148
    145149        let showVideo = EMPTY;
    146150        let showImageGallery = fifuColumnVars.onProductsPage ? EMPTY : DISPLAY_NONE;
  • featured-image-from-url/trunk/admin/html/js/meta-box.js

    r3341179 r3342989  
    184184    });
    185185});
     186
     187// Block editor: auto-remove featured image if displayed URL is external (not this site's domain)
     188(function () {
     189    if (typeof wp === 'undefined' || !wp.data || !wp.data.select || !wp.data.dispatch) {
     190        return;
     191    }
     192
     193    // Guard against multiple registrations
     194    if (window.__fifuAuthorRemoveInit) {
     195        return;
     196    }
     197    window.__fifuAuthorRemoveInit = true;
     198
     199    let scheduled = false;
     200    let lastCheckedMediaId = -1; // skip repeated same IDs within a bounce
     201    const processedIds = new Set(); // permanently skip IDs already checked this session
     202    let tickScheduled = false; // debounce wp.data churn
     203
     204    const MAX_URL_RESOLVE_RETRIES = 10;
     205    const URL_RETRY_DELAY_MS = 200;
     206
     207    function isInternalUrl(url) {
     208        if (!url || typeof url !== 'string')
     209            return false;
     210        try {
     211            const u = new URL(url, window.location.href);
     212            return u.origin === window.location.origin;
     213        } catch (e) {
     214            return false;
     215        }
     216    }
     217
     218    function getDisplayedFeaturedImageUrl() {
     219        // Try common Gutenberg selectors
     220        const selectors = [
     221            '.editor-post-featured-image img',
     222            '.editor-post-featured-image .components-responsive-wrapper__content',
     223            '.editor-post-featured-image__container img',
     224            '.components-panel__body .editor-post-featured-image img'
     225        ];
     226        for (const s of selectors) {
     227            const img = document.querySelector(s);
     228            if (img && (img.currentSrc || img.src)) {
     229                return img.currentSrc || img.src;
     230            }
     231        }
     232        return null;
     233    }
     234
     235    async function resolveDisplayedUrlWithRetry() {
     236        for (let i = 0; i < MAX_URL_RESOLVE_RETRIES; i++) {
     237            const url = getDisplayedFeaturedImageUrl();
     238            if (url)
     239                return url;
     240            await new Promise((r) => setTimeout(r, URL_RETRY_DELAY_MS));
     241        }
     242        return null;
     243    }
     244
     245    function clickWpRemoveButton() {
     246        const btns = document.querySelectorAll(
     247                '.editor-post-featured-image__actions button.editor-post-featured-image__action, button.components-button.editor-post-featured-image__action'
     248                );
     249        const removeBtn = btns[btns.length - 1];
     250        if (removeBtn) {
     251            removeBtn.click();
     252            return true;
     253        }
     254        return false;
     255    }
     256
     257    wp.data.subscribe(function () {
     258        if (tickScheduled)
     259            return;
     260        tickScheduled = true;
     261        setTimeout(function () {
     262            tickScheduled = false;
     263            try {
     264                const sel = wp.data.select('core/editor');
     265                if (!sel || !sel.getEditedPostAttribute)
     266                    return;
     267
     268                const mediaId = sel.getEditedPostAttribute('featured_media') || 0;
     269
     270                // Skip if same ID already processed in last tick
     271                if (mediaId === lastCheckedMediaId)
     272                    return;
     273
     274                // Track 0 as well to avoid repeated work when removed
     275                if (!mediaId) {
     276                    lastCheckedMediaId = 0;
     277                    return;
     278                }
     279
     280                // Hard skip IDs already checked this session (prevents loops after save)
     281                if (processedIds.has(mediaId)) {
     282                    lastCheckedMediaId = mediaId;
     283                    return;
     284                }
     285
     286                // From here we will process this new ID exactly once for this session
     287                lastCheckedMediaId = mediaId;
     288
     289                if (scheduled)
     290                    return;
     291                scheduled = true;
     292
     293                resolveDisplayedUrlWithRetry().then(function (url) {
     294                    // Mark as processed regardless of result to avoid repeated churn
     295                    processedIds.add(mediaId);
     296
     297                    if (url && !isInternalUrl(url)) {
     298                        setTimeout(function () {
     299                            if (!clickWpRemoveButton()) {
     300                                const dispatch = wp.data.dispatch('core/editor');
     301                                if (dispatch && typeof dispatch.editPost === 'function') {
     302                                    dispatch.editPost({featured_media: 0});
     303                                }
     304                            }
     305                            scheduled = false;
     306                        }, 10);
     307                    } else {
     308                        scheduled = false;
     309                    }
     310                }).catch(function (e) {
     311                    console.log('[FIFU][domain-remove] error resolving displayed URL:', e);
     312                    processedIds.add(mediaId); // guard anyway
     313                    scheduled = false;
     314                });
     315            } catch (e) {
     316                console.log('[FIFU][domain-remove] subscribe handler error:', e);
     317                scheduled = false;
     318            }
     319        }, 100); // debounce
     320    });
     321})();
    186322
    187323function fifu_get_sizes() {
     
    295431        const selectStore = wp.data.select(EDIT_POST_STORE);
    296432
    297         // Safely get toggleEditorPanelEnabled and isEditorPanelEnabled
    298         const toggleEditorPanelEnabled = dispatchStore && dispatchStore.toggleEditorPanelEnabled ? dispatchStore.toggleEditorPanelEnabled : null;
    299         const isEditorPanelEnabled = selectStore && selectStore.isEditorPanelEnabled ? selectStore.isEditorPanelEnabled : null;
    300 
    301         // Try multiple selectors for the WP featured image panel in block editor
    302         const panelSelectors = [
    303             '[aria-label="Featured image"]',
    304             '[data-panel="featured-image"]',
    305             '.editor-post-featured-image',
    306             '.components-panel__body[data-title="Featured image"]'
    307         ];
    308         let panelSelectorFound = '';
    309         let panelExists = false;
    310         for (const sel of panelSelectors) {
    311             if (document.querySelector(sel)) {
    312                 panelExists = true;
    313                 panelSelectorFound = sel;
    314                 break;
    315             }
    316         }
    317 
    318         const enabled = isEditorPanelEnabled
    319                 ? isEditorPanelEnabled('featured-image')
    320                 : true;
    321 
    322         setTimeout(function () {
    323             // Only call toggleEditorPanelEnabled if it exists
    324             if (toggleEditorPanelEnabled) {
    325                 if (show && !enabled) {
    326                     toggleEditorPanelEnabled('featured-image');
    327                 } else if (!show && enabled) {
     433        // Clear any pending timeouts
     434        if (window.fifuFeaturedImageTimer) {
     435            clearTimeout(window.fifuFeaturedImageTimer);
     436        }
     437
     438        // Single timeout with all operations
     439        window.fifuFeaturedImageTimer = setTimeout(function () {
     440            // Get panel selectors
     441            const panelSelectors = [
     442                '[aria-label="Featured image"]',
     443                '[data-panel="featured-image"]',
     444                '.editor-post-featured-image',
     445                '.components-panel__body[data-title="Featured image"]'
     446            ];
     447            let panelSelectorFound = '';
     448            let panelExists = false;
     449
     450            for (const sel of panelSelectors) {
     451                if (document.querySelector(sel)) {
     452                    panelExists = true;
     453                    panelSelectorFound = sel;
     454                    break;
     455                }
     456            }
     457
     458            // Try WordPress API first
     459            const toggleEditorPanelEnabled = dispatchStore && dispatchStore.toggleEditorPanelEnabled;
     460            const isEditorPanelEnabled = selectStore && selectStore.isEditorPanelEnabled;
     461
     462            if (toggleEditorPanelEnabled && isEditorPanelEnabled) {
     463                const enabled = isEditorPanelEnabled('featured-image') || false;
     464
     465                if ((show && !enabled) || (!show && enabled)) {
    328466                    toggleEditorPanelEnabled('featured-image');
    329467                }
    330468            }
    331             setTimeout(function () {
    332                 const refreshedEnabled = isEditorPanelEnabled
    333                         ? isEditorPanelEnabled('featured-image')
    334                         : true;
    335 
    336                 // Fallback: forcibly hide panel if it should be hidden but remains
    337                 if (!show && panelExists && refreshedEnabled) {
    338                     if (panelSelectorFound) {
    339                         jQuery(panelSelectorFound).hide();
    340                     }
     469
     470            // Fallback to direct DOM manipulation
     471            if (panelSelectorFound) {
     472                if (show) {
     473                    jQuery(panelSelectorFound).show();
     474                } else {
     475                    jQuery(panelSelectorFound).hide();
    341476                }
    342                 // Fallback: forcibly show panel if it should be shown but remains hidden
    343                 if (show && panelSelectorFound) {
    344                     jQuery(panelSelectorFound).show();
    345                 }
    346             }, 200);
    347         }, 100);
     477            }
     478        }, 150);
    348479    }
    349480}
  • featured-image-from-url/trunk/admin/html/menu.html

    r3341179 r3342989  
    47074707                                        </th>
    47084708                                        <th>
    4709                                             <?php $fifu['key']['email']() ?>                 
    4710                                         </th>
    4711                                         <th>
    4712                                             wp fifu key --email &lt;string&gt;
    4713                                         </th>
    4714                                         <th>
    4715                                             [email protected]
    4716                                         </th>
    4717                                     </tr>
    4718                                     <tr class="color">
    4719                                         <th>
    4720                                             <?php $fifu['tab']['key']() ?>
    4721                                         </th>
    4722                                         <th>
    4723                                             <?php $fifu['title']['activation']() ?>
    4724                                         </th>
    4725                                         <th>
    47264709                                            <?php $fifu['key']['key']() ?>
    47274710                                        </th>
  • featured-image-from-url/trunk/admin/languages.php

    r3328447 r3342989  
    44
    55function fifu_load_textdomain() {
    6     $locale = fifu_get_language_code(get_locale());
     6    // Use user locale in admin, site locale on frontend
     7    $raw_locale = function_exists('determine_locale') ? determine_locale() : (is_admin() ? get_user_locale() : get_locale());
     8    $locale = fifu_get_language_code($raw_locale);
    79
    810    // Do nothing if the selected language is en_US
  • featured-image-from-url/trunk/admin/menu.php

    r3341179 r3342989  
    536536    $list = '';
    537537    $active_plugins = get_option('active_plugins', []);
    538     foreach ($active_plugins as $key) {
    539         $plugin_parts = explode('/', $key);
    540         $name = $plugin_parts[0] ?? '';
    541         $list .= '&#10; - ' . $name;
     538    $all_plugins = get_plugins();
     539
     540    foreach ($active_plugins as $basename) {
     541        if (isset($all_plugins[$basename])) {
     542            $data = $all_plugins[$basename];
     543            $name = $data['Name'] ?? $basename;
     544            $text_domain = $data['TextDomain'] ?? '';
     545            $author = isset($data['Author']) ? wp_strip_all_tags($data['Author']) : '';
     546
     547            $display = $name;
     548            if ($text_domain !== '') {
     549                $display .= ' (' . $text_domain . ')';
     550            }
     551            if ($author !== '') {
     552                $display .= ': ' . $author;
     553            }
     554        } else {
     555            // Fallback to directory name if metadata is missing
     556            $parts = explode('/', $basename);
     557            $display = $parts[0] ?? $basename;
     558        }
     559
     560        $list .= '&#10; - ' . $display;
    542561    }
    543562    return $list;
  • featured-image-from-url/trunk/admin/strings.php

    r3341179 r3342989  
    16051605        _e("You can renew your license key(s) or get more information about that <a href='https://ws.featuredimagefromurl.com/keys/' target='_blank'>here</a>.", FIFU_SLUG);
    16061606    };
    1607     $fifu['key']['email'] = function () {
    1608         _e("Email", FIFU_SLUG);
    1609     };
    1610     $fifu['key']['address'] = function () {
    1611         _e("Address where you received the license key", FIFU_SLUG);
    1612     };
    16131607    $fifu['key']['key'] = function () {
    16141608        _e("License key", FIFU_SLUG);
  • featured-image-from-url/trunk/featured-image-from-url.php

    r3341179 r3342989  
    55 * Plugin URI: https://fifu.app/
    66 * Description: Use a remote image or video as featured image of a post or WooCommerce product.
    7  * Version: 5.2.2
     7 * Version: 5.2.3
    88 * Author: fifu.app
    99 * Author URI: https://fifu.app/
  • featured-image-from-url/trunk/readme.txt

    r3341179 r3342989  
    55Requires at least: 5.6
    66Tested up to: 6.8.2
    7 Stable tag: 5.2.2
     7Stable tag: 5.2.3
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    250250== Changelog ==
    251251
     252= 5.2.3 =
     253* Fix: the plugin was being translated into the site language instead of the user language; Fix: input field for featured image.
     254
    252255= 5.2.2 =
    253256* New: WordPress block for remote featured images; Enhancement: Alternative Text field added to the Elementor widget; Enhancement: Registers are no longer listed in the Custom Fields box; Enhancements and fixes: Input fields for posts, products, and categories; Fix: Images were being cropped unnecessarily in WooCommerce.
     
    271274== Upgrade Notice ==
    272275
    273 = 5.2.2 =
    274 * New: WordPress block for remote featured images; Enhancement: Alternative Text field added to the Elementor widget; Enhancement: Registers are no longer listed in the Custom Fields box; Enhancements and fixes: Input fields for posts, products, and categories; Fix: Images were being cropped unnecessarily in WooCommerce.
     276= 5.2.3 =
     277* Fix: the plugin was being translated into the site language instead of the user language; Fix: input field for featured image.
Note: See TracChangeset for help on using the changeset viewer.