Skip to content

Instantly share code, notes, and snippets.

@daggerhart
daggerhart / simple-template-class.php
Last active May 17, 2023 19:16
A simple PHP template class.
<?php
/**
* Class Template - a very simple PHP class for rendering PHP templates
*/
class Template {
/**
* Location of expected template
*
@daggerhart
daggerhart / 1.WordPress-Developer-Environment-Setup.md
Last active March 26, 2023 14:50
Modern WordPress Theme Development

Development Software

  • VirtualBox - Virtualization software for running local operating systems within your computer. This allows us have a full version of linux within our computers that better match how a live webserver works.
  • Vagrant - A tool for provisioning (creating) virtual machines.
  • VVV - A pre-built, community-supported Vagrant configuration for WordPress development.
  • Git - Version control system for managing code during development. Easily allows for tracking changes, and merging new code into an existing project.
  • SourceTree - A GUI available on Windows and Mac for managing Git projects. This makes Git much easier to use, as we won't have to learn the command line interface.
  • Github.com - A website that provides free Git repositories for both open source and private projects.
  • SASS - (SCSS) A CSS preprocessing implementation that allows us to write much less CSS for a project. This basically makes CSS into a simple programming language.
@daggerhart
daggerhart / AjaxInWebformElement.php
Last active March 1, 2023 00:00
Drupal 9, Webform 6 - custom element w/ ajax in form
<?php
namespace Drupal\ocf_integration_webform\Plugin\WebformElement;
use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\Element\WebformAjaxElementTrait;
use Drupal\webform\Plugin\WebformElementBase;
use Symfony\Component\HttpFoundation\Request;
/**
@daggerhart
daggerhart / .htaccess
Last active January 18, 2023 19:29
WordPress Rewrite API Examples
<IfModule mod_rewrite.c>
# enable rewriting
RewriteEngine on
# don't rewrite files that exist in the file system
RewriteCond %{REQUEST_FILENAME} !-f
# don't rewrite directories that exist in the file system
RewriteCond %{REQUEST_FILENAME} !-d
@daggerhart
daggerhart / wp-disable-login-form.php
Last active January 13, 2023 19:10
Completely disable the WordPress login form. You have your reasons.
<?php
// pick a hook from the wp-login.php file that best our needs. I chose the filter: wp_login_errors
add_filter( 'wp_login_errors', 'my_login_form_lock_down', 90, 2 );
/**
* Completely lock down the WordPress login form by hijacking the page
* and only executing the the login header, footer, and necessary
* closing tags.
*
* Provide a secret way to show the login form as a url variable in
@daggerhart
daggerhart / wp-get-taxonomy-hierarchy.php
Last active December 18, 2022 03:22
WordPress function to get a complete taxonomy hierarchy of terms in PHP
<?php
/**
* Recursively get taxonomy and its children
*
* @param string $taxonomy
* @param int $parent - parent term id
* @return array
*/
function get_taxonomy_hierarchy( $taxonomy, $parent = 0 ) {
@daggerhart
daggerhart / simple-js-template.js
Last active April 1, 2022 20:40
Simple javascript templating function
/**
* Very simple non-hierarchical templating engine
*
* @param name
* @param data
*
* @returns string
*/
@daggerhart
daggerhart / actions\setup-runner\action.yml
Created December 18, 2021 23:08
GitHub Composite Action for deploying to pantheon
name: "Setup Runner"
description: "Provides SSH, PHP, Terminus as a composite action"
inputs:
pantheon_ssh_key:
description: 'Pantheon SSH Private key in the PEM format.'
required: true
ssh_config:
description: 'Contents of the ssh/config file.'
required: true
<?php
/*
* Note! This is no longer updated here in the Gist. It has been moved to a repo.
*
* @link https://github.com/daggerhart/wp-custom-menu-items
*/
/**
* Class custom_menu_items
@daggerhart
daggerhart / simple-php-template.php
Last active June 30, 2021 14:44
Example of a template function in PHP
<?php
/**
* Simple PHP Templating function
*
* @param $names - string|array Template names
* @param $args - Associative array of variables to pass to the template file.
* @return string - Output of the template file. Likely HTML.
*/
function template( $names, $args ){
// allow for single file names