Wpautop () - when shortcode attributes are in newlines -breaks args array

I have my own shortcode tag with several attributes, and I would like to be able to display its attributes in new lines - to make it more readable for content editors:

[component attr1 ="value1" attr2 ="value of the second one" attr3 ="another" attr4 ="value" ... attrN ="valueN"] 

The reason for this requirement is that several attributes can be quite detailed in the content. Unfortunately, wpautop() adds some nasty extra markup that breaks an args array like this (using php print_r($args) ):

 Array ( [0] => attr1 [1] => ="value1" /> [3] => attr2 = [4] => "value [5] => of [6] => the [7] => second [8] => one" /> [10] => "" //...and more like this) 

I tried with inline attributes:

 [component attr1 ="value1" attr2 ="value of the second one" ="value"... attrN ="valueN"] 

and the output will be as expected:

 Array ( [attr1] => value1 [attr2] => value of the second one [attr3] => //...and so on) 

Is there any way to have attributes and avoid this extra markup that splits the $args array?

+4
source share
1 answer

accepted answer - credit @Stephen

Well, I never saw a short code made this way, so I put together some code to test your script. And I get the same results with code that works great with standard shortcode code.

Standard Shortcode Format

 [shortcode name1="value1" name2="value2"] 

I do not believe that this is the result of wpautop (), but the result of how the shortcode attributes are parsed. Take a look at the above example and you will see that to separate short letters and pairs of name => values, only spaces without spaces are used (ie there are no spaces between the name and "=", only one space between each name => value pair ) In this context
also considered a space.

I have not succumbed to specific internal short code parsing, so I cannot offer a hook or filter suggestion that will help. Another user may have some ideas.

If you have to format your short code as if you have one, I think you will have to write your own code to parse the array passed to your short code function. All values ​​are there so you can put them together.

Another option would be to provide a form for the end user to enter values ​​and then fill out a short code in your content.

Update my answer

Something about my answer overheard me, so I looked again. And you are right. Wpautop () affects page output. But I do not think that this is the reason for your problems with short numbers.

0
source

Source: https://habr.com/ru/post/1444321/


All Articles