Skip to content

Instantly share code, notes, and snippets.

View XanderCalvert's full-sized avatar
💭
probably coding PHP

Matt Calvert XanderCalvert

💭
probably coding PHP
View GitHub Profile
<?php
$menu_title_1 = '';
$menu_list_1 = '';
$menu_title_2 = '';
$menu_list_2 = '';
$menu_title_3 = '';
$menu_list_3 = '';
$count = 0;
foreach ($menu_items_left as $menu_item) {
@XanderCalvert
XanderCalvert / header.php
Created January 11, 2023 13:49
before refactoring
<?php
$args = array(
'location_left' => 'top-header-left',
'location_right' => 'top-header-right',
);
// Set Core Variables
$theme_location_left = $args['location_left'];
if ( ($theme_location_left) && ($locations = get_nav_menu_locations()) && isset($locations[$theme_location_left]) ) {
{
"$schema": "https://json.schemastore.org/block.json",
"apiVersion": 2,
"name": "calvert/card-child-block",
"title": "Card Block Child",
"category": "layout",
"icon": "index-card",
"textdomain": "matt-calvert",
"parent": [ "noon/card-block" ],
"example": {},
import { __ } from '@wordpress/i18n';
import { InnerBlocks, RichText, InspectorControls } from '@wordpress/block-editor';
import { ToggleControl, PanelBody } from '@wordpress/components'
const Edit = ( props ) => {
const {
attributes: {
cardTitle,
cardExcerpt,
{
"$schema": "https://json.schemastore.org/block.json",
"apiVersion": 2,
"name": "calvert/card-block",
"title": "Card Block",
"category": "layout",
"icon": "layout",
"textdomain": "matt-calvert",
"example": {},
"editorScript": "file:./build/index.js",
@XanderCalvert
XanderCalvert / parentblock.js
Created November 20, 2022 23:17
Parent block
import { __ } from '@wordpress/i18n';
import { InnerBlocks, RichText, InspectorControls } from '@wordpress/block-editor';
import { ToggleControl, PanelBody } from '@wordpress/components'
const Edit = ( props ) => {
const {
attributes: { toggleCard },
setAttributes,
} = props;
const ALLOWED_BLOCKS = [ 'calvert/card-child-block' ]
@XanderCalvert
XanderCalvert / linkControlExample.js
Created November 16, 2022 15:23
A stripped down block on using LinkControl in the Gutenberg sidebar
import { __ } from '@wordpress/i18n';
import { RichText, InspectorControls, MediaUpload, __experimentalLinkControl as LinkControl } from '@wordpress/block-editor';
import { ToggleControl, PanelBody, Button, FocalPointPicker, BaseControl } from '@wordpress/components'
const Edit = ( props ) => {
const {
attributes: {
post,
},
@XanderCalvert
XanderCalvert / question.php
Last active July 15, 2022 22:55
Interview Question
// Given a list of integers, determine how many of them are divisible by 3.
// If you encounter an integer in the list that is greater than or equal to 300,
// return 0 regardless of how many numbers divisible by 3.
// Not that 0 is divisible by 3.
// Examples:
// Input: [0, 3, 6, 9, 12]
// Output: 5
<?php
function disable_block_for_post_type( $use_block_editor, $post ) {
if ( 'gutenbergless' === $post->post_type ) {
return false;
};
return $use_block_editor;
}
<?php
if ( is_admin() ) {
add_filter( 'use_block_editor_for_post', 'disable_block_for_post_type', 10, 2 );
};