What does the last line in the wpautop function do?

View: New views
6 Messages — Rating Filter:   Alert me  

What does the last line in the wpautop function do?

by Glenn Ansley :: Rate this Message:

| View Threaded | Show Only this Message

Hi,
I have a single post that isn't making it through the wpautop filter ( all
the others do ).
I can remove the filter and the post prints without formatting.

I've gone into the wpautop function itself for testing and found that the
problem is in the last line that runs preg_replace.

If I die( $pee ); directly before the last preg_replace I get the post
content as expected.
If I die( $pee ); directly after the last preg_replace I get nothing at all
( $pee is empty ).

I need to find out what about this individual post in relation to the final
line of wpautop is not jiving correctly. Unfortunately, I don't have any
bragging rights in the regex arena (I can tell it has to do with shortags).
Could anyone help me understand what this line is doing so that I might
better troubleshoot why the post isn't making it through (length,
characters, etc).

Thanks.

Final Replacement line in wpautop:
$pee = preg_replace('/<p>\s*?(' . get_shortcode_regex() . ')\s*<\/p>/s',
'$1', $pee); // don't auto-p wrap shortcodes that stand alone
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: What does the last line in the wpautop function do?

by Dion Hulse (dd32) :: Rate this Message:

| View Threaded | Show Only this Message

Are you using any plugins which add custom shortcodes?

I'd add in a die(get_shortcode_regex()); and post that back to the list to  
try and work it out along with the above question..

But it does what the comment says, It replaces

<p>[gallery or other shortcode]</p> to the correct [shortcode] so that  
when the shortcode replaces it, it doesnt end up with extra <p> tags, eg:
<p><div class="myshortcode">...</p>


On Thu, 18 Sep 2008 11:21:45 +1000, Glenn Ansley <glenn@...>  
wrote:

> Hi,
> I have a single post that isn't making it through the wpautop filter (  
> all
> the others do ).
> I can remove the filter and the post prints without formatting.
>
> I've gone into the wpautop function itself for testing and found that the
> problem is in the last line that runs preg_replace.
>
> If I die( $pee ); directly before the last preg_replace I get the post
> content as expected.
> If I die( $pee ); directly after the last preg_replace I get nothing at  
> all
> ( $pee is empty ).
>
> I need to find out what about this individual post in relation to the  
> final
> line of wpautop is not jiving correctly. Unfortunately, I don't have any
> bragging rights in the regex arena (I can tell it has to do with  
> shortags).
> Could anyone help me understand what this line is doing so that I might
> better troubleshoot why the post isn't making it through (length,
> characters, etc).
>
> Thanks.
>
> Final Replacement line in wpautop:
> $pee = preg_replace('/<p>\s*?(' . get_shortcode_regex() . ')\s*<\/p>/s',
> '$1', $pee); // don't auto-p wrap shortcodes that stand alone
> _______________________________________________
> wp-hackers mailing list
> wp-hackers@...
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: What does the last line in the wpautop function do?

by Austin Matzko :: Rate this Message:

| View Threaded | Show Only this Message

On Wed, Sep 17, 2008 at 9:21 PM, Glenn Ansley <glenn@...> wrote:

> Could anyone help me understand what this line is doing so that I might
> better troubleshoot why the post isn't making it through (length,
> characters, etc).

> $pee = preg_replace('/<p>\s*?(' . get_shortcode_regex() . ')\s*<\/p>/s', '$1', $pee);

> <p>\s*?
Find an opening paragraph tag and a minimum number of space characters
(i.e. not greedy).

> (' . get_shortcode_regex() . ')
Match any shortcodes and save them to the first backreference.

> \s*<\/<p>
Match space characters to a closing paragraph tag.

> /s
"s" is a modifier for dot-matches-all mode, meaning that preg_replace
should treat everything like it's one big line.

So replace everything that matches all that with the backreference
that just matches the get_shortcode_regex() pattern.
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: What does the last line in the wpautop function do?

by Glenn Ansley :: Rate this Message:

| View Threaded | Show Only this Message

Thanks for the responses. The site I'm working on has several plugins but I
can reproduce the error on a local, clean installation w/o any plugins by
creating a post with the same content as the problem post on the site.

Both instances result in the same printout for die( get_shortcode_regex() );
Here it is:
\[(wp_caption|caption|gallery)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?

----- Written 10 minutes later ------

After understanding what the preg_replace was doing (thanks to you) I
decided to look through the lengthy content for any random square brackets
(I didn't write the content).

I found a rouge line that started with [caption] and ended with [/caption]
but it did not appear to be generated by WP. I'm pretty sure the author
pasted it from some other engine. After deleting that line, the post comes
through with flying colors.

So, problem is resolved but I'm not sure if I understand the root of it.
Feel free to induldge if you wish.

Thanks again!

On Wed, Sep 17, 2008 at 9:41 PM, Austin Matzko <if.website@...> wrote:

> On Wed, Sep 17, 2008 at 9:21 PM, Glenn Ansley <glenn@...>
> wrote:
>
> > Could anyone help me understand what this line is doing so that I might
> > better troubleshoot why the post isn't making it through (length,
> > characters, etc).
>
> > $pee = preg_replace('/<p>\s*?(' . get_shortcode_regex() . ')\s*<\/p>/s',
> '$1', $pee);
>
> > <p>\s*?
> Find an opening paragraph tag and a minimum number of space characters
> (i.e. not greedy).
>
> > (' . get_shortcode_regex() . ')
> Match any shortcodes and save them to the first backreference.
>
> > \s*<\/<p>
> Match space characters to a closing paragraph tag.
>
> > /s
> "s" is a modifier for dot-matches-all mode, meaning that preg_replace
> should treat everything like it's one big line.
>
> So replace everything that matches all that with the backreference
> that just matches the get_shortcode_regex() pattern.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers@...
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: What does the last line in the wpautop function do?

by Otto-19 :: Rate this Message:

| View Threaded | Show Only this Message

On Wed, Sep 17, 2008 at 9:00 PM, Glenn Ansley <glenn@...> wrote:
> I found a rouge line that started with [caption] and ended with [/caption]
> but it did not appear to be generated by WP. I'm pretty sure the author
> pasted it from some other engine. After deleting that line, the post comes
> through with flying colors.
>
> So, problem is resolved but I'm not sure if I understand the root of it.

The [caption] shortcode is used for creating captions around images.
So if you use it in some wrong way, then yes, stuff between it will
probably get deleted.
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: What does the last line in the wpautop function do?

by Glenn Ansley :: Rate this Message:

| View Threaded | Show Only this Message

Hey all,
This was a thread I started back in September. I got around the issue
by not inserting captions via the media manager and doing it on my own
with CSS. The only reason I bring it back up is because a request just
came through on the wp-pro list that references the same problem. I
haven't figured it out yet, but I believe there's some sort of problem
with the last line of the wpautop filter in conjunction with long
posts and the caption shorttag.

Here is a link to the discussion I started last month along with the
post from wp-pro that came through today:
<http://www.nabble.com/What-does-the-last-line-in-the-wpautop-function-do--td19544334.html>
-----
wp-pro post
------
I need someone to troubleshoot an issue that I'm having posting a
4000+ word article, which contains a lot of links and different
formatting.

The issue occurs when I try to add a caption title to an in the post
-- all the text and HTML is wiped out and the page is left completely
blank.  When this doesn't happen, when I go to preview the post, the
post is completely blank.

If I leave out image captions, I'm able to publish the post, but it
screws up all the formatting of the other posts on home page, making
all the text bold.

I am willing to pay someone to troubleshoot this issue.  Please, let
me know your rate.
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers