Skip to content

Instantly share code, notes, and snippets.

View kasparsd's full-sized avatar

Kaspars Dambis kasparsd

View GitHub Profile
@kasparsd
kasparsd / lazy-load-videos.js
Created June 3, 2025 07:57
Lazy Load Videos
(function () {
function initLazyVideos() {
var videos = document.querySelectorAll("video[data-src]");
if ("IntersectionObserver" in window) {
var observer = new IntersectionObserver(
function (entries, observer) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
var video = entry.target;
@kasparsd
kasparsd / readme.md
Last active June 13, 2025 14:26
WordPress handbooks as a single markdown file for LLMs (source https://developer.wordpress.org)
<?php
add_action(
'login_head',
function () {
$site_icon_url = get_site_icon_url();
if ( ! empty( $site_icon_url ) ) {
printf(
'<style type="text/css">
@kasparsd
kasparsd / x.php
Created April 22, 2025 14:02
X API get latest Tweets
<?php
class Twitter {
private string $bearer;
public function __construct( string $bearer ) {
$this->bearer = $bearer;
}
public function get_rate_limits() {
@kasparsd
kasparsd / navigation-item.php
Created April 22, 2025 07:54
Enable .current-menu-ancestor for WP core navigation item block
<?php
/**
* Plugin Name: Navigation Item Ancestors
*/
namespace Config\Navigation_Item;
function get_post_children_ids(): array {
static $children_ids;
@kasparsd
kasparsd / render.php
Created April 14, 2025 12:53
Render template of a login-logout block for WordPress
<?php
/**
* Render the login/logout block.
*
* @param array $attributes Block attributes.
* @param string $content Block content.
* @param array $block Block instance.
*/
$link = [
@kasparsd
kasparsd / 000-redirect-logger.php
Last active March 28, 2025 02:02
A must-use plugin to log and find the source of redirects in WordPress
<?php
/**
* Plugin Name: Redirect Logger
* Description: Find the source of all redirects.
*
* Place this in the mu-plugins directory and check the
* redirects-1234567.json file in the uploads directory for the logs.
*/
namespace WPElevator\Redirect_Logger;
@kasparsd
kasparsd / wp-encrypted.php
Created March 19, 2025 09:55
Initial draft
<?php
abstract class WP_Encrypted_Secret_Method {
protected WP_Encrypted_Secret_Storage $storage;
public function __construct( WP_Encrypted_Secret_Storage $storage ) {
$this->storage = $storage;
}
abstract public function is_supported(): bool;
<?php
namespace YourVendor\Project;
class Config {
private static array $config = [];
private function __construct() {
// Private constructor to prevent direct instantiation
}
<?php
namespace YourVendor\WooCommerce_CLI;
use WP_CLI;
use WooCommerce;
function anon_orders( $args, $assoc_args ) {
$order_ids = wc_get_orders(
[