CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • WordPress: Using Civi membership to control access to members' area
Pages: [1]

Author Topic: WordPress: Using Civi membership to control access to members' area  (Read 833 times)

wingfingerbill

  • I’m new here
  • *
  • Posts: 18
  • Karma: 1
  • CiviCRM version: 4.4.14
  • CMS version: WordPress 4.1.1
  • MySQL version: 5.6.23
  • PHP version: 5.5.23
WordPress: Using Civi membership to control access to members' area
August 08, 2012, 03:08:19 am
This may be of interest to some - and (of course) there may be a better way of doing this.

I've been working on a WordPress-based reverse-synch system...

Whenever a Civi membership is created/edited, the WordPress user table is checked to see if there's a user that's already associated with that Civi contact (via a customfield 'cc_id'). If not, it then looks for a matching email - and if that fails, a new WordPress user is created.

The upshot of this is that I can now (well - maybe another 4hrs work!) use Civi membership to control access to a Members' Area.

Two core hacks were required:
  • an escape route from function _civicrm_update_user( $userID ) in civicrm/civicrm.php in order to prevent Civi creating a new contact when the new WP user is created
  • a call to my function do_wp_member_update($cc_id) from civicrm/civicrm/CRM/Member/BAO/Membership.php.

If I knew how to make use of Civi's membership-edit and membership-create hooks from WordPress, I wouldn't need that second hack. Is anybody working on this?

Cheers

Bill

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: WordPress: Using Civi membership to control access to members' area
August 08, 2012, 12:33:20 pm
Hi,

Not sure how it works on WP, but that's quite easy to write a hook in general (basically a function with the right name at the right place).

The new extension and civix system allows to create these extensions at the civicrm level and works for drupal joomla and wordpress, check it out.

As for the first hook, you might be able to use the civicrm_contact_pre_save and skip the acount creation (or pre-fill the contact id). I don't think the context is clear (ie. you can't easily be sure if it's a regular contact creation or a contact after user, but you might/should be able by testing the url (if it's civicrm/contact it's normal, if it's /user/create or whatever, it's creation)

The last one is not super pretty, but avoid hacking the core

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

wingfingerbill

  • I’m new here
  • *
  • Posts: 18
  • Karma: 1
  • CiviCRM version: 4.4.14
  • CMS version: WordPress 4.1.1
  • MySQL version: 5.6.23
  • PHP version: 5.5.23
Re: WordPress: Using Civi membership to control access to members' area
August 09, 2012, 01:54:59 am
Quote
Not sure how it works on WP, but that's quite easy to write a hook in general (basically a function with the right name at the right place).

To add an action to a hook in WP I'd do:

Code: [Select]
add_action('hook_name', 'my_function_name');
I need to get to grips with how WP implements this, so that can I add an action to a Civi hook in a similar way.

I'll check out the extension/plugin stuff too.

Thanks again :)

Bill

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • WordPress: Using Civi membership to control access to members' area

This forum was archived on 2017-11-26.