2

CMS: Wordpress 4.9.6

CiviCRM: 5.2.1

I'm trying to generate Invoice with the below url, Which is working fine when I login as administrator. but when I login as actual member to download Invoice from WordPress front end with the same url giving me this error

  Sorry, you are not allowed to access this page.

( I gave this civi permission

CiviCRM: view my invoices 
Allow users to view/ download their own invoices

to all user roles). enter image description here

http://devsri.mywebsite.com/wp-admin/admin.php?page=CiviCRM&q=civicrm/contribute/invoice&reset=1&id=48657&cid=35509

Its working when I give below(CiviCRM: access CiviCRM backend and API)permission

"CiviCRM: access CiviCRM backend and API" Master control for access to the main CiviCRM backend and API. Give to trusted roles only.

enter image description here

But I cant give this permission to a member just to download Invoice. In drupal its working with "CiviCRM: view my invoices" permission. I wonder if its a bug in Civi Wordpress??

Did anyone experience this? or Am I missing anything here?

TIA

  • Probably this link(civicrm.stackexchange.com/questions/24616/…) might help you. HTH Pradeep – Pradeep Nayak Jun 29 '18 at 11:46
  • Thanks Pradeep, but "View my invoices" permission is enabled for my wordpress. In drupal I tried it with the same permissoin, its working fine on drupal. I feel its a wordpress issue. I tried to check "mywebsite/wp-content/plugins/civicrm/civicrm/CRM/Contribute/Form/Task/Invoice.php" file, its not coming to "public static function getPrintPDF" function. seems wordpress permissions is having some issue in civi. – Developer Jun 29 '18 at 11:52
  • I think you will provide access civicrm permission. – Pradeep Nayak Jun 29 '18 at 12:17
  • Or you can try devsri.mywebsite.com/… – Pradeep Nayak Jun 29 '18 at 12:18
  • I'm getting this error after change url."The requested URL /default-civipage was not found on this server." – Developer Jun 29 '18 at 12:54
2

I found the problem here. actually there is some issue with CiviCRM Wordpress codebase because its always failing to get wordpress user id.

Below checkDownloadInvoice function using drupal global $user; to get logged in user id for wordpress as well.

CRM_Core_Permission::checkDownloadInvoice

public static function checkDownloadInvoice() {
    global $user;
    $cid = CRM_Core_BAO_UFMatch::getContactId($user->uid);
    if (CRM_Core_Permission::check('access CiviContribute') ||
      (CRM_Core_Permission::check('view my invoices') && $_GET['cid'] == $cid)
    ) {
      return TRUE;
    }
    return FALSE;
  }

for WordPress It should be changed to

public static function checkDownloadInvoice() {
    $uid = get_current_user_id();//changed for WordPress
    $cid = CRM_Core_BAO_UFMatch::getContactId($uid);//changed for WordPress
    if (CRM_Core_Permission::check('access CiviContribute') ||
      (CRM_Core_Permission::check('view my invoices') && $_GET['cid'] == $cid)
    ) {
      return TRUE;
    }
    return FALSE;
  }

Hope it helps someone in future. :)

  • You should put this in the issue queue – Tony Horrocks Jan 18 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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