Skip to content

Instantly share code, notes, and snippets.

View dashaluna's full-sized avatar

Dasha Luna dashaluna

View GitHub Profile
@maheshwaghmare
maheshwaghmare / debug-http-request.php
Last active March 26, 2024 21:15
Debug the HTTP requests in WordPress wp_remote_post() or wp_remote_get() with the help of `http_api_debug` hook.
<?php
/**
* Debug HTTP requests in WordPress
*
* Fires after an HTTP API response is received and before the response is returned.
*
* Output in `wp-content\debug.log` file:
*
* [24-Apr-2019 06:50:16 UTC] ------------------------------
* [24-Apr-2019 06:50:16 UTC] https://downloads.wordpress.org/plugin/elementor.2.5.14.zip
@roborourke
roborourke / wp-react-dev.php
Last active May 17, 2020 13:50
Get the development version of react in WordPress without needing a dev version of WP
<?php
/**
* Enable dev mode vendor packages.
*/
if ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ) {
return;
}
add_action( 'init', function () {
@gaearon
gaearon / modern_js.md
Last active April 18, 2024 15:01
Modern JavaScript in React Documentation

If you haven’t worked with JavaScript in the last few years, these three points should give you enough knowledge to feel comfortable reading the React documentation:

  • We define variables with let and const statements. For the purposes of the React documentation, you can consider them equivalent to var.
  • We use the class keyword to define JavaScript classes. There are two things worth remembering about them. Firstly, unlike with objects, you don't need to put commas between class method definitions. Secondly, unlike many other languages with classes, in JavaScript the value of this in a method [depends on how it is called](https://developer.mozilla.org/en-US/docs/Web/Jav
@veekram
veekram / read-write-file.js
Created June 1, 2018 11:12
Read Write to file with javascript
/// write to file
var txtFile = "c:/test.txt";
var file = new File(txtFile);
var str = "My string of text";
file.open("w"); // open file with write access
file.writeln("First line of text");
file.writeln("Second line of text " + str);
file.write(str);
file.close();
@andreilupu
andreilupu / How to send a POST request from WordPress admin Dashboard – JS
Last active April 6, 2018 09:47
How to send a POST request from WordPress admin Dashboard
(function(){
var request = wp.ajax.post('custom_action', {param1: 'uppercase this string pls'});
// on success
request.done( function ( res ) {
console.log( res );
});
// on fail
@drodsou
drodsou / writeFileSyncRecursive.js
Last active April 11, 2024 16:06
Like writeFileSync but creating all folder paths if not exist
// -- updated in 2020/04/19 covering the issues in the comments to this point
// -- remember you also have things like `ensureDirSync` from https://github.com/jprichardson/node-fs-extra/blob/master/docs/ensureDir-sync.md
const fs = require('fs')
function writeFileSyncRecursive(filename, content, charset) {
// -- normalize path separator to '/' instead of path.sep,
// -- as / works in node for Windows as well, and mixed \\ and / can appear in the path
let filepath = filename.replace(/\\/g,'/');
// -- preparation to allow absolute paths as well
@kirilkirkov
kirilkirkov / gist:b13baec4b5142a527399693f8829547d
Created June 21, 2016 07:20
Difference between png-Interlaced, jpg-progressive AND png-non-Interlaced, jpg-baseline
Interlaced image loads an early degraded version of the whole image as soon as possible and then progressively renders the image to clear state.
Non-interlaced image will load up in tiles showing clear image in each tile as it progresses to load in the image.
For .jpg the interlaced = progressive and not interlaced = baseline.
@claudiosanches
claudiosanches / custom-my-account-endpoint.php
Last active November 6, 2023 20:10
Example of custom My Account endpoint.
<?php
class My_Custom_My_Account_Endpoint {
/**
* Custom endpoint name.
*
* @var string
*/
public static $endpoint = 'my-custom-endpoint';
INITIALISATION
==============
load wp-config.php
set up default constants
load wp-content/advanced-cache.php if it exists
load wp-content/db.php if it exists
connect to mysql, select db
load object cache (object-cache.php if it exists, or wp-include/cache.php if not)
load wp-content/sunrise.php if it exists (multisite only)
@caseywatts
caseywatts / bookmarkleting.md
Last active April 1, 2024 19:57
Making Bookmarklets

This is one chapter of my "Chrome Extension Workshops" tutorial, see the rest here: https://gist.github.com/caseywatts/8eec8ff974dee9f3b247

Unrelated update: my book is out! Debugging Your Brain is an applied psychology / self-help book

Making Bookmarklets

I'm feeling very clever. I've got this sweet line of javascript that replaces "cloud" with "butt". My mom would LOVE this, but she doesn't computer very well. I'm afraid to show her the Developer Console and have her type/paste this in. But she IS pretty good at bookmarks, she knows just how to click those!

A bookmark normally takes you to a new web page. A bookmarklet is a bookmark that runs javascript on the current page instead of taking you to a new page. To declare that it is a bookmarklet, the "location" it points to starts with javascript:.