View site-url.php
<?php
$sites = array_map( 'get_object_vars', get_sites( array( 'deleted' => 0 ) ) ); //WP 4.6+
foreach ( $sites as $site ) {
switch ( $site['blog_id'] ) {
// If you are using Mercator (https://github.com/humanmade/Mercator) and domain mapping is active
case class_exists( '\Mercator\Mapping' ) && $mappings = \Mercator\Mapping::get_by_site( $site['blog_id'] ) :
foreach ( $mappings as $mapping ) {
if ( $mapping->is_active() ) {
$site_url = $mapping->get_domain();
View mercator-add-manage-aliases-link.php
View README.md

PHP Code Beautifier and Fixer (phpcbf)

phpcbf is included when you install PHP_CodeSniffer. Tom McFarlin has written a nice guide on how to install PHP_CodeSniffer and the WordPress Coding Standards Rules for VSCode. If you follow this guide, phpcbf will be installed in the project root, in ./vendor/bin/phpcbf

PHP 5.4 Short Array Syntax Converter

You'll find the convert.php script at GitHub

View no.json
"no": {
"background": "url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMTAwIDgwMCI+DQo8cGF0aCBmaWxsPSIjZWYyYjJkIiBkPSJtMCwwaDExMDB2ODAwaC0xMTAweiIvPg0KPGcgZmlsbD0iI2ZmZiI+DQo8cGF0aCBkPSJtMzAwLDBoMjAwdjgwMGgtMjAweiIvPg0KPHBhdGggZD0ibTAsMzAwaDExMDB2MjAwaC0xMTAweiIvPg0KPC9nPg0KPGcgZmlsbD0iIzAwMjg2OCI+DQo8cGF0aCBkPSJtMzUwLDBoMTAwdjgwMGgtMTAweiIvPg0KPHBhdGggZD0ibTAsMzUwaDExMDB2MTAwaC0xMTAweiIvPg0KPC9nPg0KPC9zdmc+DQo=')",
"renderer": {
"landscape": {
"height": "100%",
"width": "137.5%"
},
"portrait": {
"height": "72.727272727273%",
"width": "100%"
View add-superadmin-to-new-site.php
<?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
*/
View add-lang-to-customizer-previewer.php
<?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() {
View cloudinary-jpg-minify.php
<?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
View convert-gif-to-video.php
<?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
View phpcs.xml
<?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>
View get-template-data.php
<?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: