Answers.Body: <p>If <a href="http://wp-cli.org">wp-cli</a> is an option, it takes a <code>--user</code> option, similarly to drush.</p>
  
  <p>If that's not an option, looking at the wp-cli source code (<a href="https://github.com/wp-cli/wp-cli/blob/e571f3c644ad5d4356ab54c5b6d1beb1e29e65a8/php/WP_CLI/Runner.php#L1131">here</a>) suggests that <code>wp_set_current_user()</code> will do the trick.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-29T07:46:43.293Z
Answers.Text: 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)
Answers.UserDisplayName: artfulrobot
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-29T00:53:16.363Z
Answers.LastActivityDate: 2016-10-29T00:53:16.363Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.Body: <p>I recently pushed <a href="https://github.com/civicrm/cv/commit/b3db22c002a5d16ae3715b97b58f3f64a1526a3a" rel="nofollow noreferrer">b3db22c002a5d16ae3715b97b58f3f64a1526a3a</a> -- which adds the <code>--user</code> (<code>-U</code>) option and seems to work in WP/D7 (but hasn't been exhaustively tested). Try <a href="https://github.com/civicrm/cv#download" rel="nofollow noreferrer">downloading the latest build of <code>cv</code></a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-29T10:19:15.203Z
Answers.Text: I've been unable to test this yet because of http://civicrm.stackexchange.com/questions/16014/can-cv-handle-custom-wordpress-installs but I've not forgotten.
Answers.UserDisplayName: artfulrobot
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-01T21:05:55.657Z
Answers.LastActivityDate: 2016-11-01T21:05:55.657Z
Answers.UserDisplayName: Tim Otten
Body: <p>I'm using <code>eval cv php:boot</code> in a script. I need to be able to delete a contact in the script, including the <code>skip_undelete</code> flag, but this action is denied - get a "could not delete contact" error.</p>
  
  <p>I <a href="https://civicrm.stackexchange.com/a/8225/35">learnt</a> that in Drupal this happens when you're bootstrapped but not as the admin user, but I'm unfamiliar with what <strong>Wordpress</strong>'s equivalent would be, and whether it's possible to do this using <code>cv</code>?</p>
  
  <p>Thanks.</p>
  
  <p>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 :-)</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-29T00:43:20.040Z
Comments.Text: Wow, someone has heard of `cv`!  Even at CiviCRM sprints most folks haven't seen it before.
Comments.UserDisplayName: Jon G - Megaphone Tech
Tags: <wordpress><testing><cv>
Title: How to bootstrap CiviCRM with admin permissions in a Wordpress environment?
ThreadText: # How to bootstrap CiviCRM with admin permissions in a Wordpress environment?
  
  (Asked by: username_0 on 2016-10-28)
  
  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](https://civicrm.stackexchange.com/a/8225/35) 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`?
  
  Thanks.
  
  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 :-)
  
  **Tags:** wordpress, testing, cv
  
  > **Comments:**
  > **username_1**: Wow, someone has heard of `cv`!  Even at CiviCRM sprints most folks haven't seen it before.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2016-11-01. Score: 4 | Accepted answer
  
  I recently pushed [b3db22c002a5d16ae3715b97b58f3f64a1526a3a](https://github.com/civicrm/cv/commit/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`](https://github.com/civicrm/cv#download).
  
  > **Comments:**
  > **username_0**: I've been unable to test this yet because of http://civicrm.stackexchange.com/questions/16014/can-cv-handle-custom-wordpress-installs but I've not forgotten.  
  
  ---
  
  ### Answer by username_1 on 2016-10-29. Score: 4
  
  If [wp-cli](http://wp-cli.org) 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](https://github.com/wp-cli/wp-cli/blob/e571f3c644ad5d4356ab54c5b6d1beb1e29e65a8/php/WP_CLI/Runner.php#L1131)) suggests that `wp_set_current_user()` will do the trick.
  
  > **Comments:**
  > **username_0**: 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)  
  
  ---
  
  