Skip to content

Instantly share code, notes, and snippets.

@Clorith
Clorith / disable-fullscreen-snippet.php
Last active Feb 17, 2022
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.
View disable-fullscreen-snippet.php
<?php
function wp378934573289_js_head_print() {
$screen = get_current_screen();
// Only add script in editor views.
if ( 'edit' !== $screen->parent_base ) {
return;
}
?>
@Clorith
Clorith / remove-super-admins.php
Created Jun 16, 2021
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).
View remove-super-admins.php
<?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 / options.html
Last active Oct 16, 2018
WordPress.org plugins topic highlighter
View options.html
<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>
@Clorith
Clorith / functions.php
Created Mar 10, 2017
Override page templates in WordPress
View functions.php
<?php
/*
* Override the template engine when it's looking for a themes templates files, and output our own one instead
*/
add_filter( 'page_template','maybe_hijack_page' );
function maybe_hijack_page( $template ) {
// Check the page ID and hijack if it's ID 50, this can be any conditional!
if ( get_the_ID() == 50 ) {
@Clorith
Clorith / alsoviewing.meta.js
Last active Mar 22, 2020
WordPress.org also-viewing for the forums
View alsoviewing.meta.js
// ==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/*
View gist:6296d0e441c683b75a51290551c14762
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WordPress Rule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
@Clorith
Clorith / plugin.php
Created Dec 11, 2015
Encourage your users to submit translations for your WordPress plugin
View plugin.php
<?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/' ) ) {
View load-more-content.js
/**
* 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 / load-more-content.js
Last active Oct 21, 2021
jQuery script for loading more content over ajax.
View load-more-content.js
/**
* 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
View gist:9e9f8b773e5c8d8213db
<div class="carousel-inner">
<?php
$first = true;
while ( have_posts() ) : the_post();
$content = get_the_content();
?>
<div class="item <?php echo ( $first ? 'active' : 'inactive' ); ?>">
<div class="container slide-element">
<?php the_post_thumbnail(); ?>
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>