Support » Plugin: WP Blog and Widget » How to properly use code from another plugin to protect the content from blog

  • Resolved jrinderknecht

    (@jrinderknecht)


    I am using an Activello childtheme. Both plugins referenced are up to date.

    I would like to use a code snippet and add it to the template for your Blog plugin. This code snippet is provided by another plugin which is a pro membership plugin. The purpose of the code is to require the user have 1 of 2 levels of membership else the content is not displayed. Usually the plugin provides checkboxes to check, that require membership to view content, within the dashboard. These checkboxes are not available with using your Blog plugin within the dashboard. I have found a shortcode to use and place in the blog, however I have 67 existing pages I need to add the content controls to. So I am trying to find a more streamlined approach.

    If the code is placed in the template now would all 67 Blog entries be protected retroactively? Would placing the shortcode on the blog pages be the best way?
    I’ve looked for the code that was marked as the template code and could not find it in my files in the plugin folder.

    I would like help pinpointing where I should place this code in the template:

    Check for any membership levels with ID 12, 14 or name=Gold

    <?php
    if(pmpro_hasMembershipLevel(array(’12’,’14’,’Gold’)))
    {
    ?>
    //Place your HTML or PHP code here if the user is in the required membership level
    …
    <?php
    }
    ?>

    [Moderator note: code fixed. Please wrap code in the backtick character or use the code button.]

    The reason content is being controlled is because the blogs that are part of the membership are accessible through the page search function when a user is not logged in. We could remove the search bar however the content could still be indexed and displayed using a browser search tool.

    • This topic was modified 5 years, 5 months ago by bdbrown.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Anoop Ranawat

    (@anoopranawat)

    Hello,

    If you are using ‘blog’ short-code then you can edit the short-code file located at:
    wp-blog-and-widgets -> wp-blog-and-widgets.php

    open this file and write your condition before ‘IF’ condition starts at line no: 234

    Hope this will be helpful to you.

    Thread Starter jrinderknecht

    (@jrinderknecht)

    Thank You.

    Moderator I apologize for the incorrect posting of code. Will keep that note and refresh myself on the rules for support posting. The shortcodes we were using in the actual pages ‘[membership]
    ….Blog entry
    [/membership]’ were restricting content of the logged in members.
    Instead of using the code from PM pro we decided to do this: It works great.

    if ( !is_user_logged_in() ) {
        echo '<style="display:none;">';
    } else {
     $args = array (
     ... 
     }
    }

    Thank you for your assistance in placement to the template and giving me the exact line number. That was very helpful. It worked right away.

    Thread Starter jrinderknecht

    (@jrinderknecht)

    Well I supposed it was good learning above. It was not the solution as my page looked steamrolled after I used that code. Rewrote for this logical solution.

    if ( is_user_logged_in() ) {
                
    
        $args = array(
    
            ...
        );
    
        register_taxonomy( 'blog-category', array( 'blog_post' ), $args );
    
    }
    
    }

    {Moderator note: tickmarks need to go at the beginning and end of code. Or, just highlight the code block and click the [code] button}

    • This reply was modified 5 years, 5 months ago by bdbrown.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to properly use code from another plugin to protect the content from blog’ is closed to new replies.