Skip to content

Instantly share code, notes, and snippets.

@patrickposner
patrickposner / index.html
Created April 30, 2024 09:18
Redirecting /feed/ to /feed/index.xml
<!DOCTYPE html>
<html>
<head>
<title>Redirecting...</title>
<meta http-equiv="refresh" content="0;url=/">
</head>
<body>
<script type="text/javascript">
window.location = "https://mmm.pics/feed/index.xml";
</script>
@patrickposner
patrickposner / functions.php
Created April 30, 2024 09:13
Replace URLs in atom elements
<?php
add_filter( 'ss_match_tags', function ( $match_tags ) {
$match_tags['atom'] = array( 'href' );
return $match_tags;
} );
@patrickposner
patrickposner / functions.php
Last active April 3, 2024 14:09
Simply Static: Set up a build to run daily with cron.
<?php
register_activation_hook( __FILE__, 'setup_build_cron' );
/**
* Setup a cron job to run daily.
*
* @return void
*/
function setup_build_cron() {
@patrickposner
patrickposner / functions.php
Created February 5, 2024 15:50
Klar Tracking in WooCommerce
<?php
// Klar:sendOrderEvent
add_action( 'woocommerce_thankyou', function ( $order_id ) {
?>
<script>
(function () {
window._k_q = window._k_q || [];
window._k_q.push(["Klar:sendOrderEvent", {
orderId: <?php echo esc_html( $order_id ); ?>,
@patrickposner
patrickposner / functions.php
Created July 26, 2023 17:33
InstaWP - Update temporary directory.
<?php
add_action( 'admin_init', function() {
// Get Simply Static options.
$options = get_option('simply-static');
// Check if directory exists, if not, create it.
$upload_dir = wp_upload_dir();
$temp_dir = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'simply-static' . DIRECTORY_SEPARATOR . 'temp-files';
@patrickposner
patrickposner / lemonsqueezy-modal.html
Created June 3, 2023 10:32
lemonsqueezy-modal.html
<p>
<a href="https://simply-cdn.lemonsqueezy.com/checkout/buy/your-api-key?embed=1&amp;" class="lemonsqueezy-button">
Pay now!
</a>
<script src="https://app.lemonsqueezy.com/js/lemon.js" defer=""></script>
</p>
@patrickposner
patrickposner / functions.php
Created April 17, 2023 13:00
Freemius Basic Auth License Activation
<?php
/* FREEMIUS API BASIC AUTH WORKAROUND */
add_filter( 'http_request_args', 'my_http_request_args_filter', 1, 2 );
add_filter( 'http_request_args', 'my_http_request_args_filter', 9999, 2 );
function my_http_request_args_filter( $parsed_args, $url ) {
if ( false === strpos( $url, '://api.freemius.com' ) ) {
return $parsed_args;
}
@patrickposner
patrickposner / functions.php
Last active March 30, 2023 07:34
Simply Static: Export all pages with shortcode in Single Export
<?php
add_filter( 'ssp_single_export_additional_urls', function ( $related_urls ) {
global $wpdb;
// Get all pages that have a recent posts shortcode.
$page_ids = $wpdb->get_row( "SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%[recent_posts AND post_type='page'", ARRAY_A );
foreach ( $page_ids as $id ) {
$related_urls[] = get_permalink( $id );
@patrickposner
patrickposner / functions.php
Last active December 23, 2022 10:25
Simply Static Pro: Single Export after save_post
<?php
add_action( 'save_post', 'ssp_auto_export', 10, 3 );
/**
* Automatically run a static export after post is saved.
*
* @param int $post_id given post id.
* @param object $post given post object.
* @param bool $update if it's updated or not.
document.addEventListener("DOMContentLoaded", function () {
const language_links = document.querySelectorAll('.wpml-ls-link');
for (const language_link of language_links) {
language_link.addEventListener('click', function handleClick(event) {
event.preventDefault();
let languages = this.getElementsByClassName('wpml-ls-native');
for (const language of languages) {