Skip to content

Instantly share code, notes, and snippets.

@arelthia
arelthia / git-cheatsheet.md
Last active April 30, 2023 20:53
Git Commands

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)

  • clone: Clone a repository into a new directory
  • init: Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)

  • add: Add file contents to the index
@arelthia
arelthia / apis.md
Last active January 7, 2023 01:46
APIs and dummy data generators
@arelthia
arelthia / grid.js
Created April 23, 2022 23:39
Wordle Grid
let grid = document.querySelector("#game");
// the number of guesses
let guessesAllowed = 4;
// the length of the word
let wordLength = 3;
// generate 3 rows
let fragement = document.createDocumentFragment();
@arelthia
arelthia / admin.php
Last active July 22, 2018 22:25
Change order of custom post type on admin edit.php screen
/*
* Change order of custom post type on admin edit.php screen from name to date
* https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
*/
function ptc_admin_order( $wp_query ) {
if (is_admin()) {
$post_type = $wp_query->query['post_type'];
if ( $post_type == 'ptc_clients' || $post_type == 'ptc_proposals' ) {
@arelthia
arelthia / gist:23d1afc4d1445d23e2d2f3b53c96af49
Created August 11, 2017 17:43
Speed Up Your WordPress Site By Disabling Smileys, Emojis and Emoticons
/**
* Disable the emoji's
*/
function disable_wordpress_emojis() {
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action('admin_print_styles', 'print_emoji_styles');
remove_filter('the_content_feed', 'wp_staticize_emoji');
remove_filter('comment_text_rss', 'wp_staticize_emoji');
<?php
function my_customize_rest_cors() {
remove_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );
add_filter( 'rest_pre_serve_request', function( $value ) {
header( 'Access-Control-Allow-Origin: *' );
header( 'Access-Control-Allow-Methods: GET' );
header( 'Access-Control-Allow-Credentials: true' );
header( 'Access-Control-Expose-Headers: Link', false );
@arelthia
arelthia / functions.php
Last active June 23, 2017 15:49
Force ssl on one page and force http on specific pages.
add_action( 'template_redirect', 'pintop_ssl_redirect', 1 );
function pintop_ssl_redirect() {
//page that should be ssl
if ( is_page( 1264 ) && ! is_ssl() ) {
if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI']), 301 );
exit();
} else {
wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301 );
@arelthia
arelthia / Add class to menu
Last active June 9, 2017 18:34
Add custom classes to WordPress menus
// Add extra classes for the first and last items in all WordPress menus
add_filter( 'wp_nav_menu_objects', function ( $items ) {
if ( ! empty( $items ) ) {
$items[1]->classes[] = 'menu-item-first';
$items[ count( $items ) ]->classes[] = 'menu-item-last';
}
return $items;
} );
@arelthia
arelthia / get-post-type.js
Created December 31, 2016 05:06
Get WordPress CPT from front end
(function( $ ) {
'use strict';
var attrs, attr, postType;
postType = null;
$(function() {
// Look to see what type of post type we're working with
attrs = $( 'body' ).attr( 'class' ).split( ' ' );
@arelthia
arelthia / gfs3.php
Created December 28, 2016 19:43 — forked from renventura/gfs3.txt
Send Gravity Forms file uploads to Amazon S3
<?php
/**
* Send Gravity Forms file uploads to Amazon S3
* @author Ren Ventura <EnageWP.com>
* @link http://www.engagewp.com/send-gravity-forms-file-uploads-to-amazon-s3/
*/
//* Include the required library
include_once 'inc/S3.php';