Membership Plugin

WordPress Membership Plugin

  • Home
  • Documentation
  • Addons
  • Support
    • Quick Setup
    • Documentation
    • Premium Addon Support
    • Paid Support
    • Support Forum
    • Support Forum Search
    • Forum Login
    • Forum Registration
  • Contact

[Resolved] Post Custom Field – Post Prtection

Simple Membership Plugin › Forums › Simple Membership Plugin › Post Custom Field – Post Prtection

Tagged: custom field, protection

  • This topic has 8 replies, 2 voices, and was last updated 4 years, 5 months ago by Martin.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • January 19, 2022 at 4:21 pm #23491
    Martin
    Participant

    Hello! Congratulations for the great plug in
    I am using it since more than 3 years and it is working very well for me.

    Now I am trying to show in my post list if a post is protected or if it is free for all
    So I am looking in the post custom fields hoping to find a field that says if the post is protected or not.

    Is there this field?
    Can you please help me finding it?

    Thanks

    January 20, 2022 at 7:57 am #23494
    Eldon McGuinness
    Participant

    You could go the route of a shortcode:

    
    function swpm_is_protected() {
    	$protected = SwpmProtection::get_instance();
    	return ( $protected->is_protected( get_the_ID() ) == true ) ? 'Protected' : 'Public';
    }
    
    function swpm_shortcode_init(){
    	add_shortcode( 'swpm_protected', 'swpm_is_protected' );
    }
    add_action('init', 'swpm_shortcode_init');
    

    Then just use [swpm_protected] in your posts. Of course, you would want to format it and what not, but this would work.

    January 20, 2022 at 12:54 pm #23496
    Martin
    Participant

    Thank you for your help. I will try to use your code. Since I am not a coder I will have to find some help.

    January 20, 2022 at 4:37 pm #23497
    Eldon McGuinness
    Participant

    Put it at the end or your functions.php file and then you can just use [swpm_protected] in your posts and pages. If you’re looking for something more specific let me know.

    January 20, 2022 at 6:19 pm #23498
    Martin
    Participant

    Very kind of you to help me!
    I am grateful 🙂

    I tried to add at the end of functions.php but I get an error:

    Sintax error, unexpected $E0F

    I have pasted this code:

    /**
     *swpm post protection custom field
     */
    
    function swpm_is_protected() {
    	$protected = SwpmProtection::get_instance();
    	return ( $protected->is_protected( get_the_ID() ) == true ) ? 'Contenido Exclusivo Certificados FdB' : 'Contenido Libre';
    }
    
    function swpm_shortcode_init(){
    	add_shortcode( 'swpm_protected', 'swpm_is_protected' );
    }
    add_action('init', 'swpm_shortcode_init')
    January 21, 2022 at 7:09 pm #23504
    Eldon McGuinness
    Participant
    /**
     *swpm post protection custom field
     */
    
    function swpm_is_protected() {
    	$protected = SwpmProtection::get_instance();
    	return ( $protected->is_protected( get_the_ID() ) == true ) ? 'Contenido Exclusivo Certificados FdB' : 'Contenido Libre';
    }
    
    function swpm_shortcode_init(){
    	add_shortcode( 'swpm_protected', 'swpm_is_protected' );
    }
    add_action('init', 'swpm_shortcode_init');

    The last line was missing a ‘;’

    January 21, 2022 at 10:27 pm #23506
    Martin
    Participant

    This worked, thanks so much! 🙂

    Now when I use [swpm_protected] I get as an output like this:

    “{{ post_meta_value: Contenido Exclusivo Certificados FdB }}”

    I would like to have only the tex pat like this:

    “Contenido Exclusivo Certificados FdB”

    is there a simple way to achieve it?

    January 22, 2022 at 3:59 am #23508
    Eldon McGuinness
    Participant

    I’m not seeing that, instead, I’m seeing exactly what you said you wanted.

    January 22, 2022 at 11:19 am #23514
    Martin
    Participant

    Ok I solved that.
    It was because I am putting the shortcode inside wp bakery… Thanks you very much for your help, really appreciated.

  • Author
    Posts
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.
Log In

Please read this message before using our plugin.

Search

Featured Addons and Extensions

  • Membership Form Builder Addon
  • Member Directory Listing Addon
  • WooCommerce Payment Integration
  • Member Data Exporter Addon

Documentation

  • Documentation Index Page

Copyright © 2026 | Simple Membership Plugin | Privacy Policy