Remember, there are 'TWIG' tools and then there are 'Timber' tools.
The second is WordPress specific.
| // getDescription - given a url, this Eleventy filter extracts the meta | |
| // description from within the <head> element of a web page using the cheerio | |
| // library. | |
| // | |
| // The full html content of the page is fetched using the eleventy-fetch plugin. | |
| // If you have a lot of links from which you want to extract descriptions, the | |
| // initial build time will be slow. However, the plugin will cache the content | |
| // for a duration of your choosing (in this example, it's set to 1 day). | |
| // | |
| // The description is extracted from the <meta> element with the name attribute |
| <?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. |
| <?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( |
| 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 |
| #!/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 | |
| } | |
| } |
| /** | |
| * WordPress dependencies. | |
| */ | |
| import api from '@wordpress/api'; | |
| import { __ } from '@wordpress/i18n'; | |
| import { dispatch } from '@wordpress/data'; | |
| import { |
| /** | |
| * WordPress dependencies. | |
| */ | |
| import { useDispatch, useSelect } from '@wordpress/data'; | |
| /** | |
| * useMeta Hook. | |
| * | |
| * useMeta hook to get/update WordPress' meta fields. | |
| * |