Skip to content

Instantly share code, notes, and snippets.

View GhostToast's full-sized avatar

Gustave F. Gerhardt GhostToast

View GitHub Profile
<?php
/**
* Plugin Name: Robots Crawl Delay
*/
function prefix_robots_crawl_delay( $output, $public ) {
$output .= "Crawl-delay: 8\n";
return $output;
}
add_filter( 'robots_txt', 'prefix_robots_crawl_delay', 10, 2 );
@franz-josef-kaiser
franz-josef-kaiser / MinFilterIterator.php
Last active January 18, 2021 19:15
An example plugin to show the use of the PHP SPL and subsidiary loops with a FilterIterator.
<?php
// Reduced to the minimum
class ThumbnailFilter extends FilterIterator
{
private $wp_query;
public function __construct( Iterator $iterator, WP_Query $wp_query )
{
NULL === $this->wp_query AND $this->wp_query = $wp_query;
parent::__construct( $iterator );
@franz-josef-kaiser
franz-josef-kaiser / ajax.js
Last active May 31, 2022 15:53
AJAX in WordPress. Class based example.
( function( $, plugin ) {
"use strict";
// Working with promises to bubble event later than core.
$.when( someObjectWithEvents ).done( function() {
console.log( 'AJAX request done.' );
} )
.then( function() {
setTimeout( function() {
console.log( 'AJAX requests resolved.' );
@GhostToast
GhostToast / menu_loader_exploder.php
Last active December 19, 2015 03:09
Creates a dropdown menu from a WordPress Nav Menu. Useful for sitting alongside regular menu for use in responsive designs, or where there's no room for a regular menu. Gracefully nests.
<?php
$menu_name = 'topnav'; // or whatever menu you want
$locations = get_nav_menu_locations();
$menu = wp_get_nav_menu_object($locations[$menu_name]);
$menu_items = wp_get_nav_menu_items($menu->term_id, array( 'order' => 'DESC' ));
?>
<select class="the-selectors" onChange="document.location.href=this.options[this.selectedIndex].value;">
<option value="">Please Select</option>
<?php
@Rarst
Rarst / deprecated.md
Last active February 21, 2023 11:21
WordPress coding standards configuration for PhpStorm

Now Native

PhpStorm now bundles WordPress coding style natively, starting from version 8.

  1. Go to Project Settings > Code Style > PHP.
  2. Select Set From... (top right of window) > Predefined Style > WordPress.

No longer need to muck with this import! :)