Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
Coding.

Russell Heimlich kingkool68

💻
Coding.
View GitHub Profile
@kingkool68
kingkool68 / README.MD
Last active Jul 15, 2022
Configure WordPress Coding Standards Linting/Formatting in VSCode
View README.MD

This assumes you're editing a WordPress theme which is the root of your VSCode workspace. In other words if your theme lived in /wp-content/themes/my-awesome-theme. You would drag the directory my-awesome-theme into VSCode and start editing files from there. This also assumes you're using Composer.

If this doesn't work for you check out https://www.edmundcwm.com/setting-up-wordpress-coding-standards-in-vs-code/ which details installing the PHP Code Sniffer tools globally instead of in a project.

We need to require dependencies in our project.

composer require --dev squizlabs/php_codesniffer
composer require --dev dealerdirect/phpcodesniffer-composer-installer
composer require --dev wp-coding-standards/wpcs
@kingkool68
kingkool68 / examples.php
Created Jun 23, 2022
Helper functions to make generating WordPress post type labels and taxonomy labels easier
View examples.php
<?php
// Register a Book post type
$args = array(
'labels' => generate_post_type_labels( 'book', 'books' ),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
@kingkool68
kingkool68 / class-coderpad-text-image-block.php
Last active Apr 25, 2022
How I use Advanced Custom Fields' Blocks to make custom components for WordPress sites. Logic is all in PHP, HTML templating is done in Twig via https://github.com/kingkool68/sprig This is in response to a tweet https://twitter.com/Gravnetic/status/1517511382102540288
View class-coderpad-text-image-block.php
<?php
/**
* A block with an image and text on the side
*/
class CoderPad_Text_Image_Block {
/**
* Get an instance of this class
*/
public static function get_instance() {
@kingkool68
kingkool68 / class-coderpad-text-image-block.php
Created Apr 22, 2022
How I use Advanced Custom Fields' Blocks to make custom components for WordPress sites. Logic is all in PHP, HTML templating is done in Twig via https://github.com/kingkool68/sprig
View class-coderpad-text-image-block.php
<?php
/**
* A block with an image and text on the side
*/
class CoderPad_Text_Image_Block {
/**
* Get an instance of this class
*/
public static function get_instance() {
@kingkool68
kingkool68 / merge-current-branch-to-target-branch.sh
Created Feb 1, 2022
Quick little helper script to speed up your Git workflow if you ever need to merge a branch into another frequently (like your current feature branch into a `staging` branch). Useful as a custom command in the Git GUI Fork (https://fork.dev/)
View merge-current-branch-to-target-branch.sh
#!/bin/bash
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
TARGET_BRANCH=staging
git fetch origin $TARGET_BRANCH
git checkout $TARGET_BRANCH
git merge "$CURRENT_BRANCH" -m "Merge branch '$CURRENT_BRANCH' into $TARGET_BRANCH"
git push origin $TARGET_BRANCH
git checkout "$CURRENT_BRANCH"
@kingkool68
kingkool68 / simple-google-apis.php
Created Jan 20, 2022
Interacting with Google API's using their PHP libraries is a nightmare. Skip the headache by authorizing a Guzzle client and make raw HTTP requests instead!
View simple-google-apis.php
<?php
$key_file_path = __DIR__ . '/service-account-credentials.json';
$google_client = new \Google_Client();
$google_client->setAuthConfig( $key_file_path );
// Set the scopes of whatever you need access to
// See https://developers.google.com/identity/protocols/oauth2/scopes
$google_client->setScopes( array( 'https://www.googleapis.com/auth/analytics.readonly' ) );
$http_client = $client->authorize();
@kingkool68
kingkool68 / wp-config.environments.php
Created Nov 27, 2021
Managing `wp-config.php` files for different environments. This allows you to version control your configurations.
View wp-config.environments.php
<?php
/** Loads environment specific config files for WordPress.
* See https://github.com/studio24/wordpress-multi-env-config and/or http://abandon.ie/notebook/wordpress-configuration-for-multiple-environments
*
* Environment can be:
* 1. Directly loaded via an Environment variable (Name: WP_ENV)
* 2. Looks the ServerName attribute
* 3. Default to production (if no other one is found)
*
* ** Usage **
@kingkool68
kingkool68 / loading-csv-data-for-google-charts.php
Last active Oct 26, 2021
James Taylor wanted to load CSV data and display it as a gauge data visualization in WordPress. See https://www.facebook.com/groups/advancedwp/posts/4673874846008026/
View loading-csv-data-for-google-charts.php
<?php
/**
* Plugin Name: River Height Levels
* Plugin URI: https://gist.github.com/kingkool68/567527d28f82bd3a0107970b624fea0a
* Description: Fetch the current river height values and display it as different data visualization.
* Version: 0.0.2
* Author: Russell Heimlich
* Author URI: https://twitter.com/kingkool68
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
View loading-csv-data-for-google-charts.php
<?php
/**
* Load an external CSV file and store it as a transient
*/
function get_the_csv_data() {
$transient_key = 'the-csv-data';
$data = get_transient( $transient_key );
// If the data already exists then return it. We're done here!
if ( false !== $data ) {
View archive-post-type.php
<?php
// Expects a page with the slug (aka post_name) set to `post-type` (the same post-type key as the custom post type)
$post = RH_Post_Type_Archives::get_post_type_archive_post();
setup_postdata( $post );
?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>