This file contains hidden or 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
<!-- wp:cover {"url":"https://cldup.com/Fz-ASbo2s3.jpg","className":"alignwide"} --> | |
<div class="wp-block-cover has-background-dim alignwide" style="background-image:url(https://cldup.com/Fz-ASbo2s3.jpg)"><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} --> | |
<p class="has-text-align-center has-large-font-size">Of Mountains & Printing Presses</p> | |
<!-- /wp:paragraph --></div></div> | |
<!-- /wp:cover --> | |
<!-- wp:paragraph --> | |
<p>The goal of this new editor is to make adding rich content to WordPress simple and enjoyable. This whole post is composed of <em>pieces of content</em>—somewhat similar to LEGO bricks—that you can move around and interact with. Move your cursor around and you’ll notice the different blocks light up with outlines and arrows. Press the arrows to reposition blocks quickly, without fearing about losing things in the process of copying and pasting.</p> | |
<!-- /wp:paragraph --> |
This file contains hidden or 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
const useEffectOnceOnDemand = (effect) => { | |
const [count, setCount] = useState(0); | |
useEffect(() => { | |
if (1 === count) { | |
effect(); | |
} | |
}); | |
return () => setCount((prev) => Math.min(2, prev + 1)); |
This file contains hidden or 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 | |
function flatten_blocks( array $blocks ) { | |
reset( $blocks ); | |
$out = []; | |
while ( $block = array_shift( $blocks ) ) { | |
$out[] = $block; |
This file contains hidden or 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 | |
$arr = [ | |
'apples' => [ | |
'red' => [ | |
'gala', | |
'mcintosh', | |
], | |
'green' => [ | |
'granny_smith', |
This file contains hidden or 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 | |
$valid = new \Alley\Validator\ValidatorByOperator('REGEX', '/^foo/'); | |
$valid->isValid('foobar'); // true | |
$valid = new \Alley\Validator\ValidatorByOperator('NOT IN', ['bar', 'baz']); | |
$valid->isValid('bar'); // false | |
$valid = new \Alley\Validator\ValidatorByOperator('!==', 42); | |
$valid->isValid(43); // true |
This file contains hidden or 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 | |
// Find all paragraph blocks in a post: | |
$grafs = \Alley\WP\match_blocks( $post, [ 'name' => 'core/paragraph' ] ); | |
// Include paragraphs in inner blocks: | |
$grafs = \Alley\WP\match_blocks( | |
$post, | |
[ | |
'flatten' => true, |
This file contains hidden or 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 | |
Alley\WP\Caper::grant_to( 'editor' )->primitives( 'edit_theme_options' ); | |
Alley\WP\Caper::deny_to( 'administrator' )->primitives( 'manage_options' ); | |
Alley\WP\Caper::grant_to( 'author' )->caps_for( 'page' ); | |
Alley\WP\Caper::deny_to( 'editor' )->caps_for( 'category' ); | |
Alley\WP\Caper::grant_to( 'editor' )->caps_for( 'category' )->only( 'delete_terms' ); | |
Alley\WP\Caper::deny( 'author' )->caps_for( 'page' )->except( 'delete_posts' ); |
This file contains hidden or 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 | |
( new \Alley\WP_Bulk_Task\Bulk_Task( 'bananaify' ) )->run( | |
[ | |
'post_status' => 'publish', | |
], | |
function ( $post ) { | |
if ( str_contains( $post->post_content, 'apple' ) ) { | |
$new_value = str_replace( 'apple', 'banana', $post->post_content ); | |
This file contains hidden or 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 | |
$person = Alley\WP\find_one_post( | |
[ | |
'meta_key' => 'twitter', | |
'meta_value' => '@potatomaster', | |
'post_type' => 'person', | |
] | |
); // ?WP_Post |
This file contains hidden or 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_action( | |
'elasticsearch_extensions_config', | |
function ( $es_config ) { | |
$es_config | |
->restrict_post_types( [ 'post', 'page' ] ) | |
->enable_empty_search() | |
->enable_post_type_aggregation() | |
->enable_taxonomy_aggregation( 'category' ) |