Skip to content

Instantly share code, notes, and snippets.

View mattwatsoncodes's full-sized avatar

Matt Watson mattwatsoncodes

View GitHub Profile
@mattwatsoncodes
mattwatsoncodes / force-block-style-use-default.js
Last active July 4, 2023 12:26
Force Block Style to use Default
// TODO: We should make a little function that handles this by reading the defaults from the block.json.
let blockProps = useBlockProps( {
className: 'my-block-name',
} );
let style = blockProps['className'].split( ' ' ).filter( className => className.startsWith( 'is-style-' ) )[0] || '';
// The default style does not automatically apply. Fix that.
if ( ! style ) {
style = 'is-style-default';
@mattwatsoncodes
mattwatsoncodes / author_and_faculty_rewrite_slugs.php
Last active July 4, 2023 11:59
Code to change the WordPress re-write slugs based on the Author and Faculty parameters
<?php
// Add the following re-write rule to the CPT, out of context here so commented out
//'rewrite' => array( 'slug' => __( '%faculty%/%author%/journal', 'aspire' ) ),
function aspire_register_rewrite_tags() {
// add our rewrite tags
// query at the end allows a custom param, however having it at the start of our URL with no prefix does cause issues
add_rewrite_tag( '%faculty%', '([^&]+)' /*, 'author='*/ );
}
@mattwatsoncodes
mattwatsoncodes / gf_prevent_data.php
Created June 26, 2018 14:16
Prevent Gravity Forms Storing Data
<?php
/**
* Prevent gravity forms storing data
**/
function mkdo_remove_form_entry( $entry ) {
if ( class_exists( 'GFAPI' ) ) {
GFAPI::delete_entry( $entry['id'] );
}
}
add_action( 'gform_after_submission', 'mkdo_remove_form_entry' );
@mattwatsoncodes
mattwatsoncodes / how-i-work.md
Last active January 2, 2022 09:56
How I Like to Work

How I like to work.

What I do

I joined Human Made in January 2022 as a Web Engineer. I tinker with PHP, JS, SCSS, well anything related to the web really.

When I work

  • My timezone is UK Time, either GMT or GMT+1 depending if it’s BST or not.
  • I work around the school run, which means I am usually out of the office between 8:30 and 9:00 and 15:15 and 15:45
@mattwatsoncodes
mattwatsoncodes / functions.php
Created November 14, 2021 20:01
WP Owls - Owl Link Block Pattern
$block_pattern_content = '<!-- wp:group {"className":"owl-link"} -->
<div class="wp-block-group owl-link"><!-- wp:image {"id":121,"sizeSlug":"full","linkDestination":"none","className":"owl-link__image"} -->
<figure class="wp-block-image size-full owl-link__image"><img src="http://wholesome-plugins.test/wp-content/uploads/2021/08/fikret-tozak-Zk-Ydz2IAs-unsplash-scaled-208x270-c-center.jpg" alt="" class="wp-image-121"/></figure>
<!-- /wp:image -->
<!-- wp:group {"className":"owl-link__content"} -->
<div class="wp-block-group owl-link__content"><!-- wp:paragraph -->
<p><strong>Courtney Patubo Kranzke</strong>&nbsp;submitted a proposal for the Global Community Sponsorship program for 2022. As analog events are still up in the air, WordCamps are not included in the draft.</p>
<!-- /wp:paragraph -->
@mattwatsoncodes
mattwatsoncodes / login-one-user-instance.php
Last active January 18, 2019 14:09
Login one user instance
<?php
/**
* Login One User Instance
*
* Only allow one instance of a user to be logged in at any one time.
* Other browser sessions will be logged out other than the latest user to
* sign in with that username.
*/
function mwtsn_example_login_one_user_instance() {
global $sessions;
@mattwatsoncodes
mattwatsoncodes / dynamically-change-locale.php
Last active June 16, 2017 08:04
Dynamically Change Locale
<?php
/**
* Redefine the sites Locale (site langauge)
*
* In this example we try to get the country and the langauge from the page meta,
* if that doesnt exist we fallback to the country and langauge set in the customizer,
* which in turn fall back to gb and en.
*/
function mwtsn_example_redefine_locale( $locale ) {
<?php
/**
* Clickjacking protection
*
* Add header to stop site loading in an iFrame.
**/
function mwtsn_example_send_headers() {
header( 'X-FRAME-OPTIONS: SAMEORIGIN' );
}
add_action( 'send_headers', 'mwtsn_example_send_headers', 10 );