latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Custom Capability control over Custom Fields

Home Forums Community Forum Custom Capability control over Custom Fields

This topic contains 3 replies, has 2 voices. Last updated by  SusanJ 3 years, 9 months ago.

Topic Author Topic
Posted: Friday Mar 8th, 2013 at 3:37 pm #44128
SusanJ
Username: susan

Currently, you can assign Custom Registration/Profile Fields availability to S2Member roles through the “Applicable Membership Levels” attribute of the custom field. Would it be possible to add the ability to S2Member to control these fields application based on Custom Capabilities?

We are trying to limit the number of member levels we use so that the number of roles does not get out of hand and instead control minor differences using Custom Capabilities. (As I think is suggested in Jason’s video tutorials.) But, the one area I’ve been unable to do this in is with controlling which profile fields a user sees.

Thanks

List Of Topic Replies

Viewing 3 replies - 1 through 3 (of 3 total)
Author Replies
Author Replies
Posted: Monday Mar 11th, 2013 at 10:27 am #44257
Eduan
Username: Eduan
Moderator

Hello Susan,

I’ll ask to Jason about this, and add it as a feature request.

– Eduan

Posted: Friday Mar 15th, 2013 at 4:42 pm #44747
Eduan
Username: Eduan
Moderator

Here’s what he answered:

This is NOT a finished piece of work, but it demonstrates how you might accomplish this with s2Member®.

Please create this directory and file:
/wp-content/mu-plugins/s2-hacks.php
(NOTE: these are MUST USE plugins, see: http://codex.wordpress.org/Must_Use_Plugins)
(See also: http://www.s2member.com/kb/hacking-s2member/)

<?php
add_filter('ws_plugin__s2member_custom_fields_configured_at_level', 's2_limit_custom_fields_further', 10, 2);
function s2_limit_custom_fields_further($fields, $vars)
    {
        if($vars['_editable_context'] !== 'profile' || current_user_can('edit_users'))
            return $fields; // Do NOT filter them any further in this case.

        // Else let's look at each field ID and Custom Capabilities.

        foreach($fields as $_key => $field_id)
            {
                switch($field_id)
                    {
                        case 'my_unique_field_id':
                            if(!current_user_can('access_s2member_ccap_music'))
                                unset($fields[$_key]);
                            break;

                        case 'another_unique_field_id':
                            if(!current_user_can('access_s2member_ccap_videos'))
                                unset($fields[$_key]);
                            break;

                        default:
                            break; // Allow the field to be edited.
                    }
            }
        return $fields;
    }
Posted: Saturday Mar 16th, 2013 at 3:24 am #44905
SusanJ
Username: susan

Thanks. That code make sense to me and I’ll try it out soon.

Viewing 3 replies - 1 through 3 (of 3 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.