PAY PER VIEW PLUGIN – CUSTOM FIELDS PROTECTION

Hi,

I’m on a project for a client who wants to protect several fields of the plugin wp resume manager. So i followed this thread to integrate custom fields to the pay per view plugin:

https://premium.wpmudev.org/forums/topic/i-dont-know-how-to-integrate-the-plugin-pay-per-view?replies=15#post-716037

Unfortunately i think i missed something because my custom fields are well displayed, but, not protected !

i integrated this code to the template file :

<?php

if ( function_exists( ‘wpmudev_ppw_html’ ) ) {

$contrat = the_custom_field( ‘contrat’ );

$price = ‘0.01’;

$description = ‘test’;

global $ppw;

if ( !is_object( $ppw ) )

return;

$my_custom_field_ppv = $ppw->content( $contrat );

// Echo the content from our custom field after we pass it through PPV

echo $my_custom_field_ppv;

}

?>

Can you help me and say to me what i missed, because i really feel dumb right now !

Thank you !

Nicolas

  • Nahid
    • Tech Support

    Hey Nicolas ( BulleDigitale ) !

    Hope you are having a great day!

    The Pay Per View Usage Guide recommends using the wpmudev_ppw_html template function to protect any content outside of the post content.

    Please try using the following code instead in your preferred template file:

    <?php
    if ( function_exists( 'wpmudev_ppw_html' ) ) {
    $contrat = the_custom_field( 'contrat' ); // field to be protected (required)
    $description = 'test'; // Optional description of the protected content
    $price = '0.01'; // Optional price for a single view. If not set, price set in the post will be applied. If that is not set either, Unit Price in the Global Settings will be used
    echo wpmudev_ppw_html( $contrat, $description, $price );
    }
    ?>

    Hope this helps. Let me know if the above code works for you. Thanks!

    Kind regards,

    Nahid

  • BulleDigitale
    • WPMU DEV Initiate

    Thank you, it’s working! I had just to change “the_custom_field” by “get_custom_field” .

    <?php
    if ( function_exists( 'wpmudev_ppw_html' ) ) {
    $contrat = get_custom_field( 'contrat' ); // field to be protected (required)
    $description = 'test'; // Optional description of the protected content
    $price = '0.01'; // Optional price for a single view. If not set, price set in the post will be applied. If that is not set either, Unit Price in the Global Settings will be used
    echo wpmudev_ppw_html( $contrat, $description, $price );
    }
    ?>

    I have another question :

    Is there any possibility to add more custom fields ? How can i do that ?

    Thank you for your help Nahid !

  • Dimitris
    • Support Star

    Hello there BulleDigitale,

    hope you’re doing good today! :slight_smile:

    In order to protect multiple custom fields, you just have to duplicate above snippet for each one of them, like:

    <?php
    if ( function_exists( 'wpmudev_ppw_html' ) ) {

    $contrat = get_custom_field( 'contrat' ); // field to be protected (required)
    $description = 'test'; // Optional description of the protected content
    $price = '0.01'; // Optional price for a single view. If not set, price set in the post will be applied. If that is not set either, Unit Price in the Global Settings will be used
    echo wpmudev_ppw_html( $contrat, $description, $price );

    $other = get_custom_field( 'other' ); // field to be protected (required)
    $otherdescription = 'other'; // Optional description of the protected content
    $otherprice = '0.01'; // Optional price for a single view. If not set, price set in the post will be applied. If that is not set either, Unit Price in the Global Settings will be used
    echo wpmudev_ppw_html( $other, $otherdescription, $otherprice );
    }
    ?>

    Please let us know, if I miss something else here and if so please elaborate a bit more on this! :slight_smile:

    Warm regards,

    Dimitris

  • Dimitris
    • Support Star

    Can you try something like the following snippet then?

    Concept here is to concatenate the custom fields in the Pay Per View argument.

    <?php
    if ( function_exists( 'wpmudev_ppw_html' ) ) {

    $contrat = get_custom_field( 'contrat' ); // field to be protected (required)
    $contrat .= get_custom_field( 'other' ); // field to be protected (required)
    $description = 'test'; // Optional description of the protected content
    $price = '0.01'; // Optional price for a single view. If not set, price set in the post will be applied. If that is not set either, Unit Price in the Global Settings will be used
    echo wpmudev_ppw_html( $contrat, $description, $price );
    }
    ?>

    Cheers,

    Dimitris

  • Dimitris
    • Support Star

    Glad to know that! :smiley:

    I don’t think that there’s any restriction on what to use in this variable.

    A simply test will reveal this to you. :wink:

    You can go like:

    <?php
    $contrat = '<div class="protected-fields">'; //opening tag
    $contrat .= get_custom_field( 'contrat' );
    $contrat .= get_custom_field( 'other' );
    $contrat .= '</div>'; //closing tag

    Warm regards,

    Dimitris

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.