Skip to content

Instantly share code, notes, and snippets.

@lucymtc
lucymtc / my_add_action_links.php
Last active June 29, 2017 21:14
Add a settings link to plugins overview page - WordPress
@lucymtc
lucymtc / ejemplos-hooks-wpvalencia.php
Created April 13, 2016 22:42
Ejemplos meetup WPValencia Introducción a hooks
<?php
/**
* Plugin Name: Ejemplos WPValencia meetup
* Plugin URI: http://wordpress.org/plugins
* Description: Ejemplos para presentacion Introducción a los hooks.
* Version: 0.0.1
* Author: Lucy Tomas
* Author URI: http://lucytomas.com
* License: GPLv2+
*/
@lucymtc
lucymtc / sublime-text-setup.txt
Last active July 9, 2018 10:23
My Sublime Text 3 Setup
##### Theme ####
Cobalt2
https://packagecontrol.io/packages/Theme%20-%20Cobalt2
##### Packages #####
Package Controll:
https://packagecontrol.io/installation
Sublime Code Sniffer - phpcs and phpmd
@lucymtc
lucymtc / media-modal-required-fields.js
Last active July 27, 2017 11:13
Make media custom fields required disabling the Insert Media button while fields are empty. Example of caption and a credit custom field.
/**
* Disables the Insert Media button while the required fields are empty.
*/
(function(){
var SelectionEventBus = _.extend({
currentSelection: {},
invalidSelection: {},
}, Backbone.Events);
var updateInvalid = function( collection ) {
@lucymtc
lucymtc / get-aspect-ratio.php
Last active June 29, 2017 21:12
Get aspect ratio for an image
<?php
function gcd( $a, $b ){
return ($a % $b) ? gcd($b,$a % $b) : $b;
}
function ratio( $x, $y ){
$gcd = gcd($x, $y);
return ($x/$gcd).':'.($y/$gcd);
}
/**
@lucymtc
lucymtc / resize-image-maintain-ratio.js
Created April 11, 2017 21:53
Get resized width and height of an image maintaining its aspect ratio
var originalWidth = 2205;
var originalHeight = 3500;
var maxSize = 160;
/** Thumbnails max width and height. */
var ratio = Math.min( maxSize / originalWidth, maxSize / originalHeight );
var thumbWidth = originalWidth * ratio;
var thumbHeight = originalHeight * ratio;
@lucymtc
lucymtc / ssl_on_vvv
Last active November 2, 2017 10:46
Set up SSL on VVV (Mac)
# From https://kellenmace.com/set-up-ssl-locally-on-vvv-vagrant-wordpress-site/
cd ~/vagrant-local/config/nginx-config/sites
mkdir ssl
cd ssl
# Generate ssl key and certificate
openssl genrsa -out example.dev.key 2048
openssl req -new -x509 -key example.dev.key -out example.dev.cert -days 3650 -subj /CN=example.dev
@lucymtc
lucymtc / is_edit_screen.php
Created July 27, 2017 11:10
Checks if current screen is Edit screen of a given list of post types.
<?php
/**
* Return true if current screen is edit screen of a post type or list of post types.
*
* @param string|array $post_type Single or list of post types.
* @return boolean
*/
function is_edit_screen( $post_types = array() ) {
global $pagenow;
if ( 'post.php' !== $pagenow ) {
@lucymtc
lucymtc / wp_encrypt_decrypts_password.php
Created July 28, 2017 11:19
Encrypt/decrypt passwords
<?php
/**
* Encrypt password using OpenSSL
*
* @param string $password The password to encrypt.
*/
public function encrypt_password( $password ) {
$encryption_key = base64_decode( SECURE_AUTH_KEY );
$iv = openssl_random_pseudo_bytes( openssl_cipher_iv_length( 'aes-256-cbc' ) );
$encrypted = openssl_encrypt( $password, 'aes-256-cbc', $encryption_key, OPENSSL_RAW_DATA, $iv );
@lucymtc
lucymtc / gist:1e5eadf39610e9435f14d602b4655df5
Last active September 28, 2017 10:28
workaround vvv2 with Variable VVV (vv create)
Using vvv2 with vv create from https://github.com/bradp/vv has incomaptibility
Workarund:
First add site to vvv-custom.yml
testvv:
skip_provisioning: false
hosts:
- testvv.dev