Half-Elf on Tech

Thoughts From a Professional Lesbian

Author: Ipstenu (Mika Epstein)

  • FacetWP, Genesis, and Archives

    FacetWP, Genesis, and Archives

    In my ongoing use of FacetWP and Genesis, I ran into a case where I wanted to change the archive description content based on what sorts of options had been selected in the search. In part I wanted to remind visitors of what they’d picked, but also I wanted to easy to remove a search facet.

    Before

    In the beginning, the archive was a static thing:

    Before any work was done - it says 'TV Shows' and lists how many.

    This is intentionally boring. It lists the archive title, how many posts, and a description.

    Filtering the Content

    Since this is Genesis, the first step is to know how to filter at all. Since I’m only doing this on custom post types, I went with the very precise action and that is genesis_do_cpt_archive_title_description (aptly named).

    I remove it and then add in my own:

    remove_action( 'genesis_before_loop', 'genesis_do_cpt_archive_title_description' );
    add_action( 'genesis_before_loop', 'DOMAIN_do_facet_archive_title_description' );
    

    From here out, all the work will happen in the function DOMAIN_do_facet_archive_title_description which lives in my functions.php because it’s all theme specific.

    What Gets Added

    Now it’s time to decide what you want to add. I picked three things:

    1. Change the post count based on the results
    2. List the selections chosen
    3. Change the title based on the sort order

    Those are two simple asks and one weird one.

    Facet comes with the ability to display counts and selections:

    • facetwp_display( 'counts' );
    • facetwp_display( 'selections' );

    The problem I had was that the counts were formatted in a way I didn’t like, so I quickly cleaned it up by filtering the result count:

    add_filter( 'facetwp_result_count', function( $output, $params ) {
        $output = $params['total'];
        return $output;
    }, 10, 2 );
    

    That means the count and the selections can simply be tacked on to the description.

    Adding the Sort Data

    The hardest part was figuring out how to add the sort data. Since FacetWP uses a lot of javascript, I spent half an afternoon ranting to myself and trying to figure out how to do this in javascript. And then I did what I usually do when confused. I read the code.

    As I read, I realized some of FacetWP’s magic is that they pass the GET parameters of the search over to javascript… And if they were doing that, then I could just use PHP to grab those parameters.

    All I had to do was pass $_GET['fwp_sort'] into a variable.

    The Code

    Enough talk. Here’s the code:

    function lwtvg_do_facet_archive_title_description() {
    
    	$headline = genesis_get_cpt_option( 'headline' );
    
    	if ( empty( $headline ) && genesis_a11y( 'headings' ) ) $headline = post_type_archive_title( '', false );
    
    	$intro_text  = genesis_get_cpt_option( 'intro_text' );
    	$count_posts = facetwp_display( 'counts' );
    	$selections  = facetwp_display( 'selections' );
    	$fwp_sort    = ( isset( $_GET['fwp_sort'] ) )? $_GET['fwp_sort'] : '';
    
    	switch ( $fwp_sort ) {
    		case 'most_chars':
    			$sort = 'Number of Characters (Descending)';
    			break;
    		case 'least_chars':
    			$sort = 'Number of Characters (Ascending)';
    			break;
    		case 'most_dead':
    			$sort = 'Number of Dead Characters (Descending)';
    			break;
    		case 'least_dead':
    			$sort = 'Number of Dead Characters (Ascending)';
    			break;
    		case 'date_desc':
    			$sort = 'Date (Newest)';
    			break;
    		case 'date_asc':
    			$sort = 'Date (Oldest)';
    			break;
    		case 'title_desc':
    			$sort = 'Name (Z-A)';
    			break;
    		case 'title_asc':
    		default:
    			$sort = 'Name (A-Z)';
    	}
    
    	$headline    = $headline ? sprintf( '<h1 %s>%s Sorted By %s (%s)</h1>', genesis_attr( 'archive-title' ), strip_tags( $headline ), $sort, $count_posts ) : '';
    
    	$intro_text  = $intro_text ? apply_filters( 'genesis_cpt_archive_intro_text_output', $intro_text ) : '';
    	$intro_text .= $selections;
    
    	if ( $headline || $intro_text ) printf( '<div %s>%s</div>', genesis_attr( 'cpt-archive-description' ), $headline . $intro_text );
    }
    

    You’ll notice that I’ve kept in all the regular Genesis filters. This was so that my theme can take advantage of whatever magic Genesis invents down the line.

    How It Looks

    Now the default looks like this:

    Default view, before sorting

    And after you’ve picked a few options, it changes to this:

    After Sorting

    If you click the little x’s on the side of the selections, they’re removed.

    There’s still room for design improvement, but remember folks. Release and iterate.

  • Adding Sort Options to Facet

    Adding Sort Options to Facet

    As I implement more and more aspects of FacetWP, I find more and more ways to manipulate the searches. At first I only added in the features that let people easily search for multiple aspects at once. But I hadn’t yet added in any features to sorting.

    Sorting and Ordering

    The way Facets generally work is that you can easily organize all ‘types’ together, so if you wanted to search for everything that crossed four separate categories, it was very easy. In addition, you can extend it to search meta data as well.

    Sorting, on the other hand, is changing the order of the results. For example, if you wanted to search for everyone with terms A, B, and D, and post meta foo, but order them based on post meta bar, you can!

    A Practical Example

    I always do better with examples I can wrap my hands around.

    Take television shows. Take a list of 500 TV shows, and have them include the following taxonomies:

    • Genres (drama, sitcom, etc)
    • Airdates (Year to Year)
    • Tropes (common tropes)
    • Number of characters
    • Number of dead characters

    That’s enough for now.

    With that list, and a couple facets, you can concoct a smaller list of all sitcoms that aired in between 2014 and 2016 (inclusive), with a trope of ‘sex workers.’ The answer is 4 by the way. By default, the list displays alphabetically.

    But. What if you wanted to order them by the ones with the most characters first?

    That’s sorting.

    The Code

    Okay so how do we add this in? Functions!

    Facet comes with quite a few defaults, but it lets you add your own sort options. The two things I’m going to show below are how to rename the display labels for some of the defaults, and how to add in one new option for the most number of characters:

    add_filter( 'facetwp_sort_options', 'DOMAIN_facetwp_sort_options', 10, 2 );
    
    function facetwp_sort_options( $options, $params ) {
    
    	$options['default']['label']    = 'Default (Alphabetical)';
    	$options['title_asc']['label']  = 'Name (A-Z)';
    	$options['title_desc']['label'] = 'Name (Z-A)';
    
    	if ( is_post_type_archive( 'DOMAIN_shows' ) ) {
    
    		$options['most_characters'] = array(
    			'label' => 'Number of Characters (Descending)',
    			'query_args' => array(
    				'orderby'  => 'meta_value_num', // sort by numerical
    				'meta_key' => 'DOMAIN_char_count',
    				'order'    => 'DESC', // descending order
    			)
    		);
    	}
    

    I have this wrapped in a check for is_post_type_archive because I don’t want the options to show on other pages. The meta key is the name of the meta key you’re going to use to sort by (I have key that updates every time a post is saved with a count of characters attached) and the orderby value is one of the ones WP Query can use.

    End result?

    A dropdown with the options

    Looks nice!

  • Calm Under Pressure

    Calm Under Pressure

    A friend remarked she was impressed I was able to stay calm under the abuse slung my way. I have a secret.

    I’m Often Very Angry

    I’m not calm. I’m often quite irate and I froth and I rant. Some of my friends hear those rants. The complaints about how can people be that myopic and obtuse run rampant. I also do on occasion see red and feel my blood pressure rise and I want to reply to people so angrily.

    I really do. I want to scream and use all caps to emphasize that lying to people, trying to trick them, or otherwise doing bad things makes them bad people. I really want to shake some people to make them see they’re hurting themselves more than anything else. Some people I want to take their computers away because clearly they’re too immature for even free plugin hosting.

    That’s My Secret

    If you saw the movie The Avengers, then you may recall a moment when Bruce Banner said he controlled the Hulk by always being angry.

    The trick of that is its simplicity. You see, if Banner could only control the Hulk by not getting angry, then he’d lose. But by accepting his anger and being always angry at the state of the world, at his situation, and so on, he doesn’t have to control the anger anymore. He has to control his temper. That is, he controls his response to anger, but he allows the anger to happen.

    It’s Okay To Be Angry

    We all get angry. We see people doing stupid things and we get mad. But we have a choice in how we respond and react to those things. You can’t stop yourself from being angry, but you can stop yourself from being an uncontrolled Hulk when you’re angry.

    Seeing people not care about others gets me madder than anything else. Be it cutting in line, stealing, abuse, or the government. Or, yes, plugins. I get pissed off. I find that lack of humanity, lack of humanitarianism, to be appalling and disgusting.

    But I don’t lash out and hurt people (at least not intentionally) when it happens. I try to educate, to discuss, and to communicate.

    We Have A Choice

    We usually have a choice on how we react. There are, of course, situations where we are not in control of ourselves, where we react before we can control. Trauma triggers cause that in many of us. But where and when we do have a choice, we must remember our humanity. We must chose control.

  • Taxonomy Icons

    Taxonomy Icons

    Last year I talked about how I made icons for my taxonomy terms. When you have a limited number of terms, that makes sense. When you have a taxonomy with the potential for a high volume of terms, like nations (192), or worse an unlimited number of terms, this approach looses its value.

    Instead, I realized what I needed for a particular project was a custom icon for each taxonomy. Not the term.

    I split this up into two files because I used a slightly different setup for my settings API, but the tl;dr of all this is I made a settings page under themes called “Taxonomy Icons” which loads all the public, non-default taxonomies and associates them with an icon.

    For this to work for you, you will need to have your images in a folder and define that as your IMAGE_PATH in the code below. Also mine is using .svg files, so change that if you’re not.

    File 1: taxonomy-icons.php

    The one gotcha with this is I usually set my default values with $this->plugin_vars = array(); in the __construct function. You can’t do that with custom taxonomies, as they don’t exist yet.

    class TaxonomyIcons {
    
    	private $settings;
    	const SETTINGS_KEY = 'taxicons_settings';
    	const IMAGE_PATH   = '/path/to/your/images/';
    
    	/*
    	 * Construct
    	 *
    	 * Actions to happen immediately
    	 */
        public function __construct() {
    
    		add_action( 'admin_menu', array( $this, 'admin_menu' ) );
    		add_action( 'admin_init', array( $this, 'admin_init' ) );
    		add_action( 'init', array( $this, 'init' ) );
    
    		// Normally this array is all the default values
    		// Since we can't set it here, it's a placeholder
    		$this->plugin_vars = array();
    
    		// Create the list of imagess
    		$this->images_array = array();
    		foreach ( glob( static::IMAGE_PATH . '*.svg' ) as $file) {
    			$this->images_array[ basename($file, '.svg') ] = basename($file);
    		}
    
    		// Permissions needed to use this plugin
    		$this->plugin_permission = 'edit_posts';
    
    		// Menus and their titles
    		$this->plugin_menus = array(
    			'taxicons'    => array(
    				'slug'         => 'taxicons',
    				'submenu'      => 'themes.php',
    				'display_name' => __ ( 'Taxonomy Icons', 'taxonomy-icons' ),
    			),
    		);
        }
    
    	/**
    	 * admin_init function.
    	 *
    	 * @access public
    	 * @return void
    	 * @since 0.1.0
    	 */
    	function admin_init() {
    		// Since we couldn't set it in _construct, we do it here
    		// Create a default (false) for all current taxonomies
    		$taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ), 'names', 'and' );
    		if ( $taxonomies && empty( $this->plugin_vars ) ) {
    			foreach ( $taxonomies as $taxonomy ) {
    				$this->plugin_vars[$taxonomy] = false;
    			}
    		}
    	}
    
    	/**
    	 * init function.
    	 *
    	 * @access public
    	 * @return void
    	 * @since 0.1.0
    	 */
    	function init() {
    		add_shortcode( 'taxonomy-icon', array( $this, 'shortcode' ) );
    	}
    
    	/**
    	 * Get Settings
    	 *
    	 * @access public
    	 * @param bool $force (default: false)
    	 * @return settings array
    	 * @since 0.1.0
    	 */
    	function get_settings( $force = false) {
    		if ( is_null( $this->settings ) || $force ) {
    			$this->settings = get_option( static::SETTINGS_KEY, $this->plugin_vars );
    		}
    		return $this->settings;
    	}
    
    	/**
    	 * Get individual setting
    	 *
    	 * @access public
    	 * @param mixed $key
    	 * @return key value (if available)
    	 * @since 0.1.0
    	 */
    	function get_setting( $key ) {
    		$this->get_settings();
    		if ( isset( $this->settings[$key] ) ) {
    			return $this->settings[$key];
    		} else {
    			return false;
    		}
    	}
    
    	/**
    	 * Set setting from array
    	 *
    	 * @access public
    	 * @param mixed $key
    	 * @param mixed $value
    	 * @return void
    	 * @since 0.1.0
    	 */
    	function set_setting( $key, $value ) {
    		$this->settings[$key] = $value;
    	}
    
    	/**
    	 * Save individual setting
    	 *
    	 * @access public
    	 * @return void
    	 * @since 0.1.0
    	 */
    	function save_settings() {
    		update_option( static::SETTINGS_KEY, $this->settings );
    	}
    
    	/**
    	 * admin_menu function.
    	 *
    	 * @access public
    	 * @return void
    	 * @since 0.1.0
    	 */
    	function admin_menu() {
    
    		foreach ( $this->plugin_menus as $menu ) {
    			$hook_suffixes[ $menu['slug'] ] = add_submenu_page(
    				$menu['submenu'],
    				$menu['display_name'],
    				$menu['display_name'],
    				$this->plugin_permission,
    				$menu['slug'],
    				array( $this, 'render_page' )
    			);
    		}
    
    		foreach ( $hook_suffixes as $hook_suffix ) {
    			add_action( 'load-' . $hook_suffix , array( $this, 'plugin_load' ) );
    		}
    	}
    
    	/**
    	 * Plugin Load
    	 * Tells plugin to handle post requests
    	 *
    	 * @access public
    	 * @return void
    	 * @since 0.1.0
    	 */
    	function plugin_load() {
    		$this->handle_post_request();
    	}
    
    	/**
    	 * Handle Post Requests
    	 *
    	 * This saves our settings
    	 *
    	 * @access public
    	 * @return void
    	 * @since 0.1.0
    	 */
    	function handle_post_request() {
    		if ( empty( $_POST['action'] ) || 'save' != $_POST['action'] || !current_user_can( 'edit_posts' ) ) return;
    
    		if ( !wp_verify_nonce( $_POST['_wpnonce'], 'taxicons-save-settings' ) ) die( 'Cheating, eh?' );
    
    		$this->get_settings();
    
    		$post_vars = $this->plugin_vars;
    		foreach ( $post_vars as $var => $default ) {
    			if ( !isset( $_POST[$var] ) ) continue;
    			$this->set_setting( $var, sanitize_text_field( $_POST[$var] ) );
    		}
    
    		$this->save_settings();
    	}
    
    	/**
    	 * Render admin settings page
    	 * If setup is not complete, display setup instead.
    	 *
    	 * @access public
    	 * @return void
    	 * @since 0.1.0
    	 */
    	function render_page() {
    		// Not sure why we'd ever end up here, but just in case
    		if ( empty( $_GET['page'] ) ) wp_die( 'Error, page cannot render.' );
    
    		$screen = get_current_screen();
    		$view  = $screen->id;
    
    		$this->render_view( $view );
    	}
    
    	/**
    	 * Render page view
    	 *
    	 * @access public
    	 * @param mixed $view
    	 * @param array $args ( default: array() )
    	 * @return content based on the $view param
    	 * @since 0.1.0
    	 */
    	function render_view( $view, $args = array() ) {
    		extract( $args );
    		include 'view-' . $view . '.php';
    	}
    
    	/**
    	 * Render Taxicon
    	 *
    	 * This outputs the taxonomy icon associated with a specific taxonomy
    	 *
    	 * @access public
    	 * @param mixed $taxonomy
    	 * @return void
    	 */
    	public function render_taxicon ( $taxonomy ) {
    
    		// BAIL: If it's empty, or the taxonomy doesn't exist
    		if ( !$taxonomy || taxonomy_exists( $taxonomy ) == false ) return;
    
    		$filename = $this->get_setting( $taxonomy );
    
    		// BAIL: If the setting is false or otherwise empty
    		if ( $filename == false || !$filename || empty( $filename ) ) return;
    
    		$icon     = file_get_contents( static::IMAGE_PATH . $filename  . '.svg' );
    		$taxicon  = '<span role="img" class="taxonomy-icon ' . $filename . '">' . $icon . '</span>';
    
    		echo $taxicon;
    	}
    
    	/*
    	 * Shortcode
    	 *
    	 * Generate the Taxicon via shortcode
    	 *
    	 * @param array $atts Attributes for the shortcode
    	 *        - tax: The taxonomy
    	 * @return SVG icon of awesomeness
    	 */
    	function shortcode( $atts ) {
    		return $this->render_taxicon( $atts[ 'tax' ] );
    	}
    
    }
    
    new TaxonomyIcons();
    

    File 2: view-appearance_page_taxicons.php

    Why that name? If you look at my render_view function, I pass the ID from get_current_screen() to it, and that means the ID is appearance_page_taxicons and that’s the page name.

    <div class="wrap">
    
    	<h1><?php _e( 'Taxonomy Icons', 'taxonomy-icons' ); ?></h1>
    
    	<div>
    
    		<p><?php __( 'Taxonomy Icons allows you to assign an icon to a non-default taxonomy in order to make it look damn awesome.', 'taxonomy-icons' ); ?></p>
    
    		<p><?php __( 'By default, Taxonomy Icons don\'t display in your theme. In order to use them, you can use a shortcode or a function:' , 'taxonomy-icons' ); ?></p>
    
    		<ul>
    			<li>Shortcode: <code>[taxonomy-icon tax=TAXONOMY]</code></li>
    		</ul>
    
    		<form method="post">
    
    		<?php
    		if ( isset( $_GET['updated'] ) ) {
    			?>
    			<div class="notice notice-success is-dismissible"><p><?php _e( 'Settings saved.', 'taxonomy-icons' ); ?></p></div>
    			<?php
    		}
    		?>
    
    		<input type="hidden" name="action" value="save" />
    		<?php wp_nonce_field( 'taxicons-save-settings' ) ?>
    
    		<table class="form-table">
    
    			<tr>
    				<th scope="row"><?php _e( 'Category', 'taxonomy-icons' ); ?></th>
    				<th scope="row"><?php _e( 'Current Icon', 'taxonomy-icons' ); ?></th>
    				<th scope="row"><?php _e( 'Select Icon', 'taxonomy-icons' ); ?></th>
    			</tr>
    
    			<?php
    
    			foreach ( $this->plugin_vars as $taxonomy => $value ) {
    				?>
    				<tr>
    					<td>
    						<strong><?php echo get_taxonomy( $taxonomy )->label; ?></strong>
    						<br /><em><?php echo get_taxonomy( $taxonomy )->name; ?></em>
    					</td>
    
    					<td>
    						<?php
    						if ( $this->get_setting( $taxonomy ) && $this->get_setting( $taxonomy ) !== false ) {
    							echo $this->render_taxicon( $taxonomy );
    						}
    						?>
    
    					</td>
    
    					<td>
    						<select name="<?php echo $taxonomy; ?>" class="taxonomy-icon">
    							<option value="">-- <?php _e( 'Select an Icon', 'taxonomy-icons' ); ?> --</option>
    							<?php
    							foreach ( $this->images_array as $file => $name ) {
    								?><option value="<?php echo esc_attr( $file ); ?>" <?php echo $file == $this->get_setting( $taxonomy ) ? 'selected="selected"' : ''; ?>><?php echo esc_html( $name ); ?></option><?php
    								};
    							?>
    						</select>
    					</td>
    
    				</tr><?php
    			}
    
    			?>
    
    			<tr valign="top">
    				<td colspan="3">
    					<button type="submit" class="button button-primary"><?php _e( 'Save', 'taxonomy-icons' ); ?></button>
    				</td>
    			</tr>
    		</table>
    		</form>
    	</div>
    </div>
    

    End Result

    And in the end?

    An example of Taxonomy Icons

    By the way, the image has some wrong text, but that is what it looks like.

  • Grandchildren Templates

    Grandchildren Templates

    When I posted about my cleverness with grandchildren themes (which as Cosper pointed out was a plugin), reader Damien mentioned templates. He said:

    I have considered using template_redirect() to override template files in the child theme. I’ve experimented with providing selectable page templates where the template file is not in the child theme directory (not so easy).

    Well Damien, I think you’ll be pleased to know there is a solution.

    WPExplorer has made a WordPress page templates plugin. My caution is not to use the GitHub repo, which is not up to date, but copy the one in the post.

    However … I forked it. And my fork is only going to work if you have both WordPress 4.7 and PHP 7. That’s because in PHP 7, PHP finally decided to allow defines to have arrays.

    The Pre-Code

    I use the template in an MU plugin. It sits in a folder called “cpts” and is summoned by my master index.php file that has this:

    define( 'PAGE_TEMPLATER_ARRAY', [
    	'videos-template.php' => 'Videos Archive',
    ] );
    
    include_once( dirname( __FILE__ ) . '/cpts/NAME-OF-cpt.php' );
    include_once( dirname( __FILE__ ) . '/cpts/page-templater.php' );
    

    As you can see, I define my array and then I call the CPT file and the templater itself.

    The Template File

    This is 90% the same as the original. The two changes are I removed the check and failsafe for pre-WP 4.7, and I changed the section to add templates to call my define.

    <?php
    /*
    Plugin Name: Page Template Plugin
    Plugin URI: http://www.wpexplorer.com/wordpress-page-templates-plugin/
    Version: 2.0
    Author: WPExplorer
    */
    
    class PageTemplater {
    
    	/**
    	 * A reference to an instance of this class.
    	 */
    	private static $instance;
    
    	/**
    	 * The array of templates that this plugin tracks.
    	 */
    	protected $templates;
    
    	/**
    	 * Returns an instance of this class.
    	 */
    	public static function get_instance() {
    
    		if ( null == self::$instance ) {
    			self::$instance = new PageTemplater();
    		}
    
    		return self::$instance;
    
    	}
    
    	/**
    	 * Initializes the plugin by setting filters and administration functions.
    	 */
    	private function __construct() {
    
    		$this->templates = array();
    
    		// Add a filter to the wp 4.7 version attributes metabox
    		add_filter(
    			'theme_page_templates', array( $this, 'add_new_template' )
    		);
    
    		// Add a filter to the save post to inject out template into the page cache
    		add_filter(
    			'wp_insert_post_data',
    			array( $this, 'register_project_templates' )
    		);
    
    
    		// Add a filter to the template include to determine if the page has our
    		// template assigned and return it's path
    		add_filter(
    			'template_include',
    			array( $this, 'view_project_template')
    		);
    
    		$this->templates = PAGE_TEMPLATER_ARRAY;
    
    	}
    
    	/**
    	 * Adds our template to the page dropdown for v4.7+
    	 *
    	 */
    	public function add_new_template( $posts_templates ) {
    		$posts_templates = array_merge( $posts_templates, $this->templates );
    		return $posts_templates;
    	}
    
    	/**
    	 * Adds our template to the pages cache in order to trick WordPress
    	 * into thinking the template file exists where it doens't really exist.
    	 */
    	public function register_project_templates( $atts ) {
    
    		// Create the key used for the themes cache
    		$cache_key = 'page_templates-' . md5( get_theme_root() . '/' . get_stylesheet() );
    
    		// Retrieve the cache list.
    		// If it doesn't exist, or it's empty prepare an array
    		$templates = wp_get_theme()->get_page_templates();
    		if ( empty( $templates ) ) {
    			$templates = array();
    		}
    
    		// New cache, therefore remove the old one
    		wp_cache_delete( $cache_key , 'themes');
    
    		// Now add our template to the list of templates by merging our templates
    		// with the existing templates array from the cache.
    		$templates = array_merge( $templates, $this->templates );
    
    		// Add the modified cache to allow WordPress to pick it up for listing
    		// available templates
    		wp_cache_add( $cache_key, $templates, 'themes', 1800 );
    
    		return $atts;
    
    	}
    
    	/**
    	 * Checks if the template is assigned to the page
    	 */
    	public function view_project_template( $template ) {
    
    		// Get global post
    		global $post;
    
    		// Return template if post is empty
    		if ( ! $post ) {
    			return $template;
    		}
    
    		// Return default template if we don't have a custom one defined
    		if ( ! isset( $this->templates[get_post_meta(
    			$post->ID, '_wp_page_template', true
    		)] ) ) {
    			return $template;
    		}
    
    		$file = plugin_dir_path( __FILE__ ). get_post_meta(
    			$post->ID, '_wp_page_template', true
    		);
    
    		// Just to be safe, we check if the file exist first
    		if ( file_exists( $file ) ) {
    			return $file;
    		} else {
    			echo $file;
    		}
    
    		// Return template
    		return $template;
    
    	}
    
    }
    add_action( 'plugins_loaded', array( 'PageTemplater', 'get_instance' ) );
    

    So long as you have PHP 7+ and WP 4.7+, it all works great.

  • While Not Being Consumed

    While Not Being Consumed

    I get painted as a bad guy a lot. I’ve been called names, everything you can think up. I’ve had my gender, sexuality, appearance, and ability all mocked and derided. And most of this has happened since I took up the role of a volunteer in WordPress.

    Creation, Editing, Fitting In

    As a writer, which is how I’ve always seen myself first, I’m used to the ruthlessness of the editing process. I’ve seen papers torn apart and painted red with corrections and commentary. Why this? What are you saying here? I understand the reason for ripping apart creativity to find it’s heart and crux and meaning. Art for the sake of art is different than art for the sake of consumption, after all.

    But instead of a career in the arts, or journalism, I had a different path. Out of college I went to work for a bank and quickly learned how to fit myself into the cog of a machine. I had a role and a life that did not encourage innovation and uniqueness, but that of interchangeability. And in that work, I began to understand the reason for patterns and the similarity.

    I’ve always been fascinated by patterns. I liked to see how the number went from 09 to 18 and 27 and obviously the first number goes up while the second goes down, and isn’t math cool? Seeing the pattern in the work at the bank taught me that while we are all creating and inventing, what we make has to be used in many different ways, and they all need to talk to each other. So we have to make sure all the little cogs and wheels interlock properly.

    It’s Still Creation

    I like to watch the behind the scenes parts of movies. It’s why I prefer to own physical copies. I have watched all the extras for the Lord of the Rings movies. That’s why I know Tolkien disliked when people were obsessed with his work. Because he was not obsessed. He liked what he did, but it wasn’t the end of the world if people didn’t care for it. He made something neat to tell the story he wanted to tell

    Often we as developers fail at this. It’s not entirely our fault. We’re told that what we do is engineering or science, and we forget to stress the creative aspect of inventing that which has never been seen before. We forget progress is forged by dreams. And that’s why, when you see a one star review of your work, it flays you open, leaving you chained to the rocks for the crows to eat your innards. You gave fire to man, and this was your reward?!

    Let’s breathe. What Tolkien didn’t seem to understand was that he had created life. He had made a world so amazing and vibrant, people saw it and wanted to be a part of it. Similarly, when we create code, we give life to others.

    The Good, The Bad, The Ugly

    I’ve gotten the greatest compliments on my work in the form of someone telling me it helped them achieve their goals. People have started businesses, found success, and made something of themselves, all because of something I did.

    But more often, or at least what I remember more, are the names and the anger and the harassment. The people who stalk me down on Slack and Twitter, demanding that I pay attention to them right now and that they are the most important thing… while being angry when I do devote that time, but that my answer is not what they wanted.

    Remember Your Self

    Originally I titled this post “When you’re evil for doing good.” Really that didn’t touch on the real feeling I have about this. Because at the end of it all, I sit and look at the work I’ve done and I ask myself “What was this for?”

    I have a strange life. I have a job that is essentially trying to keep 26% of the internet safe from itself. So my answer for “What was this for?” has become a question of itself. “Is this going to make it better or worse?”

    When I come to decisions, like to tell someone we cannot host their code because they have lied and broken the guidelines too many times, it always comes from this place. Will I make things better for the majority or worse? And in that moment, I ignore the other question. “Will this hurt me?” Because the answer to that is “Yes, probably.”

    “Honor is what you know about yourself.”

    There’s no way I can make hard decisions and not get hurt. There’s no way I can do it and not hurt others. But I sit and I remember my self. My inner self that wants to make things better, safer, and as fair as possible. I remember the me who wants to say “What I do makes the internet better.” And if that comes at a personal cost, well. I will know this.

    I have integrity.

    I have honesty.

    I have empathy.

    As long as I have those, and as long as I do my best and keep learning and becoming better, I will be doing the right thing. And I can live with being ‘evil’ when I’m doing good.