Skip to content

Instantly share code, notes, and snippets.

View soderlind's full-sized avatar

Per Søderlind soderlind

View GitHub Profile
@soderlind
soderlind / class-google-maps-oembed-provider.php
Last active April 29, 2024 11:44
WordPress Google Maps oEmbed Provider using the Google Maps Embed API
<?php
/**
* Create a Google Maps oEmbed Provider using the Google Maps Embed API
*
* @see https://developers.google.com/maps/documentation/embed/
* @link https://gist.github.com/soderlind/db6dae8a73253329bc97ac50d7ebedef
* @since 1.0.0
* @package Google_Maps_oEmbed_Provider
*/
class DSS_oEmbed_Add_Provider {
@soderlind
soderlind / licence activation.php
Created May 16, 2016 22:54 — forked from mattradford/licence activation.php
ACF5 Pro licence activation. Could be adapted for any other plugin that requires a licence key, but doesn't yet support defining it in wp-config. Fires on theme activation.
// Place this in wp-config
define( 'ACF_5_KEY', 'yourkeyhere' );
// Set ACF 5 license key on theme activation. Stick in your functions.php or equivalent.
function auto_set_license_keys() {
if ( ! get_option( 'acf_pro_license' ) && defined( 'ACF_5_KEY' ) ) {
$save = array(
'key' => ACF_5_KEY,
@soderlind
soderlind / in_reply_to_status_id.php
Last active January 11, 2017 20:18
WordPress shortcode [inreplyto]. Get twitter thread, starting with the latest as requested here https://twitter.com/helenhousandi/status/800924721227276288
<?php
/**
* Plugin Name: in_reply_to_status_id
* Version: 0.1
* Plugin URI: https://gist.github.com/soderlind/0a0a439304442b64580ee02687e1a8d8
* Description: returns twitter thread
* Author: Per Soderlind
* Author URI: https://soderlind.no
*/
@soderlind
soderlind / change-theme-root.php
Last active April 2, 2022 15:50
Change WordPress theme root to a folder in your plugin (src/assets)
<?php
/**
* Sample use:
* WordPres Customizer is dependant on functionality in the theme. Just in case
* the current theme doesn't support WordPress Customizer we'll use a theme
* that supports it.
*/
class NN {
private $theme_name = 'twentysixteen';
@soderlind
soderlind / get-template-data.php
Last active January 10, 2017 20:26
Get WordPress post template data
<?php
$current_theme = wp_get_theme(); // get WP_Theme object
if ( count( $post_templates = $current_theme->get_post_templates() ) ) { // https://developer.wordpress.org/reference/classes/wp_theme/get_post_templates/
printf( '<pre>%s</pre>', print_r( $post_templates, true ) );
}
/*
Prints:
@soderlind
soderlind / phpcs.xml
Last active February 13, 2017 09:44
Allow PSR-4 autoloading
<?xml version="1.0"?>
<ruleset name="Plugin Customizer">
<description>The code standard for Plugin Customizer in WordPress.</description>
<!-- ##### WordPress sniffs #####-->
<rule ref="WordPress-Core">
<exclude name="Generic.Files.LowercasedFilename" />
<exclude name="WordPress.Files.FileName" />
<exclude name="WordPress.Files.FileName.UnderscoresNotAllowed" />
</rule>
@soderlind
soderlind / convert-gif-to-video.php
Last active February 20, 2017 07:07
Use cloudinary to convert animated gif to video and reduce file size. Learn more at http://cloudinary.com/blog/reduce_size_of_animated_gifs_automatically_convert_to_webm_and_mp4
<?php
add_filter( 'the_content', function ( $content ) {
$doc = new DOMDocument();
// modify state
$libxml_previous_state = libxml_use_internal_errors( true );
$doc->loadHTML( $content );
// handle errors
libxml_clear_errors();
// restore
@soderlind
soderlind / cloudinary-jpg-minify.php
Last active December 5, 2017 00:48
WordPress snippet: Use Cloudinary JPGmini add-on to minify jpg site icons and jpg in content.
<?php
add_filter( 'the_content', function ( $content ) {
$doc = new DOMDocument();
// modify state
$libxml_previous_state = libxml_use_internal_errors( true );
$doc->loadHTML( $content );
// handle errors
libxml_clear_errors();
// restore
@soderlind
soderlind / add-lang-to-customizer-previewer.php
Last active July 5, 2017 07:42
Polylang: Set WordPress Customizer preview url
<?php
add_action( 'customize_controls_enqueue_scripts', 'add_lang_to_customizer_previewer' );
/**
* If Polylang activated, set the preview url
*
* @author soderlind
* @version 1.0.0
*/
function add_lang_to_customizer_previewer() {
@soderlind
soderlind / add-superadmin-to-new-site.php
Last active November 23, 2017 00:20
Add All WordPress Super-Admins to a New Site, put file in wp-content/mu-plugins
<?php
/**
* Plugin Name: Add All Super-Admins to a New Site
* Description: Will attempt to add all super-admins to a site when it's created.
* Version: 0.1.0
* Plugin URI: https://gist.github.com/soderlind/b0a7abc91eaa2646db38b81acfb532a1
* Author: Per Soderind
* Author URI: https://soderlind.no
* Requires PHP: 7.0.0
*/