Skip to content

Instantly share code, notes, and snippets.

@daggerhart
daggerhart / drupal-useful-field-info.php
Last active August 22, 2017 18:09
Drupal 7 & 8 - useful field info on field management form: required, file uri_scheme, filefield_paths. Drupal 8 version in first comment
<?php
/**
* Implements hook_form_FORM_ID_alter().
*
* Indicate some details about the field on the field overview form
*/
function MYMODULE_form_field_ui_field_overview_form_alter(&$form, &$form_state, $form_id) {
$instances = field_info_instances( $form['#entity_type'], $form['#bundle'] );
$fields = field_info_fields();
@daggerhart
daggerhart / examplefilter.module.php
Created February 9, 2017 17:07
Example Drupal 7 input filter for inserting a node into an arbitrary formatted text field.
<?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 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 / mymodule.module.php
Last active August 4, 2020 05:55
Simple Drupal 7 hook_theme() and render array examples
<?php
/**
* Implements hook_theme()
* @return array
*/
function mymodule_theme(){
$items = array();
$items['mymodule_custom_template'] = array(
@daggerhart
daggerhart / drupal7-install-uninstall-snippets.install.php
Created January 11, 2017 21:03
Drupal7 Install / Uninstall snippets. Originally from - https://gitlab.com/snippets/17139
<?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 January 4, 2017 19:44
Drupal 7 Webform dynamic select option list for providing taxonomy terms as an option list
<?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 January 3, 2017 21:12
Drupal 7 behavior to get video.js working with ajax
(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 August 25, 2016 21:05
Simple plugin that prevents requests for updats for a given list of plugins.
<?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 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 / 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
*