• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

QUESTION Use separated php codes inside of multiple short codes

Messages
7
Likes
0
Points
1
#1
Hello
I wanna to write separated codes inside of two Snippets like bellow codes but it’s not working

Part 1 :
PHP:
if( is_user_logged_in() ) {
Part 2 :
PHP:
} else {
echo “You must be logged in to download the file.”;
}
Actually should be use below codes in one post which is not working and I got an error

[wbcr_php_snippet id=”1″ title=”Start Check”]
Welcome to WordPress. This is your first post. Edit or delete it, then start writing!
[wbcr_php_snippet id=”2″ title=”End Check”]

please note that : I need to this separated codes cause to use different texts or links inside of different posts so I’ve to find eventually a solution ?
 

alexkovalev

Program developer
Staff member
Messages
235
Likes
18
Points
18
#2
Hi,

Currently, plugin does not support this syntax. But I am preparing to release an update in which I can do this way of posting.

For example, take the shortcode:
Code:
[wbcr_php_snippet id="1" title="Start Check"]
Welcome to WordPress. This is your first post. Edit or delete it, then start writing!
[/wbcr_php_snippet]
In snippet, will be passed $content variable, it will look like this:
Code:
if( is_user_logged_in() ) {
echo $content;
} else {
echo "You must be logged in to download the file.";
}
Let me know if this solution is right for you.

Best regards, Alex
 
Messages
7
Likes
0
Points
1
#3
Thanks but I think "$content" load all of texts and pictures into the variable. I would like to use part of custom text and picture inside that in per post !
 

alexkovalev

Program developer
Staff member
Messages
235
Likes
18
Points
18
#4
I still do not understand why this will not work for you? Everything that you put inside the shortcode is passed to a variable, and you can process it in a snippet.

Code:
POST 1
[wbcr_php_snippet id="1" title="Start Check"]
TEXT1
IMAGE 1
[/wbcr_php_snippet]

POST 2
[wbcr_php_snippet id="1" title="Start Check"]
TEXT2
IMAGE 3
[/wbcr_php_snippet]

POST 3
[wbcr_php_snippet id="1" title="Start Check"]
TEXT3
IMAGE 3
[/wbcr_php_snippet]
Do you have any ideas how this can be done in an alternative way?
 
Messages
7
Likes
0
Points
1
#5
because I've opened IF tag (I think you didn't see exactly my code)

Part 1 :
Code:
if( is_user_logged_in() ) {
and I would like to close it where I want

Part 2 :
Code:
} else {
echo “You must be logged in to download the file.”;
}
this problem happens when use "{" without "}" while I've used it in part 2 for close IF tag !
 
Messages
7
Likes
0
Points
1
#7
it's exactly my code ! just changed text inside that
and I've loaded below short codes that not working

Code:
[wbcr_php_snippet id="1138" title="Start Download"]
Welcome to WordPress. This is your first post. Edit or delete it, then start writing!
[wbcr_php_snippet id="1139" title="End Download"]
It's error that I got
Code:
Parse error: syntax error, unexpected end of file in /public_html/wp-content/plugins/insert-php/includes/shortcodes.php(66) : eval()'d code on line 2
and it will be solved when I close IF tag in first part and add start tag to part 2 , anyway I could not split IF tag into two short codes
 

alexkovalev

Program developer
Staff member
Messages
235
Likes
18
Points
18
#8
Ok, I understand perfectly what you want. But can you show the code for which my solution will not work?

P.S. Since you want to do in the plugin will not work and technically it is not right to do. You can rollback to old version of the plugin 1.3, where you can still use php code in tinyMce editor.
 
Messages
7
Likes
0
Points
1
#9
You can rollback to old version of the plugin 1.3, where you can still use php code in tinyMce editor.
I know , but I want to make friendly environment for my authors to add posts , old version is hard for amateur authors and they are not familiar with php codes so I want to use short codes for them
 

alexkovalev

Program developer
Staff member
Messages
235
Likes
18
Points
18
#10
Just give me a case when my decision does not work for you. Give code samples and I will write you, how to fix this problem. My example is an alternative to your idea and it should work the way you want. It is very simple and safe for your users.

I will do this in the near release of plugin.
 
Messages
7
Likes
0
Points
1
#11
none of your solutions are not working for me , for understand better please see attached files for start_if , end_if , post

start_if.PNG end_if.PNG post.PNG
 

alexkovalev

Program developer
Staff member
Messages
235
Likes
18
Points
18
#12
Unfortunately, I can not help you. Try to find other solutions, there are many alternatives.
 

Kirill

Support team
Messages
82
Likes
4
Points
8
#14
do you have any changes for fix about my request in next version ?
Sorry, we can not solve the issue in the way that you suggested. Because it will cause other problems.
We can implement solution by Alex if needed.


Thanks but I think "$content" load all of texts and pictures into the variable. I would like to use part of custom text and picture inside that in per post !
$content is predefined variable in plugin that will contain the text between the shortcode open tag and close tag.
Example:
Page text1
[wbcr_php_snippet id="1"]
Welcome to WordPress. This is your first post. Edit or delete it, then start writing!
[/wbcr_php_snippet]
page text2

// $content contains only "Welcome to WordPress. This is your first post. Edit or delete it, then start writing!"