Skip to content

Instantly share code, notes, and snippets.

View vishalkakadiya's full-sized avatar
:octocat:

Vishal Kakadiya vishalkakadiya

:octocat:
View GitHub Profile
@vishalkakadiya
vishalkakadiya / commands.txt
Created May 3, 2024 10:45
WP VIP local dev environment data sync with Elastic Search
vip dev-env exec --slug=SLUG -- wp vip-search index --setup
vip dev-env exec --slug=SLUG -- wp vip-search health validate-counts
@vishalkakadiya
vishalkakadiya / manage_columns_wp_admin.php
Last active March 16, 2024 01:08
Manage custom columns with sortable in WordPress Admin side
<?php
/*
* =================================================================================================
* Below both hooks works for custom post types.
* e.g. Suppose we have custom post-type name : Books
* @ref https://codex.wordpress.org/Plugin_API/Action_Reference/manage_$post_type_posts_custom_column
* =================================================================================================
*/
@vishalkakadiya
vishalkakadiya / functions.php
Created March 13, 2024 10:46
Add User Role based on the CPT
<?php
/**
* Registers the `news` post type.
*/
function news_cpt(): void {
$labels = [
'name' => __( 'News', 'text-domain' ),
'singular_name' => __( 'News', 'text-domain' ),
@vishalkakadiya
vishalkakadiya / reducer.jsx
Last active January 29, 2024 04:01
React Reducer with very Simple Example
import { useReducer } from 'react';
export function counterReducer(state, action) {
if (action.type === 'INCREMENT') {
return {
count: +state.count + 1
};
}
if (action.type === 'DECREMENT') {
@vishalkakadiya
vishalkakadiya / functions.php
Last active October 27, 2023 05:44
WordPress Migration: Convert HTML doms into the common Gutenberg blocks
<?php
/**
* This snippet is useful while doing migration for the WordPress.
* Basically this script will convert the HTML dom into the common Gutenberg block comments,
* so the tags like Pagragraph will be converted into the "<!-- wp:paragraph -->SOME DATA<!-- /wp:paragraph -->".
*
* This script supports paragraph, headings, list tags and many more.
*/
/**
@vishalkakadiya
vishalkakadiya / functions.php
Last active December 12, 2022 16:59
Fix sizes attribute to improve Lighthouse score for core/image and multiple core/images on the page.
<?php
/**
* Modified version of https://core.trac.wordpress.org/attachment/ticket/45985/45985-regular-images.patch patch for testing.
* Full credit goes to that patch owner.
*/
/**
* Add custom `sizes` attribute to responsive image functionality for post content images.
*
* @since Twenty Nineteen 1.0
@vishalkakadiya
vishalkakadiya / functions.php
Last active December 9, 2022 13:32
Fix sizes attribute to improve Lighthouse score for Image gallery with two images.
<?php
/**
* Modified version of https://core.trac.wordpress.org/attachment/ticket/45985/45985-regular-images.patch patch for testing.
* Full credit goes to that patch owner.
*/
/**
* Add custom `sizes` attribute to responsive image functionality for post content images.
*
* @since Twenty Nineteen 1.0
@vishalkakadiya
vishalkakadiya / functions.php
Last active December 3, 2022 07:32
FieldManager - Add custom settings page with vertical tabs.
<?php
function settings_fields() {
$children['tab'] = new Fieldmanager_Group( array(
'label' => 'ABCD', // This name must match what we registered in `fm_register_submenu_page()`
'children' => array(
'text' => new Fieldmanager_Textfield( 'Text Field' ),
'autocomplete' => new Fieldmanager_Autocomplete( 'Autocomplete', array( 'datasource' => new Fieldmanager_Datasource_Post() ) ),
'textarea' => new Fieldmanager_TextArea( 'TextArea' ),
'media' => new Fieldmanager_Media( 'Media File' ),
@vishalkakadiya
vishalkakadiya / mysql(wp)-commands.txt
Last active October 31, 2022 16:48
WordPress(or any mysql database) - Convert special characters(eg. Latin-1) to UTF-8 in mysql database
The actual step-by-step WordPress / MySQL fix…
1. Back up all your stuff first (likely using phpMyAdmin / CPANEL)
Before doing any of the following it strongly encouraged to back up all your data and files. Just to be safe. At the very least, your full database and the WordPress config file: wp-config.php
2. Note the settings that your WordPress is currently using (from wp-config.php)
Specifically, your MySQL database configuration, including DB_NAME, DB_USER, DB_PASSWORD, and also DB_CHARSET and DB_COLLATE
// ** MySQL settings - You can get this info from your web host ** //
@vishalkakadiya
vishalkakadiya / functions.php
Created September 24, 2021 15:22
WordPress - Add custom filers on backend admin post listing
/**
* Add custom filters.
*/
function custom_filters() {
$post_type = filter_input( INPUT_GET, 'post_type', FILTER_SANITIZE_STRING );
// Only add filter to post type you want.
if ( 'POST_TYPE_NAME' === $post_type ) {