Skip to content

Instantly share code, notes, and snippets.

View Bobz-zg's full-sized avatar
👨‍💻
working remotely

Vlado Bosnjak Bobz-zg

👨‍💻
working remotely
View GitHub Profile
@Bobz-zg
Bobz-zg / lock-saved-apps.sh
Last active November 5, 2026 04:06
Prevent apps and windows from reopening on Mac
#!/bin/bash
# lock-saved-apps.sh: stop macOS from reopening apps after a WindowServer crash or relogin.
#
# macOS remembers which apps were running and relaunches them at the next login,
# including the "login" that follows a WindowServer crash, where the
# "Reopen windows when logging back in" checkbox never appears. This script empties
# the files loginwindow keeps that list in and makes them immutable, so nothing
# can be saved and nothing is relaunched. Login items are unaffected.
#
# Usage: ./lock-saved-apps.sh [lock|unlock|status] (default: lock)
@Bobz-zg
Bobz-zg / Prevent apps and windows from reopening on Mac.md
Last active November 5, 2026 04:03
Prevent apps and windows from reopening on Mac

Stop macOS from reopening apps after a WindowServer crash

When WindowServer crashes (or you force-quit it), macOS drops you back to the login screen and, once you log in, relaunches every app that was running. The "Reopen windows when logging back in" checkbox doesn't help here: you never see the logout dialog, so it never gets a say.

lock-saved-apps.sh stops this by emptying the files where macOS keeps the "apps to relaunch" list and making them immutable. macOS can't save the list, so there's nothing to relaunch.

Not affected: login items (System Settings > General > Login Items) still start as usual.

Tested on macOS 27. It also covers the location used by earlier releases.

@Bobz-zg
Bobz-zg / yoast-content-analysis.js
Last active August 24, 2025 09:54
Additional content for Yoast SEO Content analysis Javascript plugin
/* global YoastSEO */
class YoastAnalysis {
constructor() {
// Initialize cached content storage for extra content to analyze
this.cachedContent = '';
// Track whether the data fetching process has completed
this.isDataFetched = false;
// Check that YoastSEO and its analysis worker are available before proceeding
if ( typeof YoastSEO === "undefined" || typeof YoastSEO.analysis === "undefined" || typeof YoastSEO.analysis.worker === "undefined" ) {
@Bobz-zg
Bobz-zg / get-post-content.php
Last active August 24, 2025 09:53
Additional content for Yoast SEO Content analysis
<?php
// Enqueue the custom Yoast Analysis JavaScript in the WordPress admin editor.
add_action( 'admin_enqueue_scripts', function( $hook ) {
// Only load the script on post editing screens ('post.php' for edit, 'post-new.php' for new posts).
if ( in_array( $hook, [ 'post.php', 'post-new.php' ], true ) ) {
// Build the full URL to the JavaScript file in the theme's 'js' directory.
$script_path = get_template_directory_uri() . '/js/yoast-analysis.js';
// Enqueue the script with a handle 'yoast-analysis'.
@Bobz-zg
Bobz-zg / mods-acf-textarea.php
Last active May 21, 2025 04:07
Set default values for ACF Textarea field in WP Admin
<?php
// No direct access
defined( 'ABSPATH' ) || exit;
/**
* Set default values for ACF Textarea field in WP Admin
*/
add_filter( 'acf/validate_field', function( $field ) {
@Bobz-zg
Bobz-zg / codesoup-wp-rest-auth.php
Last active May 1, 2025 08:18
WordPress REST Auth with custom cookie
<?php declare( strict_types=1 );
/** Prevents direct file access for security. */
defined( 'ABSPATH' ) || exit;
/**
* Class CodeSoup_CrossDomain_Cookie_Auth
*
* Drop-in class for secure cross-domain cookie authentication in WordPress REST API.
*
@Bobz-zg
Bobz-zg / lightning-address.php
Last active June 6, 2022 06:49
Add Lightning address to WordPress head
<?php
/**
* Plugin Name: Lightning Address
* Plugin URI: https://gist.github.com/Bobz-zg/5e8fe19442d88ddb32bae428dfc199f3/edit
* Author: Vlado Bosnjak
* Author URI: https://github.com/code-soup
* Description: Handle the basics with this plugin.
* Version: 0.0.1
* Requires at least: 5.2
@Bobz-zg
Bobz-zg / include-email-in-woocommerce-address-output.php
Created February 12, 2021 09:16
Include email address in WooCommerce address output | Part 3
<?php
/**
* Replace {email} shortcode with actual email address
*
* @link https://github.com/woocommerce/woocommerce/blob/5a707f3e74a18af2d7bf14c20ee65e702a119557/includes/class-wc-countries.php#L601
*/
add_filter('woocommerce_formatted_address_replacements', function( $address, $args ) {
// Replace email for billing address
if ( isset( $args['billing_email'] ) )
@Bobz-zg
Bobz-zg / include-email-in-woocommerce-address-output.php
Last active February 16, 2021 05:18
Include email address in WooCommerce address output | Part 2
<?php
/**
* Append email in list of visible info
*
* @link https://github.com/woocommerce/woocommerce/blob/ab4a46e32e338cbf33094ab26144744a021a21a9/includes/wc-account-functions.php#L316
*/
add_filter( 'woocommerce_my_account_my_address_formatted_address', function( $address, $user_id, $address_type ) {
// Meta key is either billing or shipping
$meta_key = $address_type . '_email';
@Bobz-zg
Bobz-zg / include-email-in-woocommerce-address-output.php
Created February 12, 2021 09:05
Include email address in WooCommerce address output | Part 1
<?php
/**
* Append email to address format
*
* @link https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-countries.php#L510
*/
add_filter( 'woocommerce_localisation_address_formats', function( $formats ) {
// Double quotes in sprintf() or \n will not be parsed as a new line character