Skip to content

Instantly share code, notes, and snippets.

View custom-menu-items.php
* Note! This is no longer updated here in the Gist. It has been moved to a repo.
* @link
* Class custom_menu_items
daggerhart / .htaccess
Last active Aug 15, 2021
WordPress Rewrite API Examples
View .htaccess
<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 / simple-php-template.php
Last active Jun 30, 2021
Example of a template function in PHP
View simple-php-template.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
daggerhart / wp-disable-login-form.php
Last active Jun 8, 2021
Completely disable the WordPress login form. You have your reasons.
View wp-disable-login-form.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 / get_file_field_uri.php
Created Aug 16, 2018
Drupal 8 get file or image field uri. Get default value if field is empty.
View get_file_field_uri.php
use Drupal\file\Entity\File;
* Get the set or default image uri for a file image field (if either exist)
* @link
* @param $entity \Drupal\Core\Entity\ContentEntityBase
* @param $fieldName string

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.
  • - 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 / BetterRestSerializer.php
Last active Apr 21, 2021
Drupal 8 views style plugin for a better rest serializer.
View BetterRestSerializer.php
namespace Drupal\my_module\Plugin\views\style;
use Drupal\rest\Plugin\views\style\Serializer;
* The style plugin for serialized output formats.
* @ingroup views_style_plugins
daggerhart / MyTokens.php
Created Mar 13, 2021
Drupal tokens - hooks vs event_dispatcher
View MyTokens.php
namespace Drupal\mymodule\EventSubscriber;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Utility\Token as TokenService;
use Drupal\core_event_dispatcher\Event\Token\TokensInfoEvent;
use Drupal\core_event_dispatcher\Event\Token\TokensReplacementEvent;
use Drupal\core_event_dispatcher\ValueObject\Token;
use Drupal\core_event_dispatcher\ValueObject\TokenType;
daggerhart /
Created Oct 10, 2015
A very simple php website and contact form tutorial.

Simple PHP Website and Contact Form

This is purely for example and educational purposes.

The resulting contact form you will create with this example is extremely insecure. Do not use it on a live website.

Setup Environment

  1. Create website directory on Desktop
  2. Open terminal and test PHP php --version
daggerhart / wp-get-taxonomy-hierarchy.php
Last active Feb 23, 2021
WordPress function to get a complete taxonomy hierarchy of terms in PHP
View wp-get-taxonomy-hierarchy.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 ) {