Skip to content

Instantly share code, notes, and snippets.

View milindmore22's full-sized avatar
🏠
Working from home

Milind More milindmore22

🏠
Working from home
View GitHub Profile
<?php
/**
* AMP Wordfence Compat plugin bootstrap.
*
* @package Google\AMP_Wordfence_Compat
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2020 Google Inc.
*
* @wordpress-plugin
@milindmore22
milindmore22 / amp-infinite-scroll-themes.php
Created September 1, 2021 16:57
Code Snippets for AMP infinite Scroll plugin
<?php
/**
* Install the AMP Infinite Scroll Plugin and use the code snippet for your active theme.
* @link https://github.com/milindmore22/amp-infinite-scroll
*/
/**
* Twenty Twenty One
*/
@milindmore22
milindmore22 / amp-legacy-theme-css.php
Created August 19, 2021 10:01
Add CSS to AMP Legacy theme.
<?php
/**
* Plugin Name: AMP Legacy Theme CSS
* Plugin URI: https://amp-wp.org
* Description: Plugin add CSS to AMP Legacy theme.
* Version: 1
* Requires at least: 5.6
* Requires PHP: 7.4
* Author: AMP Support
* Author URI: https://wpindia.co.in/
<?php
/**
* Web Stories amp-onerror Workaround plugin bootstrap.
*
* @package Google\Web_Stories_AMP_OnError_Workaround
* @author Pascal Birchler, Google
* @license GPL-2.0-or-later
* @copyright 2021 Google Inc.
*
* @wordpress-plugin
@milindmore22
milindmore22 / amp-server-side-redirect.php
Last active December 7, 2020 19:44
AMP server side redirect
<?php
add_action(
'wp',
function() {
add_action( 'amp_mobile_client_side_redirection', '__return_false' );
if ( ! isset( $_GET['noamp'] ) && wp_is_mobile() && function_exists( 'is_amp_endpoint' ) && ! is_amp_endpoint() && function_exists( 'amp_is_available' ) && amp_is_available() ) {
wp_safe_redirect( esc_url( add_query_arg( 'amp', '1', get_permalink() ) ), 302 );
}
@milindmore22
milindmore22 / amp-local-storage-demo.php
Last active October 26, 2020 15:30
Local Storage Demo - on AMP and Non-AMP pages
<?php
/**
* AMP Local Storage.
*
* @package AMP_Local_Storage_Test
* @author Milind, rtCamp
* @license GPL-2.0-or-later
* @copyright 2020 rtCamp pvt. ltd.
*
* @wordpress-plugin
@milindmore22
milindmore22 / amp-script-local-storage.php
Last active October 23, 2020 09:10
Using AMP Script component for local storage.
<?php
/**
* Local Storage Demo
*
* @requires AMP WordPress Plugin.
*/
add_action(
'wp_head',
function() {
@milindmore22
milindmore22 / on-load-download.js
Created July 21, 2020 10:21
Test On Load Download
(function() {
window.addEventListener('load', () => {
const download_button = document.querySelectorAll( '.download-rt-whitepaper a' );
download_button[0].click();
});
})();
@milindmore22
milindmore22 / post-type-count.sql
Last active November 14, 2019 14:29
SQL Query to get post count by post types
SELECT count(*), post_type FROM `wp_posts` WHERE post_type IN( SELECT DISTINCT post_type wp_posts ) GROUP BY post_type ORDER BY `count(*)` DESC
@milindmore22
milindmore22 / optimizing-default-wordpress-rest-api-user-endpoint-redundant-db-calls-check-permissions.php
Created January 27, 2018 12:06
Optimizing default WordPress REST API user endpoint for redundant DB calls to check permissions.
<?php
/**
* Rest endpoint filter to change permission callback of item_permission_check.
*
* @param type $endpoints return endpoints.
*/
public function replace_rest_endpoints_permission_callback( $endpoints ) {
if ( isset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] ) ) {