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 / rrmdir.php
Created September 29, 2018 11:25 — forked from liconti/rrmdir.php
PHP recursive rmdir
<?php
function rrmdir($path){
if (is_dir($path)) {
array_map( "rrmdir", glob($path . DIRECTORY_SEPARATOR . '{,.[!.]}*', GLOB_BRACE) );
@rmdir($path);
}
else {
@unlink($path);
}
}
@wp-kitten
wp-kitten / rh-get-widget-data-for-all-sidebars.php
Created August 16, 2018 04:11 — forked from kingkool68/rh-get-widget-data-for-all-sidebars.php
WordPress function to get raw widget data for all of the widgets in a given sidebar
<?php
function rh_get_widget_data_for_all_sidebars() {
global $wp_registered_sidebars;
$output = array();
foreach ( $wp_registered_sidebars as $sidebar ) {
if ( empty( $sidebar['name'] ) ) {
continue;
}
$sidebar_name = $sidebar['name'];
@wp-kitten
wp-kitten / gist:e2d2a8588b5ce772162453204674c7ce
Last active July 21, 2018 09:30
Override WooCommerce from plugin

https://www.skyverge.com/blog/override-woocommerce-template-file-within-a-plugin/

The normal WooCommerce template loader searches the following locations in order, until a match is found:

  • your theme / template path / template name
  • your theme / template name
  • default path / template name

We’re going to alter this slightly by injecting a search for the template within our own custom plugin (step 3 below), before finally defaulting to the WooCommerce core templates directory:

@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: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' );
@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');