• Resolved Sauron

    (@sauron4u)


    Hello,
    Is it possiple to hide or display sertain widgets for non users, roles and/or sertain membership levels?

    For excample: Widget 1 is shown on my home page. Non users should not see this. Only membership lvl 1 should see what it contains and membership lvl2 should also not see this widget.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Mary Job

    (@mariaojob)

    Hi @sauron4u,

    Thank you for using Paid Memberships Pro.

    This can be done with a bit of custom code. Here is an example that should help you to get started: https://gist.github.com/kimcoleman/227edd825acbfd7aaaf5ba334c8c1482. To implement this, please reach out to a local WordPress developer for assistance.

    Kind regards.

    Thread Starter Sauron

    (@sauron4u)

    Is it possible to add more level ID that will be checked at the same time?
    for example:
    level 0 should show everything
    level 1,2,3,4,5,6,7,8,9 not allowed to show certain widgets?

    I can’t figure it out with the code because I can only indicate 1 level id at a time.
    my code is now

    /**

    • Hide widgets by widget instance ID for protected members only content.
    • Update the $hide_widget_instances_array with the array of widget instance IDs you want to filter.
    • Update the pmpro_hasMembershipLevel check for your membership level IDs.
      *
    • Add this code below to your PMPro Customizations Plugin – https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
      */
      function my_pmpro_widgets_by_membership_level( $instance, $widget, $args ) { // Set an array of widget areas by ID to filter.
      $hide_widget_instances_array = array( ‘bp_core_whos_online_widget-3’ ); // Check if this widget instance should be filtered.
      if ( in_array($widget->id, $hide_widget_instances_array ) && ! pmpro_hasMembershipLevel( 1, 2, 3, 4, 5, 6, 7, 8, 9 ) ) {
      return false;
      }
      return $instance;
      }
      add_filter(‘widget_display_callback’,’my_pmpro_widgets_by_membership_level’, 10 , 3 );
    Plugin Support Mary Job

    (@mariaojob)

    Hi @sauron4u, you should be able to add more than one membership level ID in that array:- && ! pmpro_hasMembershipLevel( 1, 2, 3, 4 ) ).

    I suggest you get in touch with your local WordPress developer for further assistance modifying that code example and getting it to work for your use-case.

    Thread Starter Sauron

    (@sauron4u)

    So more than 1 id doesn’t work. If I place more than 1 ID, it will show the widget to everyone for members and non-members.
    can you tell me if the code is correct?

    /**

    • Hide widgets by widget instance ID for protected members only content.
    • Update the $hide_widget_instances_array with the array of widget instance IDs you want to filter.
    • Update the pmpro_hasMembershipLevel check for your membership level IDs.
      *
    • Add this code below to your PMPro Customizations Plugin – https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
      */
      function my_pmpro_widgets_by_membership_level( $instance, $widget, $args ) { // Set an array of widget areas by ID to filter.
      $hide_widget_instances_array = array( ‘bp_core_whos_online_widget-3’ ); // Check if this widget instance should be filtered.
      if ( in_array($widget->id, $hide_widget_instances_array ) && ! pmpro_hasMembershipLevel( 2, 6, 7 ) ) {
      return false;
      }
      return $instance;
      }
      add_filter(‘widget_display_callback’,’my_pmpro_widgets_by_membership_level’, 10 , 3 );

    Plugin Author Andrew Lima

    (@andrewza)

    @sauron4u you will need to change the pmpro_hasMembershipLevel slightly.

    Please change it to pmpro_hasMembershipLevel( array( '2', '6', '7' ) ), for more information about this please see our documentation here: https://www.paidmembershipspro.com/documentation/content-controls/require-membership-function/


    Thank you for your patience.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘widget specified for sertain membership levels’ is closed to new replies.