Answers.Body: <p>These are just very basic How To instructions on getting a custom extension/module/plugin running on WordPress CiviCRM:</p>
  <p><strong>Step 1</strong> - You need to have civix installed on your server. For this step, please take a look here: <a href="https://docs.civicrm.org/dev/en/latest/extensions" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/extensions</a></p>
  <p><strong>Step 2</strong> - From your terminal, use the cd command change dirs to the ext directory which is the uploads folder:</p>
  <pre><code>/something/public_html/wp-content/uploads/civicrm/ext
  </code></pre>
  <p><strong>Step 3</strong> - Use the following command to create the extension:
  NOTE: <em>abc123_thenameofmyextension can be anything you want, but it will need to be unique. So for example you might want to use something like com_mydomain_thenameofmyextension</em>
  NOTE: <em>When you click enter, it should generate the extension and it will ask you if you want to ENABLE it right away. I usually choose NO and then you can go the CiviCRM Extensions menu later and enable it there when you are ready to use it. But you can choose YES and it will be enabled right away.</em></p>
  <pre><code>civix generate:module abc123_thenameofmyextension --author=&quot;My Name&quot; --email=&quot;myemaile@domain.com&quot;
  </code></pre>
  <p><strong>Step 4</strong> - Once the extension is generated, you can then go your new <code>/wp-content/uploads/civicrm/ext/abc123_thenameofmyextension</code> directory and edit the <code>info.xml</code> file. The only two things you really need to worry about are the <code>&lt;name&gt;FIXME&lt;/name&gt;</code> and <code>&lt;description&gt;FIXME&lt;/description&gt;</code> fields. So set the NAME to whatever you want and add a DESCRIPTION and save the file.</p>
  <p><strong>Step 5</strong> - Now add some code that will make the extension do something! The file you want to add your code to is in the same <code>/wp-content/uploads/civicrm/ext/abc123_thenameofmyextension</code> directory and is called:</p>
  <pre><code>abc123_thenameofmyextension.php
  </code></pre>
  <p><strong>Step 6</strong> - In this step, as an example, we are actually going to add some code that will set the Default Financial Type when the New Contributions page/form is opened using the buildForm hook, which was asked here: <a href="https://civicrm.stackexchange.com/questions/41139/set-a-default-financial-type-when-adding-new-contribution">Set a default Financial Type when adding New Contribution?</a></p>
  <p>Open up the abc123_thenameofmyextension.php and scroll all the way to the bottom of the file and then add the following code:</p>
  <pre><code>// Create a new function that will set the Default Financial Type on the New Contributions page/form
  function abc123_thenameofmyextension_civicrm_buildForm($formName, &amp;$form) {
    if ($formName == 'CRM_Contribute_Form_Contribution') { // Check which page/form we are on.
      if ($form-&gt;_action &amp; CRM_Core_Action::ADD) { // Make sure we are adding a NEW contribution and not editing an existing contribution.
        $form-&gt;setDefaults(['financial_type_id' =&gt; 1]); // Set the default financial to type this financial_type_id
      }
    }
  }
  </code></pre>
  <p>Now save this file, enable the extension from the CiviCRM Extensions menu and check if your New Contribution now has a default financial type set.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-28T20:03:33.163Z
Answers.Text: This is useful, but the main place for documentation is https://docs.civicrm.org.  Maybe you could add a new step-by-step guide like this one: https://docs.civicrm.org/dev/en/latest/step-by-step/create-entity/
Answers.UserDisplayName: Aidan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-27T19:08:02.483Z
Answers.LastActivityDate: 2022-07-28T17:49:14.990Z
Answers.LastEditDate: 2022-07-28T17:49:14.990Z
Answers.UserDisplayName: jsherk
Body: <p>The question is: How do I create an extension or module for CiviCRM?</p>
  <p>I will be answering my own question below, as a very basic How To guide for noobs (like me)!</p>
  
Tags: <wordpress><extension><modules><plugin>
Title: How to create a custom extension/module (with an example)?
ThreadText: # How to create a custom extension/module (with an example)?
  
  (Asked by: username_0 on 2022-07-27)
  
  The question is: How do I create an extension or module for CiviCRM?
  
  I will be answering my own question below, as a very basic How To guide for noobs (like me)!
  
  **Tags:** wordpress, extension, modules, plugin
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2022-07-27. Score: 3 | Accepted answer
  
  These are just very basic How To instructions on getting a custom extension/module/plugin running on WordPress CiviCRM:
  Step 1 - You need to have civix installed on your server. For this step, please take a look here: https://docs.civicrm.org/dev/en/latest/extensions
  Step 2 - From your terminal, use the cd command change dirs to the ext directory which is the uploads folder:
  /something/public_html/wp-content/uploads/civicrm/ext
  
  Step 3 - Use the following command to create the extension:
  NOTE: abc123_thenameofmyextension can be anything you want, but it will need to be unique. So for example you might want to use something like com_mydomain_thenameofmyextension
  NOTE: When you click enter, it should generate the extension and it will ask you if you want to ENABLE it right away. I usually choose NO and then you can go the CiviCRM Extensions menu later and enable it there when you are ready to use it. But you can choose YES and it will be enabled right away.
  civix generate:module abc123_thenameofmyextension --author="My Name" --email="myemaile@domain.com"
  
  Step 4 - Once the extension is generated, you can then go your new /wp-content/uploads/civicrm/ext/abc123_thenameofmyextension directory and edit the info.xml file. The only two things you really need to worry about are the FIXME and FIXME fields. So set the NAME to whatever you want and add a DESCRIPTION and save the file.
  Step 5 - Now add some code that will make the extension do something! The file you want to add your code to is in the same /wp-content/uploads/civicrm/ext/abc123_thenameofmyextension directory and is called:
  abc123_thenameofmyextension.php
  
  Step 6 - In this step, as an example, we are actually going to add some code that will set the Default Financial Type when the New Contributions page/form is opened using the buildForm hook, which was asked here: Set a default Financial Type when adding New Contribution?
  Open up the abc123_thenameofmyextension.php and scroll all the way to the bottom of the file and then add the following code:
  // Create a new function that will set the Default Financial Type on the New Contributions page/form
  function abc123_thenameofmyextension_civicrm_buildForm($formName, &$form) {
    if ($formName == 'CRM_Contribute_Form_Contribution') { // Check which page/form we are on.
      if ($form->_action & CRM_Core_Action::ADD) { // Make sure we are adding a NEW contribution and not editing an existing contribution.
        $form->setDefaults(['financial_type_id' => 1]); // Set the default financial to type this financial_type_id
      }
    }
  }
  
  Now save this file, enable the extension from the CiviCRM Extensions menu and check if your New Contribution now has a default financial type set.
  
  > **Comments:**
  > **username_1**: This is useful, but the main place for documentation is https://docs.civicrm.org.  Maybe you could add a new step-by-step guide like this one: https://docs.civicrm.org/dev/en/latest/step-by-step/create-entity/  
  
  ---
  
  