Skip to content

Instantly share code, notes, and snippets.

@Greg-Boggs
Greg-Boggs / webhook.php
Created April 9, 2020 02:30
Example webhook
<?php
try {
$payload = json_decode($_REQUEST['payload']);
if ($payload->ref === 'refs/heads/master') {
$output = array();
// Pull Data
exec('cd /var/www && /usr/bin/git pull', $output);
print($output[0]);
@Greg-Boggs
Greg-Boggs / purge_cf.php
Last active June 4, 2025 08:42
PHP code to Purge Cloudflare Cache
<?php
// Replace EMAIL/API_KEY/ZONE_ID with your details.
// Zone ID is on the dashboard for the domain in the bottom right.
// Api keys are generated from the account settings. You must give cache purge permissions
// Place this script on your webserver and point a Github Webhook at it, and you'll clear
// the Cloudflare cache every time you do a push to GH.
$zoneId = "xxx";
$apiKey = "xxx";
$email = "xxx";

Hi First_Name,

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt exercitation ullamco est laborum.

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

~G

@Greg-Boggs
Greg-Boggs / nav.php
Last active July 24, 2019 22:54
Nav component
<nav class="navbar navbar-default">
<!-- toggle -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
@Greg-Boggs
Greg-Boggs / breadcrumb-cache-example.php
Last active July 24, 2019 22:45
Expire the cache for Breadcrumbs when the page changes in Drupal 8
<?php
// Expire the cache per url.
$breadcrumb->addCacheContexts(['url.path']);
// Expire cache context for config changes.
$breadcrumb->addCacheableDependency($this->config);
// Handle views path expiration cache expiration.
$parameters = $route_match->getParameters();
foreach ($parameters as $key => $parameter) {
@Greg-Boggs
Greg-Boggs / EasyBreadcrumb.html
Last active May 8, 2019 00:49
Easy Breadcrumb Release notes for 1.9
Release notes below.
@Greg-Boggs
Greg-Boggs / events.js
Last active September 10, 2020 14:30
Event tracking example with Google universal analytics
jQuery(document).ready(function ($) {
// Track all link clicks internal and external
$('a').click(function(e) {
var linkUrl = e.target.href;
var linkText = $(this).text();
if (this.hostname && this.hostname !== location.hostname) {
ga('send', 'event', {
eventCategory: 'Outbound Link',
@Greg-Boggs
Greg-Boggs / events.js
Last active April 6, 2020 16:18
data layer tracking example
jQuery(document).ready(function ($) {
// Track all link clicks internal and external
$('a').click(function(e) {
var linkUrl = e.target.href;
var linkText = $(this).text();
if (this.hostname && this.hostname !== location.hostname) {
dataLayer.push({
'event' : 'gaEvent',
@Greg-Boggs
Greg-Boggs / functions.php
Created April 12, 2018 01:59
Get the title of any page in Drupal 8
<?php
$title = $this->titleResolver->getTitle($route_request, $route_match->getRouteObject());
// Many paths return a translatable markup object.
if ($title instanceof TranslatableMarkup) {
// Sets the title to the translated string.
$title = $title->render();
}
@Greg-Boggs
Greg-Boggs / functions.php
Last active April 7, 2018 19:56
Helper function to get renderable region for Drupal 8
<?php
// Example usage: $build = blocks_get_blocks_by_region('sidebar_first');
function blocks_get_blocks_by_region($region_name) {
$build = [];
$blocks = entity_load_multiple_by_properties('block', ['theme' => $GLOBALS['theme'], 'region' => $region_name]);
uasort($blocks, 'Drupal\block\Entity\Block::sort');
foreach ($blocks as $key => $block) {