Skip to content

Instantly share code, notes, and snippets.

View gormus's full-sized avatar
💭
Never be cruel, never be cowardly.

Osman Gormus gormus

💭
Never be cruel, never be cowardly.
View GitHub Profile
@gormus
gormus / deploy.sh
Created October 19, 2021 00:24
Drupal Deployment Script for Platform.sh Environments
#!/usr/bin/env bash
#
#
# Drupal Deployment Script for Platform.sh Environments
# ==============================================================================
# Authored by osman gormus <osman@gorm.us> on Oct 5, 2021
#
#
# deploy: |
@gormus
gormus / syntax-highlighting.sh
Created June 25, 2020 06:13
WP CLI search-replace normalize syntax highlighting wrapper markup
#!/usr/bin/env bash
wp search-replace '<pre[^>]*>(<code[^>]*>)*' '<pre><code>' 'wp_posts' \
--regex \
--regex-flags='i' \
--skip-plugins \
--skip-themes \
--skip-packages \
--color \
--include-columns='post_content' \
@gormus
gormus / .js
Created January 25, 2020 00:55
Add `rel="noopener"` to all "A" tags for external links. See https://gist.github.com/gormus/575844 for an old, similar gist
/**
* Add rel="noopener" to all "A" tags for external links.
*
* Selection rules:
* - "A" tag must have "href" attribute, exclude anchors.
* - "href" attribute must not start with a "."
* - "href" attribute must not start with a "/"
* - "A" tag must not have rel="noopener" set.
* - "A" tag must not have rel="noreferrer" set.
*
@gormus
gormus / fix_wordpress_posts.sql
Created January 8, 2020 21:42
Update WordPress posts which may contain broken code snippets for syntax highlighting.
-- 1. Reset all code snippets to use '<pre><code>' as opening tags.
UPDATE wp_posts
SET post_content = REGEXP_REPLACE(post_content, '<pre[^>]*>(<code[^>]*>)*', '<pre><code>')
WHERE post_status = 'publish'
AND post_type = 'post'
AND post_content RLIKE '<pre[^>]*>(<code[^>]*>)*';
-- 2. Reset all closing tags.
UPDATE wp_posts
SET post_content = REGEXP_REPLACE(post_content, '(<\/code>)*<\/pre>>', '</code></pre>')
@gormus
gormus / cake_admin_menu.php
Created October 6, 2019 21:51
WordPress Must-Use Plugins - Save these files in `wp-content/mu-plugins` to start using them immediately.
<?php
/*
Plugin Name: Override: Admin Menu
Description: Modify admin menu items on the left panel.
Author: Osman Gormus
Version: 1.0.0
Author URI: https://gorm.us/
*/
@gormus
gormus / cake_recent_posts.php
Created October 6, 2019 21:26
WordPress Widget for recent posts.
<?php
/*
Plugin Name: Cake - Recent Posts Widget
Version: 1.0.0
Plugin URI: https://gorm.us/wordpress/plugins/recent-posts
Description: A widget to display recent posts.
Author: Osman Gormus
Author URI: https://gorm.us
*/
@gormus
gormus / qs.js
Created November 14, 2018 19:10 — forked from cvan/qs.js
get query-string parameters (alternative to `URLSearchParams`)
var queryParams = window.location.search.substr(1).split('&').reduce(function (q, query) {
var chunks = query.split('=');
var key = chunks[0];
var value = chunks[1];
return (q[key] = value, q);
}, {});
@gormus
gormus / pretty-php-date-ranges.php
Created July 10, 2018 04:59 — forked from jb510/pretty-php-date-ranges.php
Pretty PHP Date Ranges
<?php
/**
* Verbose Beautified Date Range
*
* @access public
* @param mixed $start_date
* @param mixed $end_date
* @return $date_range (beautified date range)
* @license WTFPL
*
@gormus
gormus / LinkModifierService.php
Created April 19, 2018 14:59 — forked from hudri/LinkModifierService.php
Modify _all_ Drupal links
<?php
namespace Drupal\wt_base;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Render\BubbleableMetadata;
/**
* Class DefaultService.
@gormus
gormus / FilterLazyload.php
Last active October 26, 2020 15:09
bLazy for Drupal 8
<?php
// This plug needs to be placed in a custom module:
// `modules/custom/YOURMODULE/src/Plugin/Filter/FilterLazyload.php`
namespace Drupal\YOURMODULE\Plugin\Filter;
use Drupal\Component\Utility\Html;
use Drupal\filter\FilterProcessResult;
use Drupal\filter\Plugin\FilterBase;