Skip to content

Instantly share code, notes, and snippets.

View hellofromtonya's full-sized avatar

Tonya Mork hellofromtonya

View GitHub Profile
@hellofromtonya
hellofromtonya / init.php
Created July 14, 2016 01:20
Using the theme's information to populate the constants instead of duplicating it.
<?php
/**
* Theme initialization
*
* @package KnowTheCode\Developers
* @since 1.0.0
* @author hellofromTonya
* @link https://knowthecode.io
* @license GNU General Public License 2.0+
*/
@hellofromtonya
hellofromtonya / prev-next.php
Created July 10, 2016 17:53
Two ways to turn on the Prev & Next links in Genesis.
//add_action( 'genesis_after_entry', 'genesis_prev_next_post_nav', 9 );
add_action( 'genesis_before_while', 'genesis_sample_loop_setup' );
/**
* Setup the loop.
*
* @since 1.0.0
*
* @return void
*/
@hellofromtonya
hellofromtonya / event-registry-table.php
Created July 10, 2016 17:52
Looking at the event registry table for genesis_after_entry to see what is pre-registered
add_action( 'genesis_after_entry', 'explore_event_registry_table', 1 );
/**
* Let's look at the event registry table for `genesis_after_entry`
* to discover what callbacks are pre-registered to it and in what order.
*
* @since 1.0.0
*
* @return void
*/
function explore_event_registry_table() {
@hellofromtonya
hellofromtonya / ordering-event-registry-table.php
Created July 10, 2016 15:45
Reordering Author Box & After Entry Widgetized Area + Exploring the callbacks in the Event Registry Table in WordPress Plugin API
//remove_action( 'genesis_after_entry', 'genesis_after_entry_widget_area' );
//add_action( 'genesis_after_entry', 'genesis_after_entry_widget_area', 7 );
add_action( 'genesis_after_entry', 'genesis_do_author_box_single', 11 );
remove_action( 'genesis_after_entry', 'genesis_do_author_box_single', 8 );
add_action( 'genesis_after_entry', 'ktc_show_event_table', 1 );
/**
* Let's look inside of the event registry table for the event name
* 'genesis_after_entry'. `$wp_filter` is the global variable for
@hellofromtonya
hellofromtonya / post-permalink.php
Created July 9, 2016 20:06
Customization example for changing the post permalink (i.e. which is displayed when there is no post title)
add_filter( 'genesis_post_permalink', 'genesis_sample_change_post_permalink' );
/**
* Change the post permalink by prefixing with an indicator as to what it is.
*
* @since 1.0.0
*
* @param string $html
*
* @return string
*/
@hellofromtonya
hellofromtonya / post-content-nav.php
Created July 9, 2016 19:51
Example of how to customize unfiltered string content using PHP instruction str_replace
add_filter( 'wp_link_pages_args', 'change_link_pages_args' );
/**
* Change the Link Pages Arguments - a demonstration of how to change
* "unfiltered" (meaning not passed through apply_filters())
* string data using PHP instruction str_replace().
*
* @since 1.0.0
*
* @param array $args
*
@hellofromtonya
hellofromtonya / post.php
Last active July 9, 2016 01:54
Same function refactored using the "Return Early Pattern" - now when the conditions will not let the function continue, we get out of the function right away
function genesis_do_post_image() {
if ( is_singular() || ! genesis_get_option( 'content_archive_thumbnail' ) ) {
return;
}
$img = genesis_get_image( array(
'format' => 'html',
'size' => genesis_get_option( 'image_size' ),
'context' => 'archive',
@hellofromtonya
hellofromtonya / post.php
Created July 9, 2016 01:38
Real example of a "return early pattern" opportunity - actually there are two examples of it in here.
function genesis_do_post_image() {
/**
* Return Early Pattern opportunity
* ================================
* Notice that the code wrapped in this conditional block only executes IF the
* conditional expression is true. Hum, that means if the conditional expression
* is false, then the function is done and nothing else is going to happen.
*/
if ( ! is_singular() && genesis_get_option( 'content_archive_thumbnail' ) ) {
@hellofromtonya
hellofromtonya / layout.php
Created April 22, 2016 14:38
Proposed fix for Genesis header right widgets
function genesis_header_body_classes( array $classes ) {
if ( current_theme_supports( 'custom-header' ) ) {
if ( get_theme_support( 'custom-header', 'default-text-color' ) !== get_header_textcolor() || get_theme_support( 'custom-header', 'default-image' ) !== get_header_image() )
$classes[] = 'custom-header';
}
if ( 'image' === genesis_get_option( 'blog_title' ) || ( get_header_image() && ! display_header_text() ) )
$classes[] = 'header-image';
@hellofromtonya
hellofromtonya / allow-login-via-email.php
Created April 12, 2016 02:45
Allow login via username or password for WordPress
<?php
namespace KnowTheCode;
add_filter( 'authenticate', __NAMESPACE__ . '\enable_login_with_email', 20, 3 );
/**
* Allow the user to log in via email address.
*
* If the `$email_or_username` parameter is not an email, then bail out, returning the `$user`.
* Otherwise, get the user's object via the email. Then reauthenticate their login
* via `wp_authenticate_username_password`.