Skip to content

Instantly share code, notes, and snippets.

@daggerhart
daggerhart / examplefilter.module.php
Created Feb 9, 2017
Example Drupal 7 input filter for inserting a node into an arbitrary formatted text field.
View examplefilter.module.php
<?php
/**
* Implements hook_filter_info().
*
* @link https://api.drupal.org/api/drupal/modules%21filter%21filter.api.php/function/hook_filter_info/7.x
*/
function examplefilter_filter_info() {
$filters['examplefilter_node_embed'] = array(
'title' => 'EPI node embed',
@daggerhart
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
<?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 / mymodule.module.php
Last active Aug 4, 2020
Simple Drupal 7 hook_theme() and render array examples
View mymodule.module.php
<?php
/**
* Implements hook_theme()
* @return array
*/
function mymodule_theme(){
$items = array();
$items['mymodule_custom_template'] = array(
View drupal7-install-uninstall-snippets.install.php
<?php
/**
* Uninstall modules.
*/
function lth_configuration_update_7001() {
module_disable(array('module1', 'module2'));
drupal_uninstall_modules(array('module1', 'module2'));
}
@daggerhart
daggerhart / vocabulary-terms-option-list.php
Created Jan 4, 2017
Drupal 7 Webform dynamic select option list for providing taxonomy terms as an option list
View vocabulary-terms-option-list.php
<?php
/**
* Implements hook_webform_select_options_info().
*/
function MODULE_webform_select_options_info() {
$items = array();
$vocabularies = taxonomy_get_vocabularies();
@daggerhart
daggerhart / video-js-ajax-behavior.js
Last active Jan 3, 2017
Drupal 7 behavior to get video.js working with ajax
View video-js-ajax-behavior.js
(function ($) {
Drupal.behaviors.videojsajax = {
attach: function (context, settings) {
if ( typeof videojs != 'undefined' ) {
// find all video elements with video-js class, and re-init them
$('video.video-js').each( function( i , element ){
videojs($(element)[0] , {}, function() {});
});
}
}
@daggerhart
daggerhart / lock-plugins.php
Created Aug 25, 2016
Simple plugin that prevents requests for updats for a given list of plugins.
View lock-plugins.php
<?php
/*
* Plugin Name: Lock plugin updates
* Description: Prevent plugin updates
* Version: 1.0.0
* Author: daggerhart
*/
add_filter( 'http_request_args', 'lock_plugins_http_request_args', 5, 2 );
@daggerhart
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
daggerhart / simple-template-class.php
Last active Jan 6, 2021
A simple PHP template class.
View simple-template-class.php
<?php
/**
* Class Template - a very simple PHP class for rendering PHP templates
*/
class Template {
/**
* Location of expected template
*
@daggerhart
daggerhart / wordpress-missing-functions.php
Created Mar 24, 2016
WordPress functions that I tend to write often
View wordpress-missing-functions.php
<?php
/**
* Get a WP_Post object by its slug ( post_name )
*
* @param $post_name
*
* @return WP_Post|null
*/
function get_post_by_slug( $post_name ) {