Skip to content

Instantly share code, notes, and snippets.

Avatar

Lee Powers leepowers

View GitHub Profile
@leepowers
leepowers / wpseo-yoast-sitemap-post-types.php
Created Feb 12, 2020
WordPress Yoast SEO: Custom sitemap with data sourced from one or more post types
View wpseo-yoast-sitemap-post-types.php
<?php
/**
* USAGE:
* - Configure the return value of the `CUSTOM_SITEMAP_post_types` to required post type(s) - otherwise populates sitemap with all posts and pages
* - Search and replace the `CUSTOM_SITEMAP` string with a lowercase identifier name: e.g., "myseo", "vehicles", "customer_profiles", "postspage", etc.
* - Uses heredocs for inline XML: https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
*/
/**
@leepowers
leepowers / wpseo-yoast-sitemap-custom.php
Last active Dec 1, 2020
WordPress Yoast SEO: Create a custom sitemap with data not sourced from a custom post type.
View wpseo-yoast-sitemap-custom.php
<?php
/**
* USAGE:
* - Search and replace the `CUSTOM_SITEMAP` string with a lowercase identifier name: e.g., "vehicles", "customer_profiles"
* - The `your_alternate_data_source()` function does not exist; it's simply a placeholder for your own function that returns some sort of data array.
* - Uses heredocs for inline XML: https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
*/
/**
View WordPress .gitignore
# Ignore everything in the root except the "wp-content" directory.
/*
!.gitignore
!wp-content/
# Ignore everything in the "wp-content" directory, except the "plugins" and "themes" directories.
wp-content/*
!wp-content/plugins/
!wp-content/themes/
@leepowers
leepowers / spawn-request.php
Created Jul 30, 2015
PHP Spawn HTTP Request Fork HTTP Request
View spawn-request.php
/**
* Launch a new PHP process at the given URL
* @param string $url
*/
public function spawn_request($url) {
$url_a = parse_url($url);
$port = isset($url_a["port"]) ? $url_a["port"] : 80;
$fp = fsockopen($url_a["host"], $port, $errno, $errstr, 30);
$output = "GET " . $url_a["path"] . "?" . $url_a["query"] . " HTTP/1.0\r\n";
$output .= "Host: " . $url_a["host"] . "\r\n";
@leepowers
leepowers / wordpress_settings.php
Created Sep 27, 2014
Quick-and-dirty class for managing settings for a WordPress plugin.
View wordpress_settings.php
<?php
/**
* Quick-and-dirty class for managing WordPress options for a plugin.
* Include this class in your plugin. Create an instance and use as follows:
*
* Required Usage:
*
* // Create new instance
* $settings = new wordpress_settings;
@leepowers
leepowers / gist:9862956
Last active Feb 12, 2020
Fix `clean_url` entities
View gist:9862956
<?php
/**
* Fix esc_url/clean_url. Instead of escaping `&` to numeric character entities, this filter encodes them as `&amp;`
* Some browsers (such as Android Chrome 33.0.1750.170) don't parse `&#038;` correctly inside `<script src="..."></script>` tags.
* Such browsers leave out or otherwise mangle query string parameters.
* For instance, for a URL like `//maps.googleapis.com/maps/api/js?key=xxxx&#038;sensor=false` the `sensor` parameter is not being sent to the server correctly.
*/
function lpowers_fix_url_entities($url, $original_url, $_context) {
$bad_entity = "&#038;";
@leepowers
leepowers / gist:5529546
Last active Dec 17, 2015
Auto-link URLs in an HTML document that haven't already been linked.
View gist:5529546
<?php
/**
* Safely auto-link HTML content.
* Doesn't double-link existing content.
* Plus logging features
* @param string $html
* @return string
*/
function safe_autolink($html) {
@leepowers
leepowers / gist:5267871
Created Mar 29, 2013
Wordpress `paginate_links_array` - get an array of objects that can be used to generate a custom HTML structure for pagination. Use this if you want the functionality of `paginate_links` without HTML being generated.
View gist:5267871
<?php
/**
* Modification of `paginate_links()` Wordpress built-in function.
* Returns an array of objects describing links instead of generating HTML for links.
* @param array $args Same as `paginate_links()` arguments array. Exceptions: `classes` mapping for CSS classes; `type` is ignored
* @return array Returns an array of objects representing links that can be used to generate HTML
*/
function paginate_links_array($args = '') {
$defaults = array(
You can’t perform that action at this time.