#1 WordPress forum plugin created by gVectors Team

wpForo – WordPress Forum Plugin
  • Home
  • Forum
  • Migrate to wpForo
  • Addons
  • Addons Demo
  • Documentation

Forum

Home | Forum

wpDiscuz - WordPress Comment Plugin
  • Forums
  • Members
  • Recent Posts
Forums
Main Support Forums
How-to and Troubles...
Images inline
 
Share:
Share
Tweet
Share
Notifications
Clear all

Script [Solved] Images inline

    Last Post
RSS

dimalifragis
Posts: 1131
 dimalifragis
Beta Tester
Topic starter
October 11, 2021 12:23 pm
(@dimalifragis)
Noble Member
Joined: 2 years ago

Hello.

We use for ages now a small code provided by the support guys, that each attachment that was a photo, was show inline (embeded) to the body. Worked perfectly well.

Now it seems something changed, and if I EDIT such a post, the image becomes attachment after saving.

Any ideas how to fix this?

 

Thanks

wpForo Version
1.9.9.1
WordPress Version
5.8.1
Topic Tags
photo embed attachment
5 Replies
dimalifragis
Posts: 1131
 dimalifragis
Beta Tester
Topic starter
October 11, 2021 12:27 pm
(@dimalifragis)
Noble Member
Joined: 2 years ago

The code is:

 

add_filter('wpforo_content_after', 'wpforo_default_attachment_image_embed', 11);

function wpforo_default_attachment_image_embed($content)
{
    if (preg_match_all('|<a class=\"wpforo\-default\-attachment\" href\=\"([^\"\']+)\"[^><]*>.+?<\/a>|is', $content, $data, PREG_SET_ORDER)) {
        foreach ($data as $array) {
            if (isset($array[1])) {
                $file = $array[1];
                $e    = strtolower(substr(strrchr($file, '.'), 1));
                if ($e == 'jpg' || $e == 'jpeg' || $e == 'png' || $e == 'gif') {
                    $filename = explode('/', $file);
                    $filename = end($filename);
                    $html     = '<a href="' . esc_url($file) . '" target="_blank"><img class="wpforo-default-image-attachment" src="' . esc_url($file) . '" alt="' . esc_attr($filename) . '" title="' . esc_attr($filename) . '" /></a>';
                    $content  = str_replace($array[0], $html, $content);
                }
            }
        }
    }
    return $content;
}
1 Reply
Chris
 Chris
Admin
(@chris)
Joined: 12 months ago

Support Team
Posts: 1447
October 14, 2021 1:40 pm
Reply todimalifragisdimalifragis

Hi @dimalifragis,

Delete the old Code and add the new one:

add_filter('wpforo_content_after', function( $content ){
	return preg_replace_callback(
        '#<a[^><]*\sclass=[\'\"](?:[^\'\"]*\s)?wpforo-default-attachment(?:\s[^\'\"]*)?[\'\"][^><]*\shref=[\'\"]([^\"\']+)[\'\"][^><]*>.*?</a>#isu',
        function( $match ){
                $html     = $match[0];
	        $file     = $match[1];
	        $pathinfo = pathinfo( $file );
	        if( wpforo_is_image($pathinfo['extension']) ) {
                $html = sprintf(
                    '<a href="%1$s" target="_blank"><img class="wpforo-default-image-attachment" src="%1$s" alt="%2$s" title="%2$s"></a>',
	                esc_url($file),
	                esc_attr($pathinfo['basename'])
                );
	        }
            return $html;
        },
        $content
    );
}, 11);
This post was modified 9 months ago by BlackRaz

In case you want to say thank you !)
We'd really appreciate and be thankful if you leave a good review on plugin page. This is the best way to say thank you to this project and support team.

dimalifragis liked
dimalifragis
Posts: 1131
 dimalifragis
Beta Tester
Topic starter
October 14, 2021 4:56 pm
(@dimalifragis)
Noble Member
Joined: 2 years ago

14-Oct-2021 16:53:33 UTC] PHP Warning: preg_replace_callback(): Compilation failed: unrecognized character after (? or (?- at offset 23 in /home/wp-content/plugins/custom-functions/custom-functions.php on line 52

 

Line 52 is

$content
Chris
Posts: 1447
 Chris
Admin
October 15, 2021 12:54 pm
(@chris)
Support Team
Joined: 12 months ago

@dimalifragis,

Copy and paste the Code again, please. We have updated in my above reply.

In case you want to say thank you !)
We'd really appreciate and be thankful if you leave a good review on plugin page. This is the best way to say thank you to this project and support team.

dimalifragis
Posts: 1131
 dimalifragis
Beta Tester
Topic starter
October 15, 2021 1:31 pm
(@dimalifragis)
Noble Member
Joined: 2 years ago

Works fine now, many thanks.

Chris liked
  All forum topics
  Previous Topic
Next Topic  
Related Topics
  • PDF attachment not allowed but settings allow them
    5 months ago
  • Help
    10 months ago
  • Attachment Protection.
    2 years ago
  • Protect attachments
    3 years ago
  • Wp foro
    3 years ago
Topic Tags:  photo embed (1), attachment (10),

Forum Search

Join Us!

Download wpForo plugin
on WordPress.org

wpForo Addons

wpforo-private-messages wpforo-advanced-attachments-128x128 wpforo-embeds-128x128 wpForo User Custom Fields addon wpForo – Blog Cross Posting addon wpForo Ads Manager wpForo – WooCommerce Memberships Integration wpForo Emoticons wpForo – Tenor GIFs Integration
View all Addons »

Recent Topics

  • Import users from IPBoard

    By jesusdlg, 5 hours ago

  • How to make new user to get approve manually before creating post and profile.

    By Adhyansh21, 2 days ago

  • Posts deleted in database still show up on front-end

    By nylex, 2 days ago

  • Not all links are automatically added with the "nofollow" attribute

    By st7878, 2 days ago

  • Editors assign users to groups

    By mike_netinfo, 2 days ago

  • Set password link opens forum login page instead of set password page

    By JanJan, 2 days ago

Topic Tags

  • css52
  • translation50
  • plugin conflict48
  • seo47
  • new features45
  • buddypress43
  • avatar41
  • moderation40
  • ultimate member40
  • login40
  • forum40
  • registration37
  • threaded layout35
  • cache34
  • spam33
  • editor33
  • menu33
  • shortcode32
  • forum accesses30
  • widget29
View all tags (2194)

Recent Posts

  • Import users from IPBoard

    Hello, Is it possible to import users from ipboard? (...

    By jesusdlg, 5 hours ago

  • RE: User banned for using icons?

    If you have security plugins that can ban users, try de...

    By Chris, 15 hours ago

  • RE: recover deleted forum categories

    @robert @chris could that upgrade message at the top of...

    By dimalifragis, 15 hours ago

  • RE: recover deleted forum categories

    Hi @asmadi1, Contact your hosting to get a backup.

    By Chris, 17 hours ago

  • RE: Posts deleted in database still show up on front-end

    @nylex, Copy the post content or part of it, the go-t...

    By Chris, 19 hours ago

  • RE: Problem with Block themes

    Works very well with those kind of themes. Here is MY...

    By dimalifragis, 19 hours ago

  • RE:

    By Anonymous, 53 years ago

Share:
Share
Tweet
Share
  Forum Statistics
21 Forums
9,936 Topics
50.3 K Posts
7 Online
48.2 K Members

Latest Post: Import users from IPBoard Our newest member: styotri88 Recent Posts Unread Posts Tags

Forum Icons: Forum contains no unread posts Forum contains unread posts

Topic Icons: Not Replied Replied Active Hot Sticky Unapproved Solved Private Closed

Powered by wpForo | Copyright © 2016-2022 gVectors Team
Copyright Registration Service - Click here for more information or to register work
wpForo is Registered with the IP Rights Office
Copyright Registration Service

Ref: 4477265538
  • Home
  • Forum
  • Migrate to wpForo
  • Addons
  • Addons Demo
  • Documentation