Skip to content

Instantly share code, notes, and snippets.

View mehrshaddarzi's full-sized avatar

Mehrshad Darzi mehrshaddarzi

View GitHub Profile
@ozknozsrt
ozknozsrt / app.js
Last active January 16, 2024 16:48 — forked from itzikbenh/app.js
WordPress API - how to fetch and paginate posts with Vue.js
import Vue from 'vue';
import posts from './components/posts.vue';
window.axios = require('axios');
window.Vue = Vue;
Vue.component('posts', posts);
const app = new Vue({
el: '#app',
@matzeeable
matzeeable / is_rest.php
Last active February 22, 2024 20:20
Checks if the current request is a WP REST API request.
<?php
if ( !function_exists( 'is_rest' ) ) {
/**
* Checks if the current request is a WP REST API request.
*
* Case #1: After WP_REST_Request initialisation
* Case #2: Support "plain" permalink settings and check if `rest_route` starts with `/`
* Case #3: It can happen that WP_Rewrite is not yet initialized,
* so do this (wp-settings.php)
@yayMark
yayMark / add_bootstrap_control_class.php
Created September 5, 2018 05:48
Apply Bootstrap 4 custom checkboxes and radio buttons to Gravity Fields generated forms
<?php
// Apply Bootstrap 4 custom checkboxes and radio buttons to Gravity Fields generated forms
// Derived from https://jayhoffmann.com/using-gravity-forms-bootstrap-styles/
add_filter( 'gform_field_container', 'add_bootstrap_control_class', 10, 6 );
function add_bootstrap_control_class( $field_container, $field, $form, $css_class, $style, $field_content ) {
$id = $field->id;
$field_id = is_admin() || empty( $form ) ? "field_{$id}" : 'field_' . $form['id'] . "_$id";
<?php
// Init
// -----------------------------------------------------------------------
define('DOING_AJAX', true);
define('SHORTINIT', true);
// WP Load
// -----------------------------------------------------------------------
require('wp-load.php');
/**
* Block dependencies
*/
import icon from './icon';
import SelectTeam from '../select-team';
//import './style.scss';
import './editor.scss';
/**
* Internal block libraries
@splozm
splozm / functions.php
Last active July 12, 2018 17:49 — forked from kloon/functions.php
WooCommerce Dropdown Product Quantity, including selected quantity in cart. Fully compatible with Min/Max quantities extension
<?php
// Place the following code in your theme's functions.php file
// override the quantity input with a dropdown
function woocommerce_quantity_input($data = null) {
global $product;
$defaults = array(
'input_name' => 'quantity',
'input_value' => '1',
@kellenmace
kellenmace / class-download-remote-image.php
Last active October 13, 2022 13:24
Download and Insert a Remote Image File into the WordPress Media Library
<?php
/**
* This class handles downloading a remote image file and inserting it
* into the WP Media Library.
*
* Usage:
* $download_remote_image = new KM_Download_Remote_Image( $url );
* $attachment_id = $download_remote_image->download();
*
@aldo-jr
aldo-jr / create-react-app.sh
Created January 26, 2018 19:32
React (create-react-app) Starter Pack with bootstrap (jquery & popper.js), axios, router, redux (react-redux, redux-thunk) and redux-form
#!/usr/bin/env bash
sudo npm install -g create-react-app
create-react-app my-app
cd my-app
npm i -s axios bootstrap jquery popper.js react-redux react-router-dom redux redux-form redux-thunk
npm run eject
@glueckpress
glueckpress / wp_rocket__wp_get_attachment_image__lazyload.php
Last active January 6, 2020 08:18
[WordPress][WP Rocket] [deprecated] Wrapper function: Applies WP Rocket’s LazyLoad to wp_get_attachment_image()
<?php
/**
* Wrapper function: Applies WP Rocket’s LazyLoad to wp_get_attachment_image()
*
* @link https://developer.wordpress.org/reference/functions/wp_get_attachment_image/
* @link https://github.com/wp-media/wp-rocket/blob/v2.10.9/inc/front/lazyload.php#L24-L47
*
* @param int $attachment_id (Required) Image attachment ID.
* @param string|array $size (Optional) Image size. Accepts any
* valid image size, or an array of width
@neilrackett
neilrackett / php-to-moment.js
Last active December 13, 2022 07:39
Convert PHP date string to Moment.js format
function phpToMoment(str) {
let replacements = {
'd' : 'DD',
'D' : 'ddd',
'j' : 'D',
'l' : 'dddd',
'N' : 'E',
'S' : 'o',
'w' : 'e',