Skip to content

Wordpress

Performance Optimizations

  • Combine/minify CSS (in LiteSpeed “Page Optimization” settings)
  • Contact Form 7 resources are disabled globally in sgc-functions plugin, then re-enabled only on pages that actually use a form. (See sgc-functions\functions\disable-junk.php)
  • WooCommerce is disabled everywhere using a custom WP mu-plugin called disable-plugins and then re-enabled only for a few select pages. Here's the relevant snippet from that plugin:
    $this->disable_plugins = array (
      // Plugin Name => Urls *not* to disable on.
      'woocommerce/woocommerce.php' => array( '/cart/', '/checkout/', '/export_orders.php', '/my-account/', '/wp-json/wc/' ), 
    );
    

Logging

Send logs to a file instead of showing them onscreen:

wp-config.php
define( 'WP_DEBUG', true);
define( 'WP_DEBUG_LOG', '../../wp-debug-sgc.log' ); // /home/u159938358/domains/shepherdsglobal.org/wp-debug-sgc.log
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

The child theme's functions.php also has a feature that will email any fatal errors to sgcwebsite@shepherdsglobal.org immediately.

Email

  • FluentSMTP plugin — used for sending WP emails via wordpress@shepherdsglobal.org. Follow this guide, and authenticate by logging in to the above MS account ^
  • functions/email.php has the function for sending out new blog posts to subscribers
  • People can subscribe on the /blog/ page. We have a hook in the SGC custom plugin that catches their email address if it passes validation and adds them as a WP user in the “subscriber” role. If that email already exists as a WP user, then it will add a line to the error log and send an error email.
  • Consider the https://wordpress.org/plugins/mail-queue/ plugin if we run into throttles or bottlenecks

Custom Post Types

All of the CPTs below are registered in the “SGC Functions” plugin. (An easy way to set up a new CPT is to use the CPT UI plugin, then export the code).

Partner Ministries

Imported them from a CSV file using this plugin and set the URLs as a custom field (partner_ministry_url). Displayed in a custom Post Loop.

Team Members

Used for displaying loops of team members on https://shepherdsglobal.org/our-team/. Powered by generate-press-child/team_members_shortcode.php which creates the necessary shortcodes.

Courses

100% programmatically generated by syncing from Andrew’s DB.* They are displayed using the custom PHP template files noted above.

Custom “courses” (DPG, CDL, etc)

Tim Keep requested that we make DPG and CDL available for separate download and purchase, so I created a feature in the sgc-functions plugin (in functions\create_custom_courses.php) where it auto-generates a duplicate “course” with the proper title/thumbnail and adds it to the “SGC Resources” category at the bottom of the page. These are created separately from the courses that are created via sync from Andrew B.’s app db but shouldn’t cause any conflict, because they have a different author ID (1).

These custom courses are auto generated from the aux files/info already attached to their parent courses (SF for DPG, and BED for CDL), so if anything needs changed, the aux files need changed to be correct, and then everything else should be correct once it’s synced and refreshed.

To refresh the custom courses (it deletes them and then regenerates them) just visit the following URL with this GET param while logged in as an admin: /cart/refresh_courses=true (now available as a button on the WP admin bar).

The refresh has to happen on the “cart” page because it’s a page where WooCommerce is already enabled. If we run the refresh on a page where Woo isn’t enabled, like the homepage, we’ll get an error, because the our custom mu-plugin disables Woo on all unnecessary pages to save on requests and server load.

CDL (Cultivate Discipleship Lessons)

CDL is a special case, because we are offering a Student Edition in addition to the combined (leader & student) file. We wanted to make them available for purchase (and download) separately, so a function was made to dynamically create “products” in WP so that they can be purchased through WooCommerce. They couldn't be made as a “course” post type because then they’d show up in the course loops, etc.

Note

The CDL custom WooCommerce products are more or less invisible to the end user except when they click a link to add them to the cart. If you have trouble finding them, look in WooCommerce > “Products”. Keep in mind that the custom mu-plugin has WC disabled globally, and then re-enabled only on certain pages, so if you run into issues with WC/products, that’s probably why.

New Course Email Notifications

Here’s the JS code used to dynamically create an iframe to show users their subscription settings:

<div id="myiframe"></div>
<noscript><p style="color:red;">Sorry, this page does not work without Javascript. Please enable Javascript and then reload the page.</p></noscript>
<script language="javascript">

// Create the iframe element
var iframe = document.createElement('iframe');

// Set the iframe attributes
iframe.src = '<https://sgc.andrewblankenship.dev/public/email-settings/>;' + window.location.search;
iframe.width = '100%'; // Set the width
iframe.height = '900px'; // Set the height

// Append the iframe to the div with id 'myiframe'
document.getElementById('myiframe').appendChild(iframe);

</script>

The code for the signup form went in courses-loop.php, and we also added a css file for styling: /wp-content/themes/generatepress-child/signup.css

SGC Completion Certificates

https://shepherdsglobal.org/certificate/

Depends on the mpdf library, which is installed in /home/u159938358/domains/shepherdsglobal.org/tools/mpdf using the following command on Hostinger ssh: (first copy “composer.json” and composer.lock to that dir)

composer2 install --no-dev --optimize-autoload

The rest of the code responsible for making that page work can be found in the sgc-functions plugin in functions/cert.

Here is the Canva template if the Certificate ever needs edited (to add the signature, for example).

NEON API integration (email signup)

Whenever someone downloads an SGC course they’ll get a popup to add their name, email address and an optional message to SGC. The code for this is found in the generatepress-child dir.

  • generatepress-child\neon-api.php
  • generatepress-child\post_download_popup.php

There is also a 2nd integration that whenever someone orders a hard-copy SGC course via our WooCommerce store, they also get signed up for an account at NEON with their name and email address. (Merged with neon-api.php above)

Export WooCommerce order info for Justin LePage

https://shepherdsglobal.org/export_orders.php (must be logged in to WP first)!