Instantly share code, notes, and snippets.

View debug-wordpress.md

Enable Debugging in WordPress

To enable debugging in WordPress, you will need to add the following to your site's wp-config.php file:

define( 'WP_DEBUG', true );

if ( WP_DEBUG ) {
	@error_reporting( E_ALL );
	@ini_set( 'log_errors', true );
View debug-wordpress.md

Enable Debugging in WordPress

To enable debugging in WordPress, you will need to add the following to your site's wp-config.php file:

define( 'WP_DEBUG', true );

if ( WP_DEBUG ) {
	@error_reporting( E_ALL );
	@ini_set( 'log_errors', true );
View plugin.php
<?php
/**
* Remove state field from woocommerce checkout form.
*
* @see https://github.com/woocommerce/woocommerce/blob/3.1.2/includes/class-wc-countries.php#L629
*
* @param array $fields Array of default address fields.
*/
function jeherve_remove_state_field( $fields ) {
unset( $fields['state'] );
View plugin.php
<?php
/**
* Plugin Name: Add a list of Jetpack related posts to the bottom of each post in the Rest API Posts Embeds shortcode.
* Plugin URI: http://jeremy.hu/
* Description: Add a list of Jetpack related posts to the bottom of each post in the Rest API Posts Embeds shortcode.
* Author: Jeremy Herve
* Version: 1.0.0
* Author URI: https://jeremy.hu
* License: GPL2+
*/
View stats.md

The kStats Reloaded plugin hasn't been updated in the past 7 years, and offers few ways to exclude visits. It will consequently count a lot of bots, crawlers, and search engines.

WP Statistics is updated a lot more often, but since it relies on data included in the plugin itself, you can expect some bots to be included in the stats. You can find out more in the plugin's FAQ (see I'm using another statistics plugin/service and get different numbers for them, why?). It may also count your own visits.

Jetpack Stats, on the other hand, will exclude visits from logged in users by default. It also relies on the WordPress.com cloud to filter and exclude bots and other crawlers, and all calculatations happen on our servers so it won't affect your site's performance.

View jp_restrict_rp.php
function jetpackme_related_posts_date_restricted( $date_range, $post_id ) {
// We can change this based on $post_id too but let's just filter everything
$date_range = array(
'from' => strtotime( '1 January 2013' ),
'to' => time(),
);
return $date_range;
}
add_filter( 'jetpack_relatedposts_filter_date_range', 'jetpackme_related_posts_date_restricted', 10, 2 );
View jeherve-force-deactivate-protect.php
<?php
/**
* Plugin Name: Force Deactivate Jetpack's Protect Module.
* Plugin URI: https://jetpack.com/support/security-features/#unblock
* Description: If you have lost access to your site's dashboard, you can use this plugin to deactivate the Protect module.
* Author: Automattic
* Version: 1.0.0
* Author URI: http://jetpack.com
* License: GPL2+
*
View install.sh
#!/bin/sh
echo Install all AppStore Apps at first!
# If you are looking into a solution to automate AppStore installs,
# check mas https://github.com/argon/mas
# I installed XCode, Simplenote, Clocks, Stuffit Expander, Cloudapp, Forklift.
read -p "Press any key to continue... " -n1 -s
echo '\n'
View output.bash
$ curl -I https://i0.wp.com/jeremy.hu/wp-content/uploads/watson-5818.jpg
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 07 Jun 2016 16:42:27 GMT
Content-Type: image/jpeg
Content-Length: 94394
Connection: keep-alive
Last-Modified: Tue, 07 Jun 2016 16:37:17 GMT
Expires: Fri, 08 Jun 2018 04:37:17 GMT
Cache-Control: public, max-age=63115200
View plugin.php
<?php
/**
* Create an ordered list of popular posts, using Jetpack's Site Stats.
*
* @see wordpress.org/support/topic/2883315
*/
function jeherve_new_top_posts() {
if ( ! function_exists( 'stats_get_csv' ) ) {