Plugin Directory

Changeset 3352132


Ignore:
Timestamp:
08/28/2025 03:57:03 PM (7 months ago)
Author:
marceljm
Message:

Rich Results and Captions

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

Legend:

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

    r3341179 r3352132  
    22
    33function fifu_register_blocks() {
     4    // Prevent block registration in Customizer
     5    if (is_admin() && isset($GLOBALS['wp_customize']) && $GLOBALS['wp_customize'] instanceof WP_Customize_Manager) {
     6        return;
     7    }
     8
    49    $block_strings = fifu_get_strings_block();
    510    register_block_type(
  • featured-image-from-url/trunk/admin/db.php

    r3328447 r3352132  
    517517                    false AS category
    518518                FROM {$this->postmeta} pm
    519                 INNER JOIN {$this->posts} p ON pm.post_id = p.id {$filter}
     519                INNER JOIN {$this->posts} p ON pm.post_id = p.id {$filter} AND p.post_title <> ''
    520520                INNER JOIN {$this->posts} att ON (
    521521                    pm.meta_key = '_thumbnail_id'
     
    830830        // featured group
    831831        if (count($featured_list) > 0) {
    832             $att_ids_map = $this->get_thumbnail_ids($featured_list, false);
    833             if (count($att_ids_map) > 0) {
    834                 $this->revert_attachments($urls, $featured_list, $att_ids_map);
    835                 $meta_ids_map = $this->get_thumbnail_meta_ids($featured_list, $att_ids_map);
    836                 if (count($meta_ids_map) > 0)
    837                     $this->revert_attachments_meta($urls, $featured_list, $meta_ids_map);
     832            $att_ids_map_featured = $this->get_thumbnail_ids($featured_list, false);
     833            if (count($att_ids_map_featured) > 0) {
     834                $this->revert_attachments($urls, $featured_list, $att_ids_map_featured);
     835                $meta_ids_map_featured = $this->get_thumbnail_meta_ids($featured_list, $att_ids_map_featured);
     836                if (count($meta_ids_map_featured) > 0)
     837                    $this->revert_attachments_meta($urls, $featured_list, $meta_ids_map_featured);
    838838            }
    839839        }
     
    10431043    function insert_attachment_by($value) {
    10441044        $this->wpdb->query("
    1045             INSERT INTO {$this->posts} (post_author, guid, post_title, post_mime_type, post_type, post_status, post_parent, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, post_excerpt, to_ping, pinged, post_content_filtered)
     1045            INSERT INTO {$this->posts} (post_author, guid, post_title, post_excerpt, post_mime_type, post_type, post_status, post_parent, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, to_ping, pinged, post_content_filtered)
    10461046            VALUES " . str_replace('\\', '', $value));
    10471047    }
     
    10491049    function insert_ctgr_attachment_by($value) {
    10501050        $this->wpdb->query("
    1051             INSERT INTO {$this->posts} (post_author, guid, post_title, post_mime_type, post_type, post_status, post_parent, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, post_excerpt, to_ping, pinged, post_content_filtered, post_name)
     1051            INSERT INTO {$this->posts} (post_author, guid, post_title, post_excerpt, post_mime_type, post_type, post_status, post_parent, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, to_ping, pinged, post_content_filtered, post_name)
    10521052            VALUES " . str_replace('\\', '', $value));
    10531053    }
     
    10551055    function get_formatted_value($url, $alt, $post_parent) {
    10561056        $alt = $alt ?? '';
    1057         return "({$this->author}, '', '" . str_replace("'", "", $alt) . "', 'image/jpeg', 'attachment', 'inherit', '{$post_parent}', now(), now(), now(), now(), '', '', '', '', '{$url}')";
     1057        $alt = str_replace("'", "", $alt);
     1058        return "({$this->author}, '', '{$alt}', '{$alt}', 'image/jpeg', 'attachment', 'inherit', '{$post_parent}', now(), now(), now(), now(), '', '', '', '{$url}')";
    10581059    }
    10591060
    10601061    function get_ctgr_formatted_value($url, $alt, $post_parent) {
    10611062        $alt = $alt ?? '';
    1062         return "({$this->author}, '', '" . str_replace("'", "", $alt) . "', 'image/jpeg', 'attachment', 'inherit', '{$post_parent}', now(), now(), now(), now(), '', '', '', '', '{$url}', 'fifu-category-{$post_parent}')";
     1063        $alt = str_replace("'", "", $alt);
     1064        return "({$this->author}, '', '{$alt}', '{$alt}', 'image/jpeg', 'attachment', 'inherit', '{$post_parent}', now(), now(), now(), now(), '', '', '', '{$url}', 'fifu-category-{$post_parent}')";
    10631065    }
    10641066
     
    11131115                update_post_meta($att_id, '_wp_attached_file', $url);
    11141116                $alt ? update_post_meta($att_id, '_wp_attachment_image_alt', $alt) : delete_post_meta($att_id, '_wp_attachment_image_alt');
    1115                 $this->wpdb->update($this->posts, $set = array('post_title' => $alt, 'post_content_filtered' => $url), $where = array('id' => $att_id), null, null);
     1117                $this->wpdb->update($this->posts, $set = array('post_title' => $alt, 'post_excerpt' => $alt, 'post_content_filtered' => $url), $where = array('id' => $att_id), null, null);
    11161118            }
    11171119            // insert
     
    11531155                update_post_meta($att_id, '_wp_attached_file', $url);
    11541156                $alt ? update_post_meta($att_id, '_wp_attachment_image_alt', $alt) : delete_post_meta($att_id, '_wp_attachment_image_alt');
    1155                 $this->wpdb->update($this->posts, $set = array('post_content_filtered' => $url, 'post_title' => $alt), $where = array('id' => $att_id), null, null);
     1157                $this->wpdb->update($this->posts, $set = array('post_content_filtered' => $url, 'post_title' => $alt, 'post_excerpt' => $alt), $where = array('id' => $att_id), null, null);
    11561158            }
    11571159            // insert
     
    16971699        try {
    16981700            $this->wpdb->query("
    1699                 INSERT INTO {$this->posts} (post_author, guid, post_title, post_mime_type, post_type, post_status, post_parent, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, post_excerpt, to_ping, pinged, post_content_filtered)
     1701                INSERT INTO {$this->posts} (post_author, guid, post_title, post_excerpt, post_mime_type, post_type, post_status, post_parent, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, to_ping, pinged, post_content_filtered)
    17001702                VALUES " . str_replace('\\', '', $value));
    17011703
     
    18271829        try {
    18281830            $this->wpdb->query("
    1829                 INSERT INTO {$this->posts} (post_author, guid, post_title, post_mime_type, post_type, post_status, post_parent, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, post_excerpt, to_ping, pinged, post_content_filtered, post_name)
     1831                INSERT INTO {$this->posts} (post_author, guid, post_title, post_excerpt, post_mime_type, post_type, post_status, post_parent, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, to_ping, pinged, post_content_filtered, post_name)
    18301832                VALUES " . str_replace('\\', '', $value));
    18311833
  • featured-image-from-url/trunk/admin/html/js/column.js

    r3348282 r3352132  
    88    // Check all .fifu-quick thumbnails for invalid images
    99    fifu_check_image_validity();
    10 
    11     // Add MutationObserver safely
    12     if (document.body) {
    13         observer.observe(document.body, {
    14             childList: true,
    15             subtree: true
    16         });
    17     }
    1810});
    1911
     
    7365    });
    7466});
     67
     68// Start observing
     69if (document.body) {
     70    observer.observe(document.body, {
     71        childList: true,
     72        subtree: true
     73    });
     74}
    7575
    7676var currentLightbox = null;
  • featured-image-from-url/trunk/admin/html/js/menu-su.js

    r3348282 r3352132  
    234234                },
    235235                action: function () {
    236                     jQuery("#su-dialog-remove").dialog("open");
    237                     update = true;
     236                    if (table.rows({selected: true}).count() > 0) {
     237                        jQuery("#su-dialog-remove").dialog("open");
     238                        update = true;
     239                    }
    238240                }
    239241            },
  • featured-image-from-url/trunk/admin/html/menu.html

    r3348282 r3352132  
    57445744                        <table style="background-color: #fff; border-radius: 13px;">
    57455745                            <tr>
    5746                                 <td style="width:33%;text-align:center;border-bottom: 1px solid #ddd !important">
     5746                                <td style="width:50%;text-align:center;border-bottom: 1px solid #ddd !important">
    57475747                                    <i class="fa-solid fa-robot" style="font-size:30px"></i>
    57485748                                </td>
    5749                                 <td style="width:33%;text-align:center;border-bottom: 1px solid #ddd !important">
     5749                                <td style="width:50%;text-align:center;border-bottom: 1px solid #ddd !important">
    57505750                                    <i class="fa-solid fa-glasses" style="font-size:30px"></i>
    5751                                 </td>
    5752                                 <td style="width:33%;text-align:center;border-bottom: 1px solid #ddd !important">
    5753                                     <i class="fab fa-facebook" style="font-size:30px"></i>
    57545751                                </td>
    57555752                            </tr>
    57565753                            <tr>
    5757                                 <td style="width:33%;text-align:center;border-bottom: 1px solid #ddd !important">
     5754                                <td style="width:50%;text-align:center;border-bottom: 1px solid #ddd !important">
    57585755                                    <i><?php $fifu['support']['wp-automatic']() ?></i>
    57595756                                </td>
    5760                                 <td style="width:33%;text-align:center;border-bottom: 1px solid #ddd !important">
     5757                                <td style="width:50%;text-align:center;border-bottom: 1px solid #ddd !important">
    57615758                                    <i><?php $fifu['support']['resolution']() ?></i>
    5762                                 </td>
    5763                                 <td style="width:33%;text-align:center;border-bottom: 1px solid #ddd !important">
    5764                                     <i><?php $fifu['support']['facebook']() ?></i>
    57655759                                </td>
    57665760                            </tr>
     
    57725766                                    <?php $fifu['support']['resolution-desc']() ?>
    57735767                                </td>
    5774                                 <td style="vertical-align: top;">
    5775                                     <?php $fifu['support']['facebook-desc']() ?>
    5776                                 </td>
    57775768                            </tr>
    57785769                        </table>
    5779 
    57805770                        <br>
    5781 
    57825771                        <table style="background-color: #fff; border-radius: 13px;">
    57835772                            <tr>
    5784                                 <td style="width:33%;text-align:center;border-bottom: 1px solid #ddd !important">
    5785                                     <i class="fas fa-exclamation-triangle" style="font-size:30px"></i>
    5786                                 </td>
    5787                                 <td style="width:33%;text-align:center;border-bottom: 1px solid #ddd !important">
     5773                                <td style="width:50%;text-align:center;border-bottom: 1px solid #ddd !important">
    57885774                                    <i class="fas fa-plug" style="font-size:30px"></i>
    57895775                                </td>
    5790                                 <td style="width:33%;text-align:center;border-bottom: 1px solid #ddd !important">
    5791                                     <i class="fa-solid fa-rotate-right" style="font-size:30px"></i>
     5776                                <td style="width:50%;text-align:center;border-bottom: 1px solid #ddd !important">
     5777                                    <i class="fas fa-exclamation-triangle" style="font-size:30px"></i>
    57925778                                </td>
    57935779                            </tr>
    57945780                            <tr>
    5795                                 <td style="width:33%;text-align:center;border-bottom: 1px solid #ddd !important">
    5796                                     <i><?php $fifu['support']['disappeared']() ?></i>
    5797                                 </td>
    5798                                 <td style="width:33%;text-align:center;border-bottom: 1px solid #ddd !important">
     5781                                <td style="width:50%;text-align:center;border-bottom: 1px solid #ddd !important">
    57995782                                    <i><?php $fifu['support']['plugin']() ?></i>
    58005783                                </td>
    5801                                 <td style="width:33%;text-align:center;border-bottom: 1px solid #ddd !important">
    5802                                     <i><?php $fifu['support']['others']() ?></i>
     5784                                <td style="width:50%;text-align:center;border-bottom: 1px solid #ddd !important">
     5785                                    <i><?php $fifu['support']['disappeared']() ?></i>
    58035786                                </td>
    58045787                            </tr>
    58055788                            <tr>
    58065789                                <td style="vertical-align: top;">
    5807                                     <?php $fifu['support']['disappeared-desc']() ?>
    5808                                 </td>
    5809                                 <td style="vertical-align: top;">
    58105790                                    <?php $fifu['support']['plugin-desc']() ?>
    58115791                                </td>
    58125792                                <td style="vertical-align: top;">
    5813                                     <?php $fifu['support']['others-desc']() ?>
     5793                                    <?php $fifu['support']['disappeared-desc']() ?>
    58145794                                </td>
    58155795                            </tr>
    58165796                        </table>
    5817 
    58185797                        <br>
    5819 
    58205798                        <table style="background-color: #fff; border-radius: 13px;">
    58215799                            <tr>
    5822                                 <td style="width:33%;text-align:center;border-bottom: 1px solid #ddd !important">
     5800                                <td style="width:50%;text-align:center;border-bottom: 1px solid #ddd !important">
    58235801                                    <i class="fa-solid fa-icons" style="font-size:30px"></i>
    58245802                                </td>
    5825                                 <td style="width:33%;text-align:center;border-bottom: 1px solid #ddd !important">
     5803                                <td style="width:50%;text-align:center;border-bottom: 1px solid #ddd !important">
    58265804                                    <i class="fa-solid fa-file-circle-xmark" style="font-size:30px"></i>
    5827                                 </td>
    5828                                 <td style="width:33%;text-align:center;border-bottom: 1px solid #ddd !important">
    5829 
    58305805                                </td>
    58315806                            </tr>
    58325807                            <tr>
    5833                                 <td style="width:33%;text-align:center;border-bottom: 1px solid #ddd !important">
     5808                                <td style="width:50%;text-align:center;border-bottom: 1px solid #ddd !important">
    58345809                                    <i><?php $fifu['support']['media-library']() ?></i>
    58355810                                </td>
    5836                                 <td style="width:33%;text-align:center;border-bottom: 1px solid #ddd !important">
     5811                                <td style="width:50%;text-align:center;border-bottom: 1px solid #ddd !important">
    58375812                                    <i><?php $fifu['support']['money']() ?></i>
    5838                                 </td>
    5839                                 <td style="width:33%;text-align:center;border-bottom: 1px solid #ddd !important">
    5840 
    58415813                                </td>
    58425814                            </tr>
     
    58485820                                    <?php $fifu['support']['money-desc']() ?>
    58495821                                </td>
    5850                                 <td style="vertical-align: top;">
    5851 
    5852                                 </td>
    58535822                            </tr>
    58545823                        </table>
  • featured-image-from-url/trunk/admin/meta-box.php

    r3348282 r3352132  
    300300}
    301301
    302 /* woocommerce variation elements */
    303 
    304 // add_action('woocommerce_product_after_variable_attributes', 'fifu_variation_settings_fields', 10, 3);
    305 
    306 function fifu_variation_settings_fields($loop, $variation_data, $variation) {
    307     $fifu = fifu_get_strings_meta_box_php();
    308 
    309     // variation
    310     woocommerce_wp_text_input(
    311             array(
    312                 'id' => "fifu_image_url{$loop}",
    313                 'name' => "fifu_image_url[{$loop}]",
    314                 'value' => get_post_meta($variation->ID, 'fifu_image_url', true),
    315                 'label' => '<span class="dashicons dashicons-camera" style="font-size:20px"></span>' . $fifu['variation']['field'](),
    316                 'desc_tip' => true,
    317                 'description' => $fifu['variation']['info'](),
    318                 'placeholder' => $fifu['variation']['image'](),
    319                 'wrapper_class' => 'form-row form-row-full',
    320             )
    321     );
    322     // variation gallery
    323     for ($i = 0; $i < 3; $i++) {
    324         woocommerce_wp_text_input(
    325                 array(
    326                     'id' => "fifu_image_url_" . $i . "{$loop}",
    327                     'name' => "fifu_image_url_" . $i . "[{$loop}]",
    328                     'value' => get_post_meta($variation->ID, 'fifu_image_url_' . $i, true),
    329                     'label' => '<span class="dashicons dashicons-format-gallery" style="font-size:20px"></span>' . $fifu['variation']['images']() . ' #' . ($i + 1),
    330                     'desc_tip' => true,
    331                     'placeholder' => $fifu['variation']['image'](),
    332                     'wrapper_class' => 'form-row form-row-full',
    333                 )
    334         );
    335     }
    336 }
    337 
    338302/* dimensions */
    339303
  • featured-image-from-url/trunk/admin/strings.php

    r3348282 r3352132  
    467467        _e("A plugin isn't working with FIFU", FIFU_SLUG);
    468468    };
    469     $fifu['support']['facebook'] = function () {
    470         _e("Facebook doesn't share images", FIFU_SLUG);
    471     };
    472469    $fifu['support']['money'] = function () {
    473470        _e("Broken image icon", FIFU_SLUG);
     
    482479        _e("Contact us. If you are available to discuss the details, we should provide an integration. Or contact its developer and ask him to use the functions at 'Developers → FIFU API'.", FIFU_SLUG);
    483480    };
    484     $fifu['support']['facebook-desc'] = function () {
    485         _e("You probably have a plugin or theme that sets a default image as the Facebook image (og:image meta tag). Just find and disable the option.", FIFU_SLUG);
    486     };
    487481    $fifu['support']['money-desc'] = function () {
    488482        _e("Possibilities: a) CDN can't serve it; b) image deleted by owner; c) hotlink protection; d) incorrect URL. For (a), disable 'Image → Optimized images' temporarily and contact us. For (b) or (c), try FIFU Cloud.", FIFU_SLUG);
     
    497491        _e("Images saved in the media library", FIFU_SLUG);
    498492    };
    499     $fifu['support']['others'] = function () {
    500         _e("Changes have no effect", FIFU_SLUG);
    501     };
    502493    $fifu['support']['wp-automatic-desc'] = function () {
    503494        _e("Notify WP Automatic (or WPeMatico) support that image URLs are not sent to FIFU. Alternatively, use our PRO version to obtain images using page addresses or post titles.", FIFU_SLUG);
     
    505496    $fifu['support']['media-library-desc'] = function () {
    506497        _e("This plugin doesn't save images to the media library unless you're using the 'Image → Save in the media library' feature. So, another plugin or your theme may be causing this.", FIFU_SLUG);
    507     };
    508     $fifu['support']['others-desc'] = function () {
    509         _e("If you're using a performance plugin, clearing the cache may help. This ensures that backend changes propagate effectively to the frontend.", FIFU_SLUG);
    510498    };
    511499
     
    18301818
    18311819    // variation
    1832     $fifu['variation']['field'] = function () {
    1833         return __("Product Image (URL)", FIFU_SLUG);
    1834     };
    1835     $fifu['variation']['info'] = function () {
    1836         return __("Powered by FIFU plugin", FIFU_SLUG);
    1837     };
    1838     $fifu['variation']['image'] = function () {
    1839         return __("Image URL", FIFU_SLUG);
    1840     };
    1841     $fifu['variation']['images'] = function () {
    1842         return __("Gallery Image (URL)", FIFU_SLUG);
    1843     };
    1844     $fifu['variation']['upload'] = function () {
     1820    $fifu['variation']['new']['upload'] = function () {
    18451821        return __("Upload to media library", FIFU_SLUG);
     1822    };
     1823    $fifu['variation']['new']['images'] = function () {
     1824        return __("Images", FIFU_SLUG);
     1825    };
     1826    $fifu['variation']['new']['help'] = function () {
     1827        return __("The first slot is for the featured image, and the others are for the image gallery.", FIFU_SLUG);
    18461828    };
    18471829
     
    22992281    // media
    23002282    $fifu['media']['desc'] = function () {
    2301         _e("Before uploading local images to the cloud, you should copy their URLs to FIFU custom fields by clicking the \"link\" button. Have a database backup as post metadata will be replaced, making this plugin responsible for displaying images. Do not delete images from the media library until ensuring they were saved in the cloud.", FIFU_SLUG);
     2283        _e("To have local images listed on the 'Upload' tab, you should first select them here and click the 'link' button, which will copy the local image URLs to the FIFU custom field, making FIFU responsible for displaying the images. Then you should be able to upload the local images to the cloud. Do not delete any image from the media library before doing this.", FIFU_SLUG);
    23022284    };
    23032285
  • featured-image-from-url/trunk/elementor/elementor-fifu-extension.php

    r2926179 r3352132  
    1818    public function __construct() {
    1919        add_action('init', [$this, 'i18n']);
    20         add_action('plugins_loaded', [$this, 'init']);
     20
     21        // Use current Elementor hooks for widgets and controls registration
     22        add_action('elementor/widgets/register', [$this, 'on_widgets_register']);
     23        add_action('elementor/controls/register', [$this, 'on_controls_register']);
     24
     25        // Enqueue frontend scripts at the recommended timing
     26        add_action('elementor/frontend/after_enqueue_scripts', [$this, 'enqueue_widget_scripts']);
    2127    }
    2228
     
    2531    }
    2632
    27     public function init() {
    28         // Add Plugin actions
    29         add_action('elementor/widgets/widgets_registered', [$this, 'init_widgets']);
    30         add_action('elementor/controls/controls_registered', [$this, 'init_controls']);
     33    // Register widgets using the new API (>= 3.5)
     34    public function on_widgets_register(\Elementor\Widgets_Manager $widgets_manager) {
     35        require_once(__DIR__ . '/widgets/widget.php');
     36        $widgets_manager->register(new \Elementor_FIFU_Widget());
    3137
    32         // Register Widget Scripts
    33         add_action('elementor/frontend/after_register_scripts', [$this, 'widget_scripts']);
     38        require_once(__DIR__ . '/widgets/widget-video.php');
     39        $widgets_manager->register(new \Elementor_FIFU_Video_Widget());
    3440    }
    3541
    36     public function init_widgets() {
    37         // Include Widget files and register widget
    38         require_once( __DIR__ . '/widgets/widget.php' );
    39         \Elementor\Plugin::instance()->widgets_manager->register_widget_type(new \Elementor_FIFU_Widget());
    40 
    41         require_once( __DIR__ . '/widgets/widget-video.php' );
    42         \Elementor\Plugin::instance()->widgets_manager->register_widget_type(new \Elementor_FIFU_Video_Widget());
     42    // Register custom controls if needed
     43    public function on_controls_register($controls_manager) {
     44        // Add custom controls registration here if needed
    4345    }
    4446
    45     public function init_controls() {
    46        
     47    // Enqueue frontend scripts/styles at the recommended hook
     48    public function enqueue_widget_scripts() {
     49        // Example: wp_enqueue_script('fifu-el-frontend', plugins_url('assets/js/frontend.js', __FILE__), ['elementor-frontend'], '1.0.0', true);
    4750    }
    48 
    49     public function widget_scripts() {
    50        
    51     }
    52 
    5351}
    5452
  • featured-image-from-url/trunk/elementor/widgets/widget-video.php

    r2926179 r3352132  
    2020    }
    2121
    22     protected function _register_controls() {
     22    protected function register_controls() {
    2323        $strings = fifu_get_strings_elementor();
    2424
     
    4848       
    4949    }
    50 
    5150}
    5251
  • featured-image-from-url/trunk/elementor/widgets/widget.php

    r3341179 r3352132  
    2020    }
    2121
    22     protected function _register_controls() {
     22    // Use the current API method name (no underscore)
     23    protected function register_controls() {
    2324        $strings = fifu_get_strings_elementor();
    2425
     
    5051                    'input_type' => 'text',
    5152                    'placeholder' => '',
    52                     'description' => $strings['help']['alt'](), // Add help text here
     53                    'description' => $strings['help']['alt'](),
    5354                ]
    5455        );
     
    7071}
    7172
    72 function fifu_image_after_save_elementor_data($post_id, $editor_data) {
    73     foreach ($editor_data as $data) {
    74         if (isset($data['elements'][0]['widgetType'])) {
    75             $widgetType = $data['elements'][0]['widgetType'];
    76             if (strpos($widgetType, 'fifu') !== false) {
    77                 $settings = $data['elements'][0]['settings'] ?? [];
     73// Recursively traverse the editor data tree and apply logic to FIFU widgets
     74function fifu_walk_elements_and_apply($elements, $post_id) {
     75    if (!is_array($elements))
     76        return;
    7877
    79                 if ($widgetType == 'fifu-elementor') {
    80                     if (isset($settings['fifu_input_url'])) {
    81                         $image_url = $settings['fifu_input_url'];
    82                         if (filter_var($image_url, FILTER_VALIDATE_URL) === false)
    83                             $image_url = '';
    84                         fifu_dev_set_image($post_id, $image_url);
    85                     }
    86                     // Save alternative text
    87                     if (isset($settings['fifu_input_alt'])) {
    88                         $alt = esc_html(wp_strip_all_tags($settings['fifu_input_alt']));
    89                         fifu_update_or_delete_value($post_id, 'fifu_image_alt', $alt);
     78    foreach ($elements as $el) {
     79        if (
     80                isset($el['elType']) && $el['elType'] === 'widget' &&
     81                isset($el['widgetType'])
     82        ) {
     83            $widgetType = $el['widgetType'];
     84            $settings = $el['settings'] ?? [];
     85
     86            if ($widgetType == 'fifu-elementor') {
     87                if (isset($settings['fifu_input_url'])) {
     88                    $image_url = $settings['fifu_input_url'];
     89                    if ($image_url && filter_var($image_url, FILTER_VALIDATE_URL) === false)
     90                        $image_url = '';
     91                    fifu_dev_set_image($post_id, $image_url);
     92                    $att_id = get_post_thumbnail_id($post_id);
     93                    if ($att_id && $image_url) {
     94                        $image_sizes = getimagesize($image_url);
     95                        if ($image_sizes && isset($image_sizes[0], $image_sizes[1])) {
     96                            fifu_save_dimensions($att_id, $image_sizes[0], $image_sizes[1]);
     97                        }
    9098                    }
    9199                }
     100                // Save alternative text
     101                if (isset($settings['fifu_input_alt'])) {
     102                    $alt = esc_html(wp_strip_all_tags($settings['fifu_input_alt']));
     103                    fifu_update_or_delete_value($post_id, 'fifu_image_alt', $alt);
     104                }
    92105            }
     106        }
     107
     108        // Recursively process child elements
     109        if (!empty($el['elements']) && is_array($el['elements'])) {
     110            fifu_walk_elements_and_apply($el['elements'], $post_id);
    93111        }
    94112    }
    95113}
    96114
     115function fifu_image_after_save_elementor_data($post_id, $editor_data) {
     116    if (!is_array($editor_data))
     117        return;
     118    fifu_walk_elements_and_apply($editor_data, $post_id);
     119}
     120
    97121add_action('elementor/editor/after_save', 'fifu_image_after_save_elementor_data', 10, 2);
    98122
  • featured-image-from-url/trunk/featured-image-from-url.php

    r3348282 r3352132  
    55 * Plugin URI: https://fifu.app/
    66 * Description: Use remote media as the featured image and beyond.
    7  * Version: 5.2.5
     7 * Version: 5.2.6
    88 * Author: fifu.app
    99 * Author URI: https://fifu.app/
    1010 * WC requires at least: 4.0
    11  * WC tested up to: 10.1.1
     11 * WC tested up to: 10.1.2
    1212 * Text Domain: featured-image-from-url
    1313 * License: GPLv3
  • featured-image-from-url/trunk/includes/attachment.php

    r3341179 r3352132  
    198198    /* img */
    199199
     200    $buffer = fifu_filter_og_images($buffer);
     201
    200202    $srcType = "src";
    201203    $imgList = array();
     
    407409add_action('wp_ajax_get-attachment', 'custom_get_attachment_intercept', 0);
    408410
     411function fifu_filter_og_images($buffer) {
     412    // Regex to match FIFU blocks
     413    $pattern_blocks = '/<!--\s*FIFU:meta:begin:[a-z]+\s*-->.*?<!--\s*FIFU:meta:end:[a-z]+\s*-->/is';
     414
     415    // Extract all FIFU blocks
     416    $blocks = [];
     417    if (preg_match_all($pattern_blocks, $buffer, $matches, PREG_OFFSET_CAPTURE)) {
     418        foreach ($matches[0] as $match) {
     419            $blocks[] = $match[0];
     420        }
     421    }
     422
     423    // Check if there is at least one og:image inside any FIFU block
     424    $has_fifu_ogimage = false;
     425    foreach ($blocks as $block) {
     426        if (preg_match('/<meta\s+[^>]*property=["\']og:image[^"\']*["\']/i', $block)) {
     427            $has_fifu_ogimage = true;
     428            break;
     429        }
     430    }
     431
     432    // If no og:image was found inside FIFU blocks, return original buffer
     433    if (!$has_fifu_ogimage) {
     434        return $buffer;
     435    }
     436
     437    // Otherwise, protect blocks and remove unwanted tags outside them
     438    $buffer_preserve = $buffer;
     439    foreach ($blocks as $i => $block) {
     440        $buffer_preserve = str_replace($block, "___FIFU_BLOCK_" . ($i + 1) . "___", $buffer_preserve);
     441    }
     442
     443    // Remove ALL <meta property="og:image..."> tags outside FIFU blocks
     444    $buffer_preserve = preg_replace('/<meta\s+[^>]*property=["\']og:image[^"\']*["\'][^>]*>\s*/i', '', $buffer_preserve);
     445
     446    // Remove ALL <meta name="twitter:image..."> tags outside FIFU blocks
     447    $buffer_preserve = preg_replace('/<meta\s+[^>]*name=["\']twitter:image[^"\']*["\'][^>]*>\s*/i', '', $buffer_preserve);
     448
     449    // Restore preserved FIFU blocks in their original positions
     450    foreach ($blocks as $i => $block) {
     451        $buffer_preserve = str_replace("___FIFU_BLOCK_" . ($i + 1) . "___", $block, $buffer_preserve);
     452    }
     453
     454    return $buffer_preserve;
     455}
     456
  • featured-image-from-url/trunk/includes/html/js/json-ld.js

    r3089471 r3352132  
    11(function () {
    22    if (typeof fifuJsonLd !== 'undefined' && fifuJsonLd.url) {
     3        // Map string/objects to ImageObject with @id and url; dedup per list
     4        function toImageObjects(img) {
     5            var arr = Array.isArray(img) ? img : (img ? [img] : []);
     6            var out = [];
     7            var seen = Object.create(null);
     8
     9            for (var i = 0; i < arr.length; i++) {
     10                var it = arr[i];
     11                if (!it)
     12                    continue;
     13
     14                if (typeof it === 'string') {
     15                    if (seen[it])
     16                        continue;
     17                    seen[it] = 1;
     18                    out.push({
     19                        "@type": "ImageObject",
     20                        "@id": it,
     21                        "url": it
     22                    });
     23                } else if (typeof it === 'object') {
     24                    // If already an object, ensure it has @type/@id/url
     25                    var id = it['@id'] || it.url;
     26                    if (!id)
     27                        continue;
     28                    if (seen[id])
     29                        continue;
     30                    seen[id] = 1;
     31
     32                    var obj = {};
     33                    for (var k in it)
     34                        if (Object.prototype.hasOwnProperty.call(it, k))
     35                            obj[k] = it[k];
     36                    obj['@type'] = obj['@type'] || 'ImageObject';
     37                    obj['@id'] = id;
     38                    obj['url'] = obj['url'] || id;
     39                    out.push(obj);
     40                }
     41            }
     42            return out;
     43        }
     44
    345        var jsonData = {
    4             "@context": "http://schema.org",
    5             "@type": "ImageObject",
    6             "url": fifuJsonLd.url,
    7             "image": fifuJsonLd.url
     46            "@context": fifuJsonLd["@context"],
     47            "@type": fifuJsonLd["@type"],
     48            "url": fifuJsonLd.url
    849        };
    950
    10         // Create a script element for the JSON-LD structured data
     51        // Product-level images -> ImageObject[]
     52        if (fifuJsonLd.image) {
     53            jsonData.image = toImageObjects(fifuJsonLd.image);
     54        }
     55
     56        if (fifuJsonLd.headline) {
     57            jsonData.headline = fifuJsonLd.headline; // BlogPosting
     58        }
     59
     60        if (fifuJsonLd.name) {
     61            jsonData.name = fifuJsonLd.name; // Product
     62        }
     63
     64        var commentBegin = document.createComment(' FIFU:jsonld:begin');
     65        document.head.appendChild(commentBegin);
     66
    1167        var script = document.createElement('script');
    1268        script.type = 'application/ld+json';
    1369        script.textContent = JSON.stringify(jsonData);
    1470        document.head.appendChild(script);
     71
     72        var commentEnd = document.createComment(' FIFU:jsonld:end');
     73        document.head.appendChild(commentEnd);
    1574    }
    1675})();
  • featured-image-from-url/trunk/includes/html/og-image.html

    r2932443 r3352132  
    1 <!-- FIFU: meta tags for featured image (begin) -->
     1<!-- FIFU:meta:begin:image -->
    22<meta property="og:image" content="<?php echo $url ?>" />
    3 <!-- FIFU: meta tags for featured image (end) -->
     3<!-- FIFU:meta:end:image -->
  • featured-image-from-url/trunk/includes/html/social-home.html

    r3024872 r3352132  
    1 <!-- FIFU: meta tags for home (begin) -->
     1<!-- FIFU:meta:begin:home -->
    22<meta property="og:image" content="<?php echo $url ?>" />
    3 <!-- FIFU: meta tags for home (end) -->
     3<!-- FIFU:meta:end:home -->
  • featured-image-from-url/trunk/includes/html/twitter-image.html

    r2295697 r3352132  
     1<!-- FIFU:meta:begin:twitter -->
    12<meta name="twitter:image" content="<?php echo $url ?>" />
     3<!-- FIFU:meta:end:twitter -->
  • featured-image-from-url/trunk/includes/thumbnail.php

    r3344902 r3352132  
    9191    $description = str_replace("'", "&#39;", wp_strip_all_tags(get_post_field('post_excerpt', $post_id)));
    9292
     93    $arr = array($url);
     94
     95    // https://search.google.com/test/rich-results
     96    // Add JSON-LD for WordPress posts and products
     97    $type = get_post_type($post_id);
     98    if (is_singular($type)) {
     99        wp_enqueue_script('fifu-json-ld', plugins_url('/html/js/json-ld.js', __FILE__), array(), fifu_version_number_enq());
     100        $json_ld = [
     101            "@context" => "https://schema.org",
     102            "url" => get_permalink($post_id),
     103            "image" => $arr,
     104        ];
     105        if ($type === 'product') {
     106            $json_ld["@type"] = "Product";
     107            $json_ld["name"] = get_the_title($post_id);
     108        } else {
     109            $json_ld["@type"] = "BlogPosting";
     110            $json_ld["headline"] = get_the_title($post_id);
     111        }
     112        wp_localize_script('fifu-json-ld', 'fifuJsonLd', $json_ld);
     113    }
     114
    93115    if ($url) {
    94116        if (fifu_is_from_speedup($url))
     
    98120        }
    99121        include 'html/og-image.html';
    100 
    101         wp_enqueue_script('fifu-json-ld', plugins_url('/html/js/json-ld.js', __FILE__), array(), fifu_version_number_enq());
    102         wp_localize_script('fifu-json-ld', 'fifuJsonLd', [
    103             'url' => $url,
    104         ]);
    105122    }
    106123
  • featured-image-from-url/trunk/readme.txt

    r3348282 r3352132  
    55Requires at least: 5.6
    66Tested up to: 6.8.2
    7 Stable tag: 5.2.5
     7Stable tag: 5.2.6
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    247247== Changelog ==
    248248
     249= 5.2.6 =
     250* Enhancement: improved integration with Rich Results from Google; Enhancement: alternative text can now be displayed as captions at the bottom of the image; Fix: images defined by other plugins were being displayed on social media instead of the remote featured image; Fix: Elementor widget not working with newer Elementor versions.
     251
    249252= 5.2.5 =
    250253* Enhancement: Improved translations and support for 40 new languages; Enhancement: Alternative Text field now opens in the lightbox for easier editing; Enhancement: Redirects to the plugin settings after activation; Fix: Quick Edit not working for variable products with multiple attributes; Fix: Google Drive images not displaying in the admin area.
     
    277280== Upgrade Notice ==
    278281
    279 = 5.2.5 =
    280 * Enhancement: Improved translations and support for 40 new languages; Enhancement: Alternative Text field now opens in the lightbox for easier editing; Enhancement: Redirects to the plugin settings after activation; Fix: Quick Edit not working for variable products with multiple attributes; Fix: Google Drive images not displaying in the admin area.
     282= 5.2.6 =
     283* Enhancement: improved integration with Rich Results from Google; Enhancement: alternative text can now be displayed as captions at the bottom of the image; Fix: images defined by other plugins were being displayed on social media instead of the remote featured image; Fix: Elementor widget not working with newer Elementor versions.
Note: See TracChangeset for help on using the changeset viewer.