Skip to content

Instantly share code, notes, and snippets.

Mohammad Jangda mjangda

Block or report user

Report or block mjangda

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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 Sep 26, 2019
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' );
View wp-android-checkstyle.diff
diff --git a/tools/checkstyle.sh b/tools/checkstyle.sh
index 8f536e2..e206727 100755
--- a/tools/checkstyle.sh
+++ b/tools/checkstyle.sh
@@ -1,7 +1,7 @@
#!/bin/sh
-if [ x"$1" == x ]; then
+if [ -z "$1" ]; then
checkstyle -c cq-configs/checkstyle/checkstyle.xml -r src/
@mjangda
mjangda / wp-error-merge.php
Created Jun 26, 2013
Merge multiple WP_Error objects together.
View wp-error-merge.php
<?php
function wpcom_wp_error_merge() {
$wp_error_merged = new WP_Error();
$wp_errors = func_get_args();
foreach ( $wp_errors as $wp_error ) {
if ( ! is_wp_error( $wp_error ) )
continue;
foreach ( $wp_error as $key => $errors ) {
You can’t perform that action at this time.