View markup.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add spans and icons to buttons added by applying custom link classes in the WYSIWYG editor | |
* @param $content | |
* @return string | |
*/ | |
function wapr_add_icons_to_buttons($content): string { | |
return preg_replace_callback('/<a class="btn btn--(?:.*) btn--icon" href="(?:.*)">(.*)<\/a>/', function($match) { | |
return str_replace($match[1], '<span>'.$match[1].'</span><i class="fa-regular fa-chevron-right"></i>', $match[0]); | |
}, $content); |
View useTruncatedText.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect, useMemo, MutableRefObject } from 'react'; | |
import { useVisibleSize } from './useVisibleSize.ts'; | |
export function useTruncatedText(outerRef: MutableRefObject<any>, innerRef: MutableRefObject<any>) { | |
const { width: outerWidth } = useVisibleSize(outerRef.current); | |
const { width: innerWidth } = useVisibleSize(innerRef.current); | |
useEffect(() => { | |
if (innerRef.current) { | |
innerRef.current.style.whiteSpace = "nowrap"; |
View ColorThemeTypedExample.styled.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import styled from 'styled-components'; | |
import { ThemeColor } from '../../types'; | |
interface ButtonProps { | |
color: ThemeColor | |
} | |
export const StyledButton = styled.button<ButtonProps>` | |
background: ${({ theme, color }): string => theme.colors[color]}; | |
// more styles |
View ThemeUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { meetsContrastGuidelines } from 'polished'; | |
import { ContrastScores } from 'polished/lib/types/color'; | |
type WCAGLevel = keyof ContrastScores; | |
export function contrastTextColour(color: string, wcag: WCAGLevel = 'AA') { | |
const scores = meetsContrastGuidelines(color, '#fff'); | |
if(scores[wcag]) { | |
return '#fff'; | |
} |
View _useResize.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { MutableRefObject, useMemo, useEffect, useState } from 'react'; | |
interface Dimensions { | |
width: number; | |
height: number; | |
} | |
export function useResize(ref: MutableRefObject<HTMLElement | undefined>, deps: unknown[]): Dimensions { | |
const [width, setWidth] = useState<number>(0); | |
const [height, setHeight] = useState<number>(0); |
View filter-orders-by-role.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add role drop-down to orders screen | |
*/ | |
function doublee_add_order_user_role_filter_selectbox() { | |
global $typenow, $wp_query; | |
if (in_array($typenow, wc_get_order_types('order-meta-boxes'))) : | |
$user_role = ''; |
View class-unhooky-plugin-custom-admin-stuff.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Job listings functionality for Client Website | |
* Note: Requires Ninja Forms plugin | |
* Note: Truncated for use in a gist to demonstrate unhooking a Ninja Forms function | |
* | |
* @since 1.0.0 | |
* @package MyPlugin | |
* @subpackage MyPlugin/admin | |
*/ | |
class MyPlugin_Jobs extends MyPlugin_Settings { |
View useLocalStorage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect, Dispatch, SetStateAction } from 'react'; | |
export function useLocalStorage<T>(key: string, defaultValue: T): { value: T; setValue: Dispatch<SetStateAction<T>> } { | |
const [value, setValue] = useState(() => { | |
return localStorage?.getItem(key) ? JSON.parse(localStorage.getItem(key)) : defaultValue; | |
}); | |
useEffect(() => { | |
localStorage.setItem(key, JSON.stringify(value)); | |
}, [key, value]); |
NewerOlder