0

I am setting up some member self-service pages, restricting access using the 'Members' plugin, to show (on separate pages):

  • a profile to allow members to update their details via [civicrm component="profile" mode="edit" gid="1"] (different errors depending on view or edit modes)
  • Dashboard so that invoices and event bookings are visible via [civicrm component="user-dashboard"]

But still getting the following error:

  • Error with anonymous / not logged in user and viewing profile (if the mode="edit" then redirects to homepage) Error with anonymous user and viewing profile

  • Error with anonymous / not logged in user and viewing Dashboard Error with anonymous user and Dashboard

'Members' plugin is working as expected and I can successfully set it up to restrict content and show custom messages. CiviCRM permissions appear to be correct / default.

I was not expecting to get any CiviCRM error messages as the content was restricted and not showing, though something is triggering the error messages / redirection.

I have checked with a clean install of both WordPress (5.4.1) and CiviCRM (5.25.0 and 5.26.0), and even used other plugins that do similar content restriction but all to the same end.

I am pretty new to CiviCRM so any suggestions as to fix this / or where to look would be much appreciated.

The back trace posted below for the view profile states 'Could not find the required contact id parameter (id=) for viewing a contact ...' which is understandable, though why it is trying to find contact id when the content is restricted is puzzling me.

backTrace

#0 [...]/wp-content/plugins/civicrm/civicrm/CRM/Core/Error.php(337): CRM_Core_Error::backtrace()
#1 [...]/wp-content/plugins/civicrm/civicrm/CRM/Profile/Page/View.php(52): CRM_Core_Error::fatal("Could not find the required contact id parameter (id=) for viewing a contact ...")
#2 [...]/wp-content/plugins/civicrm/civicrm/CRM/Profile/Page/View.php(152): CRM_Profile_Page_View->preProcess()
#3 [...]/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(311): CRM_Profile_Page_View->run((Array:3), NULL)
#4 [...]/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(68): CRM_Core_Invoke::runItem((Array:13))
#5 [...]/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(36): CRM_Core_Invoke::_invoke((Array:3))
#6 [...]/wp-content/plugins/civicrm/civicrm.php(1479): CRM_Core_Invoke::invoke((Array:3))
#7 [...]/wp-content/plugins/civicrm/includes/civicrm.shortcodes.php(328): CiviCRM_For_WordPress->invoke()
#8 [...]/wp-includes/shortcodes.php(343): CiviCRM_For_WordPress_Shortcodes->render_single((Array:3), "", "civicrm")
#9 [internal function](): do_shortcode_tag((Array:7))
#10 [...]/wp-includes/shortcodes.php(218): preg_replace_callback("/\[(\[?)(civicrm)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\...", "do_shortcode_tag", "[civicrm component=\"profile\" mode=\"view\" gid=\"1\"]")
#11 [...]/wp-content/plugins/civicrm/includes/civicrm.shortcodes.php(214): do_shortcode("[civicrm component=\"profile\" mode=\"view\" gid=\"1\"]")
#12 [...]/wp-includes/class-wp-hook.php(287): CiviCRM_For_WordPress_Shortcodes->prerender(Object(WP))
#13 [...]/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters("", (Array:1))
#14 [...]/wp-includes/plugin.php(544): WP_Hook->do_action((Array:1))
#15 [...]/wp-includes/class-wp.php(748): do_action_ref_array("wp", (Array:1))
#16 [...]/wp-includes/functions.php(1274): WP->main("")
#17 [...]/wp-blog-header.php(16): wp()
#18 [...]/index.php(17): require("[...]/wp-blog-header.php")
#19 {main}
2
  • In the CiviCRM shortcode [civicrm component="profile" mode="edit" gid="1"], can you confirm that gid="1" does relate to the relevant profile id that you should have set up in Administer>Customize data and screens>Profiles?
    – peterb
    Commented Jun 6, 2020 at 22:15
  • It does, I have tried it with profiles I have created (and default profiles). All the profiles (and the dashboard) work as expected as a functional profile with a logged in user. Commented Jun 7, 2020 at 8:44

2 Answers 2

1

I have found a partial solution...

To wrap the CiviCRM shortcode in a Members shortcode (which would have been the 'old' / pre-gutenberg block way to do it)

[members_logged_in][civicrm component="user-dashboard"][/members_logged_in]

The content is then restricted to logged in users (in this instance) and no visible errors are thrown, though while the form works it appears some Javascript/CSS is not loaded on the page when the shortcode is nested - which others have also come across here: Request login on edit mode profile form.

0

Digging a little deeper, I think I have discovered why the nesting of the shortcodes works.

  • CiviCRM html header is not present (1), resulting in
  • Uncaught ReferenceError: CRM is not defined (2)

So the page breaks at the point of validation meaning no errors are thrown. Resulting in an error solving an error.

Unfortunately I am at the limits of my knowledge to properly solve the original error, which looks like it is caused by either/and/or:

  • Members plugin not restricting content fully - though as I get the same error with similar plugins doing the same thing as the restriction is only on page content rather than in the header so perhaps a fix is needed elsewhere if inclusions in the header cannot be restricted
  • WordPress continuing to load content even though a plugin has restricted it - which it isn't as the scripts and styles are loaded in the header which the plugin does not restrict.

However fixing both of those would then result in CRM validation which would throw the original error...

Could the CiviCRM shortcode have parameters to either fail silently (which means the WordPress plugin / WordPress code could continue its business), or have similar restriction functionality baked in so that CiviCRM code can do all the hard work.

(1)

<!-- CiviCRM html header -->
<script type="text/javascript">
var CRM = {"config":{"isFrontend":true,"wysisygScriptLocation":"\/wordpress\/wp-content\/plugins\/civicrm\/civicrm\/js\/wysiwyg\/crm.ckeditor.js","CKEditorCustomConfig":{"default":"https:\/\/[...]\/uploads\/civicrm\/persist\/crm-ckeditor-default.js"}}};
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/bower_components/jquery/dist/jquery.min.js">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/bower_components/jquery-ui/jquery-ui.min.js">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/bower_components/lodash-compat/lodash.min.js">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/packages/jquery/plugins/jquery.mousewheel.min.js">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/bower_components/select2/select2.min.js">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/packages/jquery/plugins/jquery.form.min.js">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/packages/jquery/plugins/jquery.timeentry.min.js">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/packages/jquery/plugins/jquery.blockUI.min.js">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/bower_components/datatables/media/js/jquery.dataTables.min.js">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/bower_components/jquery-validation/dist/jquery.validate.min.js">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/packages/jquery/plugins/jquery.ui.datepicker.validation.min.js">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/js/Common.js?r=pLAwt">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/js/crm.datepicker.js?r=pLAwt">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/js/crm.ajax.js?r=pLAwt">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/js/wysiwyg/crm.wysiwyg.js?r=pLAwt">
</script>
<script type="text/javascript" src="https://[...]/crm/ajax/l10n-js/en_GB/?cid=2&r=pLAwt">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/packages/jquery/plugins/jquery.tableHeader.js">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/packages/jquery/plugins/jquery.notify.min.js">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/js/crm.optionEdit.js?r=pLAwt">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/bower_components/jquery-ui/ui/i18n/datepicker-en-GB.js">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/js/crm.wordpress.js?r=pLAwt">
</script>
<link href="https://[...]/plugins/civicrm/civicrm/css/crm-i.css?r=pLAwt" rel="stylesheet" type="text/css"/>
<link href="https://[...]/plugins/civicrm/civicrm/bower_components/datatables/media/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css"/>
<link href="https://[...]/plugins/civicrm/civicrm/bower_components/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
<link href="https://[...]/plugins/civicrm/civicrm/bower_components/jquery-ui/themes/smoothness/jquery-ui.min.css" rel="stylesheet" type="text/css"/>
<link href="https://[...]/plugins/civicrm/civicrm/bower_components/select2/select2.min.css" rel="stylesheet" type="text/css"/>
<link href="https://[...]/plugins/civicrm/civicrm/css/searchForm.css?r=pLAwt" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/js/crm.searchForm.js?r=pLAwt">
</script>
<script type="text/javascript" src="https://[...]/plugins/civicrm/civicrm/js/noconflict.js?r=pLAwt">
</script>

(2)

  <script type="text/javascript">
    CRM.$(function($) {
      $("form.CRM_Contact_Form_GroupContact").crmValidate();
    });
  </script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.