Skip to content

Instantly share code, notes, and snippets.

View jeherve's full-sized avatar
🚀
👨‍🏭

Jeremy Herve jeherve

🚀
👨‍🏭
View GitHub Profile
<?php
/**
* Display a Podcast player anywhere.
* Pulled from extensions/blocks/podcast-player/podcast-player.php
* @see https://github.com/Automattic/jetpack/blob/b88b1edbdce4d8576ce9be02a9093702ae112fed/extensions/blocks/podcast-player/podcast-player.php
* @see https://wordpress.org/support/topic/embedding-the-podcast-player-with-code/
*/
function jeherve_display_podcast() {
// bail early if Jetpack isn't installed.
if ( ! class_exists( 'Jetpack' ) ) {
@jeherve
jeherve / plugin.php
Last active July 3, 2019 09:15
[Jetpack] Deactivate Twitter Cards and / or Open Graph Meta tags.
<?php
/*
* Plugin Name: Disable Jetpack Open Graph tags and Twitter Cards
* Plugin URI: http://wordpress.org/extend/plugins/jetpack/
* Description: Disables Jetpack Open Graph tags
* Author: Jeremy Herve
* Version: 1.0
* Author URI: http://jeremyherve.com
* License: GPL2+
*/

You could use the jetpack_set_available_extensions filter (reference) to avoid registering some of Jetpack's blocks in the editor. When you do so, they won't appear in the block editor.

That said, it won't change the size of the CSS file used to style those blocks in the editor; that file concatenates CSS for all blocks, regardless of what's actually available in the editor. It should not be too much of an issue though:

  1. That file is minified and rather small (63.8 KB right now - #).
  2. The file is only loaded in the editor. It is not loaded on the frontend. On your site, we only load CSS for the blocks that are on the page, and need CSS, and in those cases we use separate CSS files like the ones you can find in this directory.

I hope this clarifies things a bit.

@jeherve
jeherve / debug-wordpress.md
Created September 11, 2018 10:39
A test Gist, with 2 files

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 );
@jeherve
jeherve / jp_restrict_rp.php
Last active February 10, 2018 10:50 — forked from richardmtl/jp_restrict_rp.php
Restrict Jetpack's Related Posts to a specific time-frame
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 );
<?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+
*/
@jeherve
jeherve / stats.md
Created February 21, 2017 17:37
Differences between different Stats plugins

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.

@jeherve
jeherve / plugin.php
Last active February 7, 2017 02:00
[Jetpack] Add tracking parameters to a post URL, and then have that tracked URL shortened by goo.gl, and then use that short URL in sharing buttons
<?php
/**
* Overwrite the links used in Jetpack's Sharing module.
*
* @see https://wordpress.org/support/topic/how-to-use-utm-codes-with-jetpack-sharing
*
* @param string $url
* @param int $post_id
* @param int $sharing_id
* @filter sharing_permalink
@jeherve
jeherve / jp-rm-jpmenu.php
Last active November 27, 2016 10:44
[Jetpack] How to hide the Jetpack menu to all non-admins https://github.com/jeherve/jetpack-addons/archive/jetpack-admins.zip
<?php
/*
* Plugin Name: Jetpack Only for Admins
* Plugin URI: http://wordpress.org/extend/plugins/
* Description: Hides the Jetpack menu for all non-admins
* Author: Jeremy Herve
* Version: 1.1
* Author URI: http://jeremyherve.com
* License: GPL2+
* Text Domain: jetpack
<?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+
*