Skip to content

Instantly share code, notes, and snippets.

View mjangda's full-sized avatar

Mohammad Jangda mjangda

View GitHub Profile
<?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 November 17, 2020 02:47
Client-side, randomized, percentage-based segmentation using the WordPress Cache Segmentation API. Only supports 1 experiment and 1 control group.
<?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)
<?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 ];
<?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 February 7, 2023 07:57
How to connect ngrok to your local WordPress environment (props @DanReyLop)

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.

<?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 January 14, 2017 00:09
Fixer command for fixing broken sitemap dates
<?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();
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 November 24, 2015 17:36
Use assets from Emoji One instead of Twitter for your WordPress site.
<?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/' );
<?php
vip_register_async_script( 'twitter', 'https://platform.twitter.com/widgets.js' );