Skip to content

Instantly share code, notes, and snippets.

View pbrocks's full-sized avatar

Paul Barthmaier pbrocks

View GitHub Profile
@pbrocks
pbrocks / edit-form-advanced.php
Created July 17, 2021 19:43 — forked from tanamako/edit-form-advanced.php
Wordpress管理画面カスタマイズ
<?php
/**
* Post advanced form for inclusion in the administration panels.
*
* @package WordPress
* @subpackage Administration
*/
// don't load directly
if ( !defined('ABSPATH') )
@pbrocks
pbrocks / check-post-title.php
Created March 15, 2021 14:19
Return the post type after the post title
<?php
/**
* [pbrocks_check_title_filter]
*
* @param [type] $title [description]
* @param [type] $post_id [description]
* @return [type] [description]
*/
function pbrocks_check_title_filter( $title, $post_id = null ) {
$current_post_type = get_post_type();
@pbrocks
pbrocks / run-php-index.php
Created October 15, 2020 14:00
Use this file to run php that also has access to WordPress functions by placing this file in a folder at the root of any WordPress installation.
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>Include WP</title>
<style type="text/css">
html {
box-sizing: border-box;
}
*, *:before, *:after {
@pbrocks
pbrocks / install-phpcs-with-homebrew.md
Last active May 8, 2024 10:29
Install phpcs with Homebrew

Install phpcs with Homebrew

To set up php linting, you’ll want to install this PHP CodeSniffer repo and configure with this WordPress Coding Standards repo: . There are a number of ways to do this, whether direct download, Composer, Homebrew, Pear, etc. The following is what works for me on MacOS using Homebrew:

In a terminal window on your Mac, start by updating your Homebrew.

brew doctor

Then install the Code Sniffer:

@pbrocks
pbrocks / sublime-clean
Created May 17, 2020 21:17 — forked from gerardroche/sublime-clean
Clean Sublime Text caches and optionally clean out any sessions
# 301 https://github.com/gerardroche/dotfiles
@pbrocks
pbrocks / disable-by-default-fullscreen-mode.php
Created April 1, 2020 01:36
Jean-Baptiste Audras -- Disable editor in fullscreen mode by default.
<?php
/**
* https://jeanbaptisteaudras.com/en/2020/03/disable-block-editor-default-fullscreen-mode-in-wordpress-5-4/
*/
function jba_disable_editor_fullscreen_by_default() {
$script = "jQuery( window ).load(function() { const isFullscreenMode = wp.data.select( 'core/edit-post' ).isFeatureActive( 'fullscreenMode' ); if ( isFullscreenMode ) { wp.data.dispatch( 'core/edit-post' ).toggleFeature( 'fullscreenMode' ); } });";
wp_add_inline_script( 'wp-blocks', $script );
}
add_action( 'enqueue_block_editor_assets', 'jba_disable_editor_fullscreen_by_default' );
@pbrocks
pbrocks / ankit-singh-recipe-card.js
Created January 14, 2020 16:13
Adding attributes to WordPress block templates
const { __ } = wp.i18n;
const { registerBlockType } = wp.blocks;
const { InnerBlocks } = wp.blockEditor;
registerBlockType( 'ankit-singh/recipe-card', {
@pbrocks
pbrocks / show-the-block-constituents.php
Last active March 22, 2021 22:53
Use the `render_block` filter to show the elemental parts of a WordPress block.
<?php
add_filter( 'render_block', 'show_the_block_constituents', 10, 2 );
/**
* [show_the_block_constituents] Debug code for showing the parts of WP Blocks
*
* @param [string] $block_content
* @param [array] $block
* @return [string]
*/
@pbrocks
pbrocks / wplancpa-2019-show-block-type.php
Created May 24, 2019 19:40
WC Lancaster filter to show block type if you have WP_DEBUG turned on.
<?php
add_filter( 'render_block', 'wplancpa_2019_show_block_type', 10, 2 );
function wplancpa_2019_show_block_type( $block_content, $block ) {
if ( true === WP_DEBUG ) {
$block_content = "<h5 style=\"color:salmon\">{$block['blockName']}</h5><div class='wp-block' data-blockType='{$block['blockName']}'>{$block_content}</div>";
}
return $block_content;
}
@pbrocks
pbrocks / wclancpa-2019-acf-block-render.php
Created April 27, 2019 16:41
Render an ACF field in a block for WordPress
<?php
/**
* Our combined block and shortcode renderer.
*
* We're not using sophisticated php, so if using the shortcode we'd need to specify all three values.
*
* @param array $attributes The attributes set on the block or shortcode.
*/
function acf_built_with_php_render( $attributes ) {
$return = '<h2 style="color:salmon;">' . ( print_r( $attributes['value_one'], true ) ?: 'value_one not defined' ) . '</h2>';