Skip to content

Instantly share code, notes, and snippets.

{
"core": null,
"plugins": [
"https://downloads.wordpress.org/plugin/woocommerce.zip"
],
"config": {
"WP_DEBUG": true,
"SCRIPTS_DEBUG": true,
"WP_DEBUG_LOG": false,
"WP_DEBUG_DISPLAY": true
@Clorith
Clorith / plugin.php
Created December 11, 2015 15:22
Encourage your users to submit translations for your WordPress plugin
<?php
function language_detector_admin_notices() {
// Get the current language locale
$language = get_locale();
// Check if the nag screen has been disabled for this language
if ( false === get_option( 'plugin_slug_language_detector_' . $language, false ) ) {
// Check if a translation file already exists for this language
if ( $loaded = load_plugin_textdomain( 'text_domain', false, plugin_dir_path( __FILE__ ) . '/languages/' ) ) {
@Clorith
Clorith / functions.php
Last active March 22, 2022 14:05
WordPress filter for adding responsive wrapper to embedded content
<?php
/**
* Filter for adding wrappers around embedded objects
*/
function responsive_embeds( $content ) {
$content = preg_replace( "/<object/Si", '<div class="embed-container"><object', $content );
$content = preg_replace( "/<\/object>/Si", '</object></div>', $content );
/**
* Added iframe filtering, iframes are bad.
@Clorith
Clorith / disable-fullscreen-snippet.php
Last active February 17, 2022 00:32
Quick drop-in snippet to disable the default full-screen editing mode and welcome guide in WordPress when a user first visits the edit interface.
<?php
function wp378934573289_js_head_print() {
$screen = get_current_screen();
// Only add script in editor views.
if ( 'edit' !== $screen->parent_base ) {
return;
}
?>
@Clorith
Clorith / load-more-content.js
Last active October 21, 2021 11:06
jQuery script for loading more content over ajax.
/**
* Load more content over ajax in a nice manner
*
* This script utilizes Font Awesome to give proper visual feedback
* while the new content is being fetched and loaded
*
* Usage:
* - Attach the class 'load-more-content' to any a tag in the DOM
* - Give this object a data attribute of data-content-area which indicates
* what part of the site is to be loaded in
@Clorith
Clorith / remove-super-admins.php
Created June 16, 2021 18:12
A script to be used with WP-CLI's `wp eval-file` to remove super-admins from all sub-sites in a network (except the primary site in the network when applicable).
<?php
// Fetch all superadmins on a site.
$super_admins = get_super_admins();
// Loop over all super admins
foreach ( $super_admins as $admin_slug ) {
// Get a user object for this user.
$user = get_user_by( 'slug', $admin_slug );
// Fail-safe, maybe the slug somehow couldn't be identified.
@Clorith
Clorith / alsoviewing.meta.js
Last active March 22, 2020 04:36
WordPress.org also-viewing for the forums
// ==UserScript==
// @name WordPress.org Also Viewing
// @namespace http://jason.stallin.gs
// @description See when another person is viewing the same post.
// @author Clorith
// @grant none
// @include https://*.wordpress.org/support/topic/*
// @include https://*.wordpress.org/support/view/*
// @include https://wordpress.org/support/topic/*
// @include https://wordpress.org/support/view/*
@Clorith
Clorith / options.html
Last active October 16, 2018 20:32
WordPress.org plugins topic highlighter
<form id="tamper-wp-topic-highlighter">
<hr>
<strong>Topics older than 1 week with no resolution</strong>
<br>
<div style="display: inline-block; width: 30%;">Background: </div>
<div style="display: inline-block;"><input type="text" id="tamper-wp-topic-highlighter-old" value="#ffc173" style="padding: 0 5px;"></div>
<br>
<div style="display: inline-block; width: 30%;">Text: </div>
<div style="display: inline-block;"><input type="text" id="tamper-wp-topic-highlighter-old-text" value="inherit" style="padding: 0 5px;"></div>
/**
* Load more content over ajax in a nice manner
*
* This script utilizes Font Awesome to give proper visual feedback
* while the new content is being fetched and loaded
*
* Usage:
* - Attach the class 'load-more-content' to any a tag in the DOM
* - Give this object a data attribute of data-content-area which indicates
* what part of the site is to be loaded in
@Clorith
Clorith / gist:7675143
Created November 27, 2013 12:50
wp_nav_menu_items filter example
<?php
function theme_menu_append( $items ) {
$prepend = "";
$append = "";
$prepend .= "<li>First item always!</li>";
$append .= "<li>This is the 2nd to last item</li>";
$append .= "<li>This is the very last item</li>";