Skip to content

Instantly share code, notes, and snippets.

View seanlanglands's full-sized avatar
👋

Sean Langlands seanlanglands

👋
View GitHub Profile
<?php
/**
* Plugin Name: CLI: Bulk Assign Term by IDs
* Description: WP-CLI command to bulk-assign a taxonomy term to explicit post IDs.
*/
if ( ( defined( 'WP_CLI' ) && WP_CLI ) && class_exists( 'WPCOM_VIP_CLI_Command' ) ) {
/**
* Bulk-assign a taxonomy term to a comma-separated list of post IDs.
*
<?php
add_action(
'plugins_loaded', function () {
class QM_Output_RAW_EP_Query_Log extends QM_Output_Raw {
/**
* Collector instance.
*
* @var QM_Collector_HTTP Collector.
*/
@seanlanglands
seanlanglands / fix-twitter-oembeds.php
Created December 6, 2024 21:46
Fix failed X/Twitter embeds by rendering them client-side when oembed has failed.
<?php
add_filter( 'the_content', 'fix_failed_twitter_embeds', 11 );
/**
* Fix failed X/Twitter embeds by rendering them client-side when oEmbed has failed.
*
* Does not prevent WordPress core's oEmbed from being attempted, which can result in
* a server-side 404 request to Twitter's API.
*
* @param string $content The post content.
<?php
/**
* Enable msm-sitemap plugin sitemap rendering on non-production environments
* by overriding blog_public to 1 on the pre_option hook.
*
* @param mixed $pre_option Value of an existing option.
*
* @return mixed
*/
function vip_enable_non_prod_sitemap_rendering( $pre_option ) {
@seanlanglands
seanlanglands / yoast-sitemap-mitigations.php
Last active July 2, 2025 12:38
Yoast SEO sitemap performance mitigations
<?php
// Yoast sitemap performance improvements.
/**
* Objects are cached for 24 hours and changes will be applied upon next sitemap update.
*/
add_filter( 'wpseo_enable_xml_sitemap_transient_caching', '__return_true' );
add_action( 'parse_request', 'filter_yoast_sitemap_cache_maxage' );
add_action( 'parse_request', 'block_query_string_sitemap_requests' );
@seanlanglands
seanlanglands / custom-wp-sitemap-routes.php
Last active August 29, 2023 02:24
Custom wp-sitemap routes and serve via siteurl value
<?php
// Disable sitemap stylesheets if needed.
add_filter( 'wp_sitemaps_stylesheet_url', '__return_false' );
add_filter( 'wp_sitemaps_stylesheet_index_url', '__return_false');
add_action( 'init', 'register_custom_sitemap_rewrites', 20 );
/**
* Register custom `^sitemap/*` rewrite rules for sitemap routes.
*
@seanlanglands
seanlanglands / check-file-visibility-by-metadata.php
Created July 20, 2023 05:15
Determine whether the file is private or public based on post meta value
<?php
add_filter( 'vip_files_acl_file_visibility', 'check_file_visibility_by_metadata', 11, 2 );
/**
* Given a path determine whether the file is private or public based on the
* value of the attachment's `_custom_restriction_meta` post meta.
*
* @param string $file_visibility one of Automattic\VIP\Files\Acl\(FILE_IS_PUBLIC | FILE_IS_PRIVATE_AND_ALLOWED | FILE_IS_PRIVATE_AND_DENIED).
* @param string $file_path path to file to be checked for visibility.
*
@seanlanglands
seanlanglands / class-cli-import-csv.php
Last active April 6, 2023 19:01
Custom WP-CLI command to import a CSV file into a post type
<?php
/**
* ExamplePackage\CLI_Import_CSV Class.
*
* @package ExamplePackage
*/
namespace ExamplePackage;
if ( ! defined( '\WP_CLI' ) ) {
<?php
/**
* Overwrite default post_tag taxonomy to be non-public.
*
* @see https://developer.wordpress.org/reference/functions/register_taxonomy/
*
* @return void
*/
function vip_modify_post_tag_taxonomy() {
$post_tag_args = get_taxonomy( 'post_tag' );
#{"rootDirectory":"public","phpVersion":"8.0"}
server {
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
{{ssl_certificate_key}}
{{ssl_certificate}}
{{server_name}}
{{root}}