Skip to content

Instantly share code, notes, and snippets.

View lmartins's full-sized avatar

Luis Martins lmartins

  • Goodwin Media, Multiweb
  • Portugal
View GitHub Profile
@lmartins
lmartins / functions.php
Last active November 3, 2023 19:28 — forked from woogist/functions.php
By default WooCommerce redirects the user to the My Account page after a successful login. You may change this and use a custom URL based on the user role, like the Dashboard for admins and My Account page for customers. To do this, add this code at the end of the file functions.php located in wp-content/themes/your-theme-name/ https://support.w…
<?php
/**
* Redirect users to custom URL based on their role after login
*
* @param string $redirect
* @param object $user
* @return string
*/
function wc_custom_user_redirect( $redirect, $user ) {
// Get the first of all the roles assigned to the user
@lmartins
lmartins / front-page.php
Created October 8, 2014 08:44
WooCommerce custom loop for Featured Products
<?php
$args = array(
'post_type' => 'product',
'meta_key' => '_featured',
'meta_value' => 'yes',
'posts_per_page' => 6
);
$featured_query = new WP_Query( $args );
if ($featured_query->have_posts()) :
?>
@lmartins
lmartins / genesis_attr_add_class.php
Last active September 20, 2022 13:33 — forked from JiveDig/genesis_attr_add_class.php
Add classes and attributes to any element in Genesis
<?php
//* Add class to .site-container
add_filter('genesis_attr_site-container', 'jive_attributes_st_container');
function jive_attributes_st_container($attributes) {
$attributes['class'] .= ' st-container';
return $attributes;
}
//* Add class to .site-inner
@lmartins
lmartins / functions.php
Created November 14, 2014 12:44
Sanitize file names during upload to Wordpress
/**
* Sanitize File name during upload
* http://stackoverflow.com/questions/3259696/rename-files-during-upload-within-wordpress-backend
*/
function make_filename_hash($filename) {
$info = pathinfo($filename);
$ext = empty($info['extension']) ? '' : '.' . $info['extension'];
$name = basename($filename, $ext);
return md5($name) . $ext;
}
@lmartins
lmartins / front-page.php
Created October 8, 2014 08:44
WooCommerce custom loop for products on-sale
<?php
$args = array(
'post_type' => 'product',
'meta_query' => array(
'relation' => 'OR',
array( // Simple products type
'key' => '_sale_price',
'value' => 0,
'compare' => '>',
'type' => 'numeric'
@lmartins
lmartins / SassMeister-input-HTML.html
Created January 27, 2014 19:25
Creating SASS mixins aliases
<button>Alerted</button>
@lmartins
lmartins / Debounce.coffee
Created April 11, 2014 15:06
Debounce function execution in CoffeeScript
# Based on:
# http://unscriptable.com/2009/03/20/debouncing-javascript-methods/
debounce = (func, threshold, execAsap) ->
timeout = null
(args...) ->
obj = this
delayed = ->
func.apply(obj, args) unless execAsap
timeout = null
@lmartins
lmartins / template-test.php
Last active April 11, 2019 00:59 — forked from billerickson/template-test.php
Genesis Custom Loop
<?php
/* Template Name: Test */
/**
* Genesis custom loop
*/
function be_custom_loop() {
global $post;
// arguments, adjust as needed
@lmartins
lmartins / upload-a-file.MD
Created January 2, 2019 14:35 — forked from ahmadawais/upload-a-file.MD
Upload a file using the WordPress REST API

Upload files

Using the REST API to upload a file to WordPress is quite simple. All you need is to send the file in a POST-Request to the wp/v2/media route.

There are two ways of sending a file. The first method simply sends the file in the body of the request. The following PHP script shows the basic principle:

@lmartins
lmartins / Closures.coffee
Created March 28, 2014 12:29
JS Closures in Coffeescript
# CLOSURES
showName = (firstName, lastName) ->
nameIntro = "Your name is "
makeFullName = ->
console.log nameIntro + firstName + " " + lastName
return makeFullName()
showName("Michael", "Jackson")