Hello @laucoste
Basically the do_shortcode function has to include the opening-shortcode AND the ending-shortcode containing the content between. This is not your case in your example because the actual logic is outside and the second closing-shortcode doesnt know whats going on because its not related to the opening-one anymore.
So basically what you have to do is to “save” the output you want to hide inside of a string and place it between like this:
echo do_shortcode(‘[swpm_protected for=”2-3″]’.$output.‘[/swpm_protected]’);
Thread Starter
Law
(@laucoste)
Hello,
Thank you for your reply. I just copy below a piece of code from forum-editor.php file.
I hope the interesting part for my need is in these lines of code.
So, with :
echo do_shortcode(‘[swpm_protected for=”2-3″]’.$output.‘[/swpm_protected]’);
May I replace $output by $editor_view to hide the content editor for example ?
I want to hide every parts from the title to the submit button, so which value do I have to consider ?
Then, where to place it in the below code ? I hope you can help me about that, I am touching my goal.
Best regards,
Law
—————-
<form id=”forum-editor-form” class=”<?php echo $editor_view; ?>-editor” tabindex=”-1″ name=”addform” method=”post” action=”<?php echo $actionURL; ?>” enctype=”multipart/form-data”<?php if ($inOtherView && !isset($_POST[‘subject’]) && !isset($_POST[‘message’])) { echo ‘ style=”display: none;”‘; } ?>>
<div class=”title-element”><?php if ($inOtherView) { echo $editorTitle; } ?></div>
<div class=”editor-element”>
<?php if ($editor_view === ‘addtopic’ || ($editor_view == ‘editpost’ && $this->asgarosforum->is_first_post($post->id))) { ?>
<div class=”editor-row-subject”>
<label for=”subject”><?php _e(‘Subject:’, ‘asgaros-forum’); ?></label>
<span>
<input class=”editor-subject-input” type=”text” id=”subject” maxlength=”255″ name=”subject” value=”<?php echo esc_html(stripslashes($subject)); ?>”>
</span>
</div>
<?php
}
echo ‘<div class=”editor-row no-padding”>’;
wp_editor(stripslashes($message), ‘message’, $this->asgarosforum->options_editor);
echo ‘</div>’;
$this->asgarosforum->uploads->show_editor_upload_form($post);
$this->asgarosforum->notifications->show_editor_subscription_option();
do_action(‘asgarosforum_editor_custom_content_bottom’, $editor_view);
echo ‘<div class=”editor-row editor-row-submit”>’;
if ($editor_view === ‘addtopic’) {
echo ‘<input type=”hidden” name=”submit_action” value=”add_topic”>’;
} else if ($editor_view === ‘addpost’) {
echo ‘<input type=”hidden” name=”submit_action” value=”add_post”>’;
} else if ($editor_view === ‘editpost’) {
echo ‘<input type=”hidden” name=”submit_action” value=”edit_post”>’;
}
echo ‘<div class=”left”>’;
if ($inOtherView) {
echo ‘‘.__(‘Cancel’, ‘asgaros-forum’).’‘;
} else {
if ($editor_view === ‘editpost’) {
$actionURL = $this->asgarosforum->get_link(‘topic’, $this->asgarosforum->current_topic);
}
echo ‘‘.__(‘Cancel’, ‘asgaros-forum’).’‘;
}
echo ‘</div>’;
echo ‘<div class=”right”><input class=”button button-normal” type=”submit” value=”‘.__(‘Submit’, ‘asgaros-forum’).'”></div>’;
echo ‘</div>’;
echo ‘</div>’;
echo ‘</form>
Hello @laucoste
Basically you need to collect every output in a variable first and then apply it inside of the shortcode. This requires a lot of restructuring of the function you have mentioned, so I cannot post you the complete one:
$output = '<form id=”forum-editor-form” class=”<?php echo $editor_view; ?>-editor” tabindex=”-1″ name=”addform” method=”post” action=”<?php echo $actionURL; ?>” enctype=”multipart/form-data”<?php if ($inOtherView && !isset($_POST[‘subject’]) && !isset($_POST[‘message’])) { echo ‘ style=”display: none;”‘; } ?>>';
$output .= '<div class=”title-element”><?php if ($inOtherView) { echo $editorTitle; } ?></div>';
// etc ...
In case the variable $output contains all generated html, at the end you have to run the following code:
do_shortcode('[swpm_protected for="2-3"]'.$output.'[/swpm_protected]');