I'm using eval cv php:boot in a script. I need to be able to delete a contact in the script, including the skip_undelete flag, but this action is denied - get a "could not delete contact" error.

I learnt that in Drupal this happens when you're bootstrapped but not as the admin user, but I'm unfamiliar with what Wordpress's equivalent would be, and whether it's possible to do this using cv?


PS. I'm writing a phpunit test (not a unit test) for a wordpress integration plugin (not a CiviCRM extension) that makes various API calls. I am running this against a real world database, not a buildkit one, so it's not appropriate to use the extension-style phpunit tests which start by tearing out your data :-)

  • Wow, someone has heard of cv! Even at CiviCRM sprints most folks haven't seen it before. – Jon G - Megaphone Tech Oct 29 '16 at 0:43

I recently pushed b3db22c002a5d16ae3715b97b58f3f64a1526a3a -- which adds the --user (-U) option and seems to work in WP/D7 (but hasn't been exhaustively tested). Try downloading the latest build of cv.

| improve this answer | |

If wp-cli is an option, it takes a --user option, similarly to drush.

If that's not an option, looking at the wp-cli source code (here) suggests that wp_set_current_user() will do the trick.

| improve this answer | |
  • Thanks, Jon, yes I only just heard about cv at CiviCon London - had been doing my own hacky things before that. I'll check out your suggestion. I know it's for my own protection etc. but would be handy for testing to get elevated permissions simply. Sounds like I'm going to have to search through the WP users table for an administrator account and then use wp_set_current_user. Not enjoying developing CiviCRM stuff in wordpress...! Thanks anyway, will check it out (prob. on Monday now) – artfulrobot Oct 29 '16 at 7:46

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.