CRM_Core_Permission_WordPress check function does not get all WP User capabilities after IPN return
I have been getting the following error when trying to load the thank you page after a Stripe payment contribution:
CRM_Contribute_Form_Contribution_Confirm::completeTransaction CiviCRM_API3_Exception: The requested Profile (gid= ) is disabled OR it is not configured to be used for 'Profile' listings in its Settings OR there is no Profile with that ID OR you do not have permission to access this profile. Please contact the site administrator if you need assistance.
All user roles have the correct Civicrm Capabilities to view the profile. After a lot of debugging I discovered that the CRM_Core_Permission_WordPress check function was not loading all the user's role capabilities. The function calls get_userdata or wp_get_current_user to get the user object:
$user = $userId ? get_userdata($userId) : wp_get_current_user();
In certain cases (i.e. the user not previously cached). These methods may not return all the capabilities of the user. They only load the basic user capabilities but may not include their role based capabilities.
The method WP_User::get_role_caps() should also be called to get the role base capabilities.
Here is an example user capabilities before get_role_caps() is called. As you can see none of the CiviCRM capabilities are listed:
Click to expand
[allcaps] => Array
(
[activate_plugins] => 1
[add_users] => 1
[create_users] => 1
[customize] => 1
[delete_others_pages] => 1
[delete_others_posts] => 1
[delete_pages] => 1
[delete_plugins] => 1
[delete_posts] => 1
[delete_private_pages] => 1
[delete_private_posts] => 1
[delete_published_pages] => 1
[delete_published_posts] => 1
[delete_themes] => 1
[delete_users] => 1
[edit_dashboard] => 1
[edit_files] => 1
[edit_others_pages] => 1
[edit_others_posts] => 1
[edit_pages] => 1
[edit_plugins] => 1
[edit_posts] => 1
[edit_private_pages] => 1
[edit_private_posts] => 1
[edit_published_pages] => 1
[edit_published_posts] => 1
[edit_theme_options] => 1
[edit_themes] => 1
[edit_users] => 1
[export] => 1
[import] => 1
[install_plugins] => 1
[install_themes] => 1
[list_users] => 1
[manage_categories] => 1
[manage_options] => 1
[moderate_comments] => 1
[promote_users] => 1
[publish_pages] => 1
[publish_posts] => 1
[read] => 1
[read_private_pages] => 1
[read_private_posts] => 1
[remove_users] => 1
[switch_themes] => 1
[unfiltered_html] => 1
[update_core] => 1
[update_plugins] => 1
[update_themes] => 1
[upload_files] => 1
[upload_plugins] => 1
[upload_themes] => 1
)
Here is the list of capabilities after get_role_caps() is called:
Click to expand
[allcaps] => Array
(
[0] => 1
[activate_plugins] => 1
[create_blocks] => 1
[create_posts] => 1
[create_users] => 1
[delete_blocks] => 1
[delete_others_blocks] => 1
[delete_others_pages] => 1
[delete_others_posts] => 1
[delete_pages] => 1
[delete_plugins] => 1
[delete_posts] => 1
[delete_private_blocks] => 1
[delete_private_pages] => 1
[delete_private_posts] => 1
[delete_published_blocks] => 1
[delete_published_pages] => 1
[delete_published_posts] => 1
[delete_themes] => 1
[delete_users] => 1
[edit_blocks] => 1
[edit_dashboard] => 1
[edit_files] => 1
[edit_manage_optionss] => 1
[edit_others_blocks] => 1
[edit_others_manage_optionss] => 1
[edit_others_pages] => 1
[edit_others_posts] => 1
[edit_pages] => 1
[edit_plugins] => 1
[edit_posts] => 1
[edit_private_blocks] => 1
[edit_private_pages] => 1
[edit_private_posts] => 1
[edit_published_blocks] => 1
[edit_published_pages] => 1
[edit_published_posts] => 1
[edit_theme_options] => 1
[edit_themes] => 1
[edit_users] => 1
[export] => 1
[import] => 1
[install_plugins] => 1
[install_themes] => 1
[list_users] => 1
[manage_categories] => 1
[manage_links] => 1
[manage_options] => 1
[moderate_comments] => 1
[promote_users] => 1
[publish_blocks] => 1
[publish_manage_optionss] => 1
[publish_pages] => 1
[publish_posts] => 1
[read] => 1
[read_blocks] => 1
[read_private_blocks] => 1
[read_private_manage_optionss] => 1
[read_private_pages] => 1
[read_private_posts] => 1
[remove_users] => 1
[switch_themes] => 1
[unfiltered_html] => 1
[unfiltered_upload] => 1
[update_core] => 1
[update_plugins] => 1
[update_themes] => 1
[upload_files] => 1
[access_civicrm] => 1
[access_ajax_api] => 1
[access_all_custom_data] => 1
[access_civicontribute] => 1
[access_civimail_subscribe_unsubscribe_pages] => 1
[access_civimember] => 1
[access_civireport] => 1
[access_contact_dashboard] => 1
[access_contact_reference_fields] => 1
[access_report_criteria] => 1
[access_uploaded_files] => 1
[add_contact_notes] => 1
[add_contacts] => 1
[delete_contacts] => 1
[delete_in_civicontribute] => 1
[delete_in_civimember] => 1
[edit_all_contacts] => 1
[edit_contributions] => 1
[edit_groups] => 1
[edit_inbound_email_basic_information] => 1
[edit_inbound_email_basic_information_and_content] => 1
[edit_memberships] => 1
[edit_my_contact] => 1
[make_online_contributions] => 1
[merge_duplicate_contacts] => 1
[profile_create] => 1
[profile_edit] => 1
[profile_listings] => 1
[profile_listings_and_forms] => 1
[profile_view] => 1
[register_for_events] => 1
[save_report_criteria] => 1
[view_all_activities] => 1
[view_all_contacts] => 1
[view_all_notes] => 1
[view_event_info] => 1
[view_my_contact] => 1
[view_my_invoices] => 1
[view_public_civimail_content] => 1
[administrator] => 1
[member] => 1
)
Thank You.