This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* This doesn't work and here's why not. | |
* | |
* The missing piece here has to do with rewrite rules. | |
* The registration process creates new rewrite rules during the process. | |
* This ensures the custom post type is set up appropriately. | |
* Modifying the url structure (which we're doing here) to hierarchical requires a change to the rewrite rules as well. | |
* | |
* The following is the first change you need to make. The rewrite change is not included here. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; | |
;; Domain: wrir.org | |
;; Exported: 2017-01-20 02:47:07 | |
;; | |
;; This file is intended for use for informational and archival | |
;; purposes ONLY and MUST be edited before use on a production | |
;; DNS server. In particular, you must: | |
;; -- update the SOA record with the correct authoritative name server | |
;; -- update the SOA record with the contact e-mail address information | |
;; -- update the NS record(s) with the authoritative name servers for this domain. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pantheon's Terminus is awesome, but it can be frustrating when you're first getting used to the syntax. | |
# Some quick tips follow. | |
# | |
# The following applies for Terminus v1.4+ | |
# | |
# When specifying WP CLI commands to run, separate the terminus commands from the wp cli commands with 2 dashes: | |
terminus remote:wp sitename.env -- command-name --flag=value "wp-content/path/to/file-name.ext" | |
# It also helps to wrap paths in double quotes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('the_content','add_my_content'); | |
function add_my_content($content) { | |
$my_custom_text = '<hr><div class="patreonpara"><p><em>PARAGRAPH TEXT</em></p><a href="LINKURL" data-patreon-widget-type="become-patron-button" class="patreonbutton"><img src="FILEURL"></a></div>'; | |
$my_custom_text_other = 'something else'; | |
if(is_single() && !is_home()) { | |
if(in_category('videos')) { | |
$content .= $my_custom_text_other; | |
} else { | |
$content .= $my_custom_text; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Found: https://steindom.com/articles/exporting-and-creating-field-definitions-drupal-7 | |
// My new favorite developer because of this, "Now that you understand how it works, let me show you some easy tricks to incorporate this into your development workflow." | |
// Fill in these with your desired field details. | |
$entity_type = ''; | |
$field_name = 'field_'; | |
$bundle_name = ''; | |
$info_config = field_info_field($field_name); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file will demonstrate a method to export fields to code. | |
* You can use this to easily create fields using the UI, export to code | |
* and then use in a custom module. Upon installation of the module | |
* your fields and instances will already be set up. | |
*/ | |
// Create the fields you want using the Drupal UI. | |
// On the same site, go to example.com/devel/php |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Force cache headers on 404 pages and prevent WordPress from handling 404s. | |
* | |
* @param bool $preempt determines who handles 404s. | |
* @param obj $wp_query global query object. | |
*/ | |
function change_404_headers( $preempt, $wp_query ) { | |
if ( ! is_admin() && ! is_robots() && count( $wp_query->posts ) < 1 ) { | |
header( 'Cache-Control: max-age=30000, must-revalidate' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if( | |
strpos( $_SERVER['HTTP_REFERER'], 'wp-admin' ) === false && | |
strpos( $_SERVER['REQUEST_URI'], 'admin-ajax.php' ) !== false | |
) { | |
header( 'Cache-Control: max-age=30000, must-revalidate' ); | |
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', strtotime( '+5000 minutes' ) ) . ' GMT' ); | |
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', strtotime( '-5000 minutes' ) ) . ' GMT' ); | |
header( $_SERVER["SERVER_PROTOCOL"]." 404 Not Found" ); | |
die; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Crawl a site's public urls to produce a csv list of urls and response codes | |
# This could be reduced into a single command, but I find it helpful to have a list of all urls. | |
# overview: crawl the site to add one url per line in a text file. | |
# NOTE: this must run and complete first. | |
# wget mirror's the site (including static files) | |
# grep files the line with the url on it. | |
# awk grabs the 3rd item (separated by spaces) and writes to urls.txt | |
wget --mirror -p https://domain.com/ 2>&1 | grep '^--' | awk '{ print $3 }' > urls.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set multiple install paths for phpcs. | |
# This example adds configs for WordPress, Drupal, and PHP compatibility. | |
# NOTE: change `/full/path/to/` to the path to your composer directory. | |
phpcs --config-set installed_paths "/full/path/to/.composer/vendor/wp-coding-standards/wpcs/,/full/path/to/.composer/vendor/drupal/coder/,/full/path/to/composer/vendor/phpcompatibility/php-compatibility/" | |
# Solves the error: PHPCS Response ERROR: Referenced sniff "WordPress-Extra" does not exist. Run "phpcs --help" for usage information |