Skip to content

Instantly share code, notes, and snippets.

View proweb's full-sized avatar

Sergey Mochalov proweb

View GitHub Profile
@aguilar1181
aguilar1181 / wp-preload.php
Last active February 11, 2023 20:50
add to WordPress themes functions.php to preload assets without a plugin
<?php
/**
* Preloading WordPress assets without a plugin.
* Change function name to something more unique.
* Priority is set to 0 to include as high in the <head> DOM as possible. Change priority if needed.
* Use WordPress is_page() to target specific page or is_front_page() to target ONLY homepage as in Option #1
* If asset needs to be preloaded globally use Option #2.
* For multiple assets clone the link tag instead of the entire echo block.
* Change 'as' attribute accordingly. Values for 'as' can be found here https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-as.
* Use abolute paths. For external assets paste the url, for internal assets use WordPress functions to construct URL.
@KevinBatdorf
KevinBatdorf / router.php
Last active December 26, 2025 12:01
A simple router for WordPress REST API - Laravel-like
<?php
defined( 'ABSPATH' ) or die;
namespace Kevin;
class Router extends \WP_REST_Controller
{
protected static $instance = null;
public function getHandler($namespace, $endpoint, $callback) {
\register_rest_route(
@KevinBatdorf
KevinBatdorf / uploadImage.ts
Last active December 26, 2025 12:01
Upload an image to the WordPress media library using the ImageData JavaScript object type
import apiFetch from '@wordpress/api-fetch'
// This is also set up to clone fields from an existing image.
// Just remove imageToClone and supply the missing fields on your own.
export const uploadImage = async (image: ImageData, imageToClone: WpImage): Promise<WpImage | undefined> => {
const canvas = document.createElement('canvas')
canvas.width = image.width
canvas.height = image.height
const ctx = canvas.getContext('2d')
if (!ctx) return
import _ from 'lodash';
import PropTypes from 'prop-types';
import React, { Fragment } from 'react';
import { BlockControls } from '@wordpress/block-editor';
import { isUnmodifiedDefaultBlock } from '@wordpress/blocks';
import {
ToolbarButton,
ToolbarGroup,
} from '@wordpress/components';
@homu9
homu9 / gist:7d68b59aeb24c6f02455b776263041a2
Created April 13, 2022 19:54
Bulk update plugins for runcloud
#!/bin/bash
# Change directory to /home
cd /home
# Iterate through all users directories
for user in * ; do
# For every webapp under the user directory
# Count wp-config files to make sure its Wordpess
export const isValidJson = (str) => {
try {
JSON.parse(str)
return true
} catch (e) {
return false
}
}
@HardeepAsrani
HardeepAsrani / useSettings.js
Last active December 15, 2023 22:00
useSettings.js
/**
* WordPress dependencies.
*/
import api from '@wordpress/api';
import { __ } from '@wordpress/i18n';
import { dispatch } from '@wordpress/data';
import {
@taotiwordpress
taotiwordpress / twig-bag-of-tools.md
Last active February 11, 2026 17:18
Twig Cheatsheet #twig #timber #wordpress #cheatsheet #images #wp-query #wp_query #the_loop

Timber Bag of Tools Cheat Sheet

Useful Variables

Remember, there are 'TWIG' tools and then there are 'Timber' tools.

The second is WordPress specific.

Twig-based Variables

@HardeepAsrani
HardeepAsrani / useMeta.js
Last active December 15, 2023 22:00
useMeta.js
/**
* WordPress dependencies.
*/
import { useDispatch, useSelect } from '@wordpress/data';
/**
* useMeta Hook.
*
* useMeta hook to get/update WordPress' meta fields.
*

So, You Want to be a Systems Engineer

Systems Engineering (also known as Infrastructure Engineering, Operations Engineering, or DevOps) is a challenging but rewarding career path. Because Systems Engineering draws from a wide variety of smaller topics, it can be hard to know where to start and in what order to begin. This resource is intended to give you a sketch of some of the learning-paths that that can lead you to a career in Systems Engineering.

What do I need to know?

To start, let's examine a high-level list of topics that established systems engineers should have knowledge of. In each of these topics, the level of depth required to get started as a systems engineer may vary, but it's good to have a general breadth of knowledge on all of these topics.

These lists are not exhaustive, rather a good starting point to gain general knowledge.