Answers.Body: <p>Start reading here: <a href="https://docs.civicrm.org/dev/en/latest/framework/bootstrap/#how-to-bootstrap-civicrm" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/framework/bootstrap/#how-to-bootstrap-civicrm</a></p>
  <p>If running your code with <code>cv</code> is an option for what you're trying to do, like a shell script, then that's the easiest. You just write your script as normal and then <code>cv scr --user=admin myscript.php</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-25T20:45:20.500Z
Answers.LastActivityDate: 2022-04-25T20:45:20.500Z
Answers.UserDisplayName: Demerit
Answers.Body: <p>You could also access CiviCRM API3 via the WordPress REST API or WP-CLI depending on your use case:</p>
  <ul>
  <li><a href="https://docs.civicrm.org/dev/en/latest/api/v3/wp-rest/" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/api/v3/wp-rest/</a></li>
  <li><a href="https://docs.civicrm.org/dev/en/latest/api/v3/usage/#wp-cli" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/api/v3/usage/#wp-cli</a></li>
  </ul>
  <p>Note that the WP-CLI example should read:</p>
  <pre><code>wp civicrm api contact.get first_name=Alice last_name=Roberts
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-26T07:52:15.273Z
Answers.LastActivityDate: 2022-04-26T07:52:15.273Z
Answers.UserDisplayName: Christian Wach
Body: <p>I am able to access WordPress functions from outside of a wordpress plugin by doing a require wp-load.php and then I can access (for example) the db functions directly by setting  global $wpdb:</p>
  <pre><code>require_once( '/mydomain/public_html/wp-load.php' );
  global $wpdb;
  </code></pre>
  <p>For CiviCRM I will specifically I need to access the following:</p>
  <ul>
  <li>Find Contact</li>
  <li>Add Contact</li>
  <li>Find Financial Type</li>
  <li>Add Financical Type</li>
  <li>Add New Contribution</li>
  </ul>
  <p>If I want to access any of these CiviCRM functions (without a plugin), what would I need to add to make them available?</p>
  <p>Thanks</p>
  <p>EDIT: I can directly retrieve from database is needed, and I could potentially even add new contact or financial type or contribution direct to database, but if there are functions that do this already then they would the better choice as all the 'checks and balances' will already be there and nothing will get missed.</p>
  <p>EDIT: So I see I can use API4 ... the explorer tool is excellent by the way! So how can I access these API4 functions from the same server as CiviCRM, but from seperate php code (not a civicrm function).</p>
  
Tags: <wordpress><civicontribute>
Title: Access Civi functions from outside wordpress plugin
ThreadText: # Access Civi functions from outside wordpress plugin
  
  (Asked by: username_0 on 2022-04-25)
  
  I am able to access WordPress functions from outside of a wordpress plugin by doing a require wp-load.php and then I can access (for example) the db functions directly by setting global $wpdb:
  
  ```
  require_once( '/mydomain/public_html/wp-load.php' );
  global $wpdb;
  
  ```
  
  For CiviCRM I will specifically I need to access the following:
  
  * Find Contact
  * Add Contact
  * Find Financial Type
  * Add Financical Type
  * Add New Contribution
  
  If I want to access any of these CiviCRM functions (without a plugin), what would I need to add to make them available?
  
  Thanks
  
  EDIT: I can directly retrieve from database is needed, and I could potentially even add new contact or financial type or contribution direct to database, but if there are functions that do this already then they would the better choice as all the 'checks and balances' will already be there and nothing will get missed.
  
  EDIT: So I see I can use API4 ... the explorer tool is excellent by the way! So how can I access these API4 functions from the same server as CiviCRM, but from seperate php code (not a civicrm function).
  
  **Tags:** wordpress, civicontribute
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2022-04-25. Score: 1 | Accepted answer
  
  Start reading here: <https://docs.civicrm.org/dev/en/latest/framework/bootstrap/#how-to-bootstrap-civicrm>
  
  If running your code with `cv` is an option for what you're trying to do, like a shell script, then that's the easiest. You just write your script as normal and then `cv scr --user=admin myscript.php`
  
  
  ---
  
  ### Answer by username_2 on 2022-04-26. Score: 2
  
  You could also access CiviCRM API3 via the WordPress REST API or WP-CLI depending on your use case:
  
  * <https://docs.civicrm.org/dev/en/latest/api/v3/wp-rest/>
  * <https://docs.civicrm.org/dev/en/latest/api/v3/usage/#wp-cli>
  
  Note that the WP-CLI example should read:
  
  ```
  wp civicrm api contact.get first_name=Alice last_name=Roberts
  
  ```
  
  
  ---
  
  