Skip to content

Instantly share code, notes, and snippets.

@daggerhart
daggerhart / auto_entitylabel_eck_support.php
Last active July 7, 2017 19:21
Drupal 8 - How to add Automatic Entity Label support to ECK (Entity Construction Kit) created bundles
<?php
/**
* Implements hook_entity_type_alter().
*/
function example_entity_type_alter(array &$entity_types)
{
foreach ($entity_types as $entity_type) {
if ($entity_type->getProvider() == 'eck' && !is_null($entity_type->getBundleOf())){
$entity_type->setLinkTemplate('auto-label', $entity_type->getLinkTemplate('edit-form') . "/auto-label");
@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 / 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 / wp-allow-img-in-comments.php
Last active March 6, 2018 11:41
Allow HTML img tags in WordPress comments
<?php
add_filter( 'wp_kses_allowed_html', array( $this, 'my_kses_allowed_html_hook' ), 20, 2 );
function my_kses_allowed_html_hook( $tags, $context = null ){
if ( 'post' == $context && ! isset( $tags['img'] ) ) {
$tags['img'] = array(
'src' => 1,
'height' => 1,
'width' => 1,
'alt' => 1,
@daggerhart
daggerhart / wordpress-cleanup-basic.php
Created July 27, 2015 20:36
WordPress post data cleanup. Very basic.
<?php
/**
* Example of using wp_kses() to clean up WordPress post data.
*/
function __cleanup_post_data(){
global $wpdb;
// default wordpress "allowed html" for posts
$allowed_tags = wp_kses_allowed_html( 'post' );
@daggerhart
daggerhart / wordpress-cleanup-content.php
Last active March 6, 2018 11:42
Wordpres: Clean up content
<?php
function __cleanup_post_data(){
global $wpdb;
// default wordpress "allowed html" for posts
$allowed_tags = wp_kses_allowed_html( 'post' );
// don't allow spans
unset($allowed_tags['span']);
@daggerhart
daggerhart / bbpress_recent_replies-shortcode-optimized.php
Last active March 6, 2018 11:42
Custom bbpressRecent replies shortcode - optimized.
<?php
/*
* Get the most recently replied-to topics, and their most recent reply
*/
function custom_bbpress_recent_replies_by_topic($atts){
$short_array = shortcode_atts(array('show' => 5), $atts);
extract($short_array);
// get the 5 topics with the most recent replies
@daggerhart
daggerhart / bbpress-remove-reply-post_title-filter.php
Last active March 6, 2018 11:42
bbPress - remove "Reply To: " from reply post titles
<?php
/*
* Filter for bbpress reply post_title, without "Reply To: " prefix
* - reference: https://bbpress.trac.wordpress.org/browser/trunk/src/includes/replies/template.php
*/
function custom_bbp_get_reply_title_fallback( $post_title = '', $post_id = 0 ){
// Bail if title not empty, or post is not a reply
if ( ! empty( $post_title ) || ! bbp_is_reply( $post_id ) ) {
return $post_title;
@daggerhart
daggerhart / bbpress_recent_replies-shortcode.php
Last active March 6, 2018 11:42
Custom bbpressRecent replies shortcode.
<?php
/*
* Get the most recently replied-to topics, and their most recent reply
*/
function custom_bbpress_recent_replies_by_topic($atts){
$short_array = shortcode_atts(array('show' => 5, 'forum' => false, 'include_empty_topics' => false), $atts);
extract($short_array);
// default values
@daggerhart
daggerhart / custom_qw_field_example.php
Last active March 6, 2018 11:42
An example of creating a custom field for display with Query Wrangler
<?php
/*
Plugin Name: Custom QW Field Example
Description: Example of custom Query Wrangler field with $post and $field parameters.
Author: Jonathan Daggerhart
Version: 1.0
*/
add_filter('qw_fields', 'custom_qw_field');