Skip to content

Instantly share code, notes, and snippets.

View test-vip-private-files-unpublished-files.php
<?php
<?php
namespace Automattic\VIP\Files\Acl;
use WP_Error;
class VIP_Files_Acl_Unpublished_Files_Test extends \WP_UnitTestCase {
const TEST_IMAGE_PATH = VIP_GO_MUPLUGINS_TESTS__DIR__ . '/fixtures/image.jpg';
@mjangda
mjangda / beta.php
Last active Nov 17, 2020
Client-side, randomized, percentage-based segmentation using the WordPress Cache Segmentation API. Only supports 1 experiment and 1 control group.
View beta.php
<?php
require_once( WPMU_PLUGIN_DIR . '/cache/class-vary-cache.php' );
use Automattic\VIP\Cache\Vary_Cache;
Vary_Cache::register_group( 'beta' );
add_action( 'wp_head', function() {
// TODO: if possible, load this directly very early in the header.php (instead of wp_head)
View html-map.php
<?php
add_action( 'init', function() {
$html_map = [
'howdy/world' => 'howdy',
];
$current_path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
if ( in_array( $current_path, array_keys( $html_map ), true ) ) {
$filename = $html_map[ $current_path ];
View load-wp-filesystem-vip.php
<?php
/**
* With the filters below, our override should load automatically when `WP_Filesystem()` is called.
*
* If we don't want to explicitly initialize it everywhere:
*
* $api_client = Automattic\VIP\Files\new_api_client();
* WP_Filesystem( [
* new Automattic\VIP\Files\WP_Filesystem_VIP_Uploads( $api_client ),
@mjangda
mjangda / ngrok-and-jetpack.md
Last active Jan 25, 2021
How to connect ngrok to your local WordPress environment (props @DanReyLop)
View ngrok-and-jetpack.md

How to develop with Jetpack locally with ngrok

To connect Jetpack in your local installation, you'll need a way for WP.com servers to reach your server. That can be done in a number of different ways:

  • You can open your router's ports and use your public IP
  • You can use some kind of Dynamic DNS provider.

But these options fall short of ngrok, which is a "localhost tunnel". It basically allows the Internet to hit a local port on your machine without worrying about ports or IPs.

As long as ngrok is running, Jetpack / WP.com will be able to communicate with your local site. This will allow remote modules like Site Search and Manage to work.

View amphtml-rest-response.php
<?php
add_filter( 'rest_prepare_post', 'amp_add_amphtml_link_to_rest_response', 10, 2 );
function amp_add_link_to_rest_response( $response, $post ) {
if ( ! post_supports_amp( $post ) ) {
return $response;
}
$response->add_link( 'amphtml', amp_get_permalink( $post->ID ) );
@mjangda
mjangda / msm-sitemap-fixer.php
Created Jan 14, 2017
Fixer command for fixing broken sitemap dates
View msm-sitemap-fixer.php
<?php
class MSM_Sitemap_Fixers_Command extends WP_CLI_Command {
/**
* Regenerate sitemaps with broken dates
*
* @subcommand fix-msm-sitemap-dates
*/
function fix_msm_sitemap_dates( $args, $assoc_args ) {
$defaults = array();
View gist:788bb4654dabbadb030d
diff --git a/desktop/env.js b/desktop/env.js
index 68fac96..1dbc45a 100644
--- a/desktop/env.js
+++ b/desktop/env.js
@@ -86,7 +86,8 @@ debug( '========================================================================
global.desktop = {
config: config,
settings: Settings,
- editorContextMenu: EditorContextMenu,
- generalContextMenu: GeneralContextMenu
@mjangda
mjangda / emoji-one.php
Created Nov 24, 2015
Use assets from Emoji One instead of Twitter for your WordPress site.
View emoji-one.php
<?php
/**
* Plugin Name: Emoji One
* Description: Use assets from Emoji One (emojione.com) when displaying emoji.
* Version: 0.1
*/
add_filter( 'emoji_url', '//cdn.jsdelivr.net/emojione/assets/png/' );
View usage.php
<?php
vip_register_async_script( 'twitter', 'https://platform.twitter.com/widgets.js' );