Skip to content

Instantly share code, notes, and snippets.

View seanlanglands's full-sized avatar
👋

Sean Langlands seanlanglands

👋
View GitHub Profile
<?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 January 24, 2024 00:04
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}}
@seanlanglands
seanlanglands / cta-block-pattern.php
Last active July 21, 2022 09:35
Example block pattern that's based on a cover block featuring move and remove locking attributes.
<?php
$default_attachment_url = get_stylesheet_directory_uri() . '/assets/images/default-cover-bg.jpg';
$block_pattern_content = '<!-- wp:cover {"url":"' . esc_url( $default_attachment_url ) . '","id":42,"dimRatio":90,"minHeight":0,"minHeightUnit":"px","gradient":"vivid-cyan-blue-to-vivid-purple","align":"full","style":{"spacing":{"padding":{"top":"5rem","right":"14rem","bottom":"5rem","left":"14rem"}}}} -->
<div class="wp-block-cover alignfull" style="padding-top:5rem;padding-right:14rem;padding-bottom:5rem;padding-left:14rem;min-height:0px">
<span aria-hidden="true" class="has-background-dim-90 wp-block-cover__gradient-background has-vivid-cyan-blue-to-vivid-purple-gradient-background has-background-dim has-background-gradient"></span>
<img class="wp-block-cover__image-background wp-image-42" alt="" src="' . esc_url( $default_attachment_url ) . '" data-object-fit="cover"/>
<div class="wp-block-cover__inner-container">
<!-- wp:heading {"textAlign":"center","level":4,"style":{"spacing":{"margin":{"top"
@seanlanglands
seanlanglands / theme.json
Created March 28, 2022 22:33
Example theme.json for an existing Classic Theme that excludes many default color and typography controls from being enabled.
{
"schema": "https://schemas.wp.org/trunk/theme.json",
"version": 2,
"settings": {
"layout": {
"contentSize": "800px",
"wideSize": "1000px"
},
"color": {
"link": false