• Resolved Law

    (@laucoste)


    Hello,

    I need to use a restriction-content shortcode from the plugin https://simple-membership-plugin.com and to apply this content-restriction to some displayed elements of the Asgaros forum.

    Precisely, I want to hide the new topic form (all its elements : title, content, submit button…). Thus, it could show only a specific message to the users who have the restriction. This message and the restriction are completely managed by the above plugin.

    By testing the shortcode allowing that, the opening bracket of the shortcode is OK : the message is displayed.
    But the closing bracket is not considered as a shortcode (always displayed as a simple text). The consequence is that the shortcode is not interpreted, and the form that I want to want is displayed.

    Modified file : includes/forum-editor.php

    Used shortcode, 2 ways :
    echo do_shortcode(‘[swpm_protected for=”2-3″]’);
    echo do_shortcode(‘[/swpm_protected]’);
    //or
    <?php echo do_shortcode(‘[swpm_protected for=”2-3″]’); ?>
    <?php echo do_shortcode(‘[/swpm_protected]’); ?>

    Do you see how I could manage that ? Where to place precisely this shortcode ?

    I hope this topic is not too specific about the other plugin. I think it is more about the management / integration of shortcodes to Asgaros forum, so that could help many users.

    Thanks you so much for your help,

    Law

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Asgaros

    (@asgaros)

    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>

    Plugin Author Asgaros

    (@asgaros)

    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]');

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Using a shortcode from another plugin to hide forum content’ is closed to new replies.