Skip to content

Instantly share code, notes, and snippets.

View wp-kitten's full-sized avatar

Costin wp-kitten

View GitHub Profile
@wp-kitten
wp-kitten / gist:deee20bd58a8e94fcc6746d190b5d251
Created May 11, 2018 00:03
[AWS] [S3] [LAMBDA] Sign Url
'use strict';
const AWS = require('aws-sdk');
const s3 = new AWS.S3({signatureVersion: 'v4'});
exports.handler = (event, context, callback) => {
const bucket = process.env['s3_bucket'];
if (!bucket) {
callback(new Error(`S3 bucket not set`));
}
<?php
if ( ! function_exists( 'el_crypto_hmacSHA1' ) ) {
/**
* Calculate the HMAC SHA1 hash of a string.
*
* @param string $key The key to hash against
* @param string $data The data to hash
* @param int $blockSize Optional blocksize
* @return string HMAC SHA1
@wp-kitten
wp-kitten / git_cheat-sheet.md
Created March 8, 2018 07:45 — forked from davfre/git_cheat-sheet.md
git commandline cheat-sheet
@wp-kitten
wp-kitten / gist:d6b9024e6a23f35fdeaf6ce9508a269f
Created February 28, 2017 20:34
WooCommerce - display product variations as list after Product Content
/* Tested with Catalog Mode = true */
/*
* Remove the following tabs from the Product page:
* - Description
* - Reviews
* - Additional Information
*/
remove_filter( 'woocommerce_product_tabs', 'woocommerce_default_product_tabs' );
@wp-kitten
wp-kitten / gist:c647cda5ddacc5b27f1db20a3a476ae2
Created February 28, 2017 20:28
Add WordPress Internal Link Popup
/*
* Load the scripts needed so we can display the Internal Link Popup
*/
add_action( 'admin_enqueue_scripts', 'loadScripts', 800 );
function loadScripts( $hook ) {
if( is_admin()) {
wp_enqueue_script( 'wplink' );
wp_enqueue_style( 'editor-buttons' );
}
}
@wp-kitten
wp-kitten / gist:912d239320fe93d3bdee2a6fa0c781d2
Created June 10, 2016 14:15
[WordPress] Cleanup wp head tag
// removes <link rel="EditURI" type="application/rsd xml" title="RSD" href="http://bhoover.com/wp/xmlrpc.php?rsd
remove_action( 'wp_head', 'rsd_link' );
// removes <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://bhoover.com/wp/wp-includes/wlwmanifest.xml">
remove_action( 'wp_head', 'wlwmanifest_link' );
// removes Ex: <meta name="generator" content="WordPress 4.5">
remove_action( 'wp_head', 'wp_generator' );
// removes Ex: <link rel='shortlink' href="http://example.com/?p=42">
remove_action( 'wp_head', 'wp_shortlink_wp_head');
// remove adjacent post links
remove_action('wp_head', 'index_rel_link');
@wp-kitten
wp-kitten / gist:90f686e60993f5f6a2381aae0d7b6d21
Created June 10, 2016 14:14
[WordPress] Redirect certain pages to 404
/*
* WP creates a lot of pages we don’t really need. First in the list of the unwanted is the attachment page.
* Each image you upload gets its very own personal web page.
* Also the archive by Author if you are a sole blogger is totally unneeded.
* travel diaries maybe).
*/
function wpkTemplateRedirect ()
{
global $wp_query, $post;
@wp-kitten
wp-kitten / gist:302ce4bc8e6a9b6f9155ebcdb4d24bc1
Created May 27, 2016 16:22
Add custom link to menu to logged in users only
// Filter wp_nav_menu() to add additional links
function kallyasChildExtendMenuNav($items, $args = null)
{
// Make sure the arguments are passed correctly
if(! empty($args) && is_object($args))
{
// Make sure the WooCommerce plugin exists and is activated
if( class_exists('WooCommerce') )
{
// Make sure we're updating the correct menu: top nav
@wp-kitten
wp-kitten / gist:cbb3b0572a640b602fc5e3975f74009d
Created April 25, 2016 15:30
Get file from remote password protected ftp url
// define some variables
$local_file = 'local.zip';
$server_file = 'server.zip';
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
@wp-kitten
wp-kitten / gist:978d730b27958b82fda62771d04153fd
Created April 16, 2016 10:34
[WordPress] Create new admin account
function wpkAddAdminAccount()
{
$login = 'username';
$passw = 'password';
$email = 'email';
if ( !username_exists( $login ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $login, $passw, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );