Skip to content

Instantly share code, notes, and snippets.

View nfsarmento's full-sized avatar

NS nfsarmento

View GitHub Profile
@nfsarmento
nfsarmento / functions.php
Created October 31, 2018 17:04
Admin user page custom column - Capture User Last Login
/*
* Admin user page custom column - Capture User Last Login
* https://www.nuno-sarmento.com
*/
add_action('wp_login','ns_capture_user_last_login', 10, 2);
function ns_capture_user_last_login($user_login, $user){
update_user_meta($user->ID, 'last_login', current_time('mysql'));
}
//Display Last Login Date in Admin
add_filter( 'manage_users_columns', 'ns_user_last_login_column');
@nfsarmento
nfsarmento / functions.php
Created November 13, 2018 10:22
WordPress restrict files bigger than 1mb
/**
* Restrict files bigger than 1mb to all users expect the ones inside of the array
* https://www.nuno-sarmento.com
*/
add_filter( 'upload_size_limit', 'ns_change_upload_size' );
function ns_change_upload_size(){
/* setup an array of user ids to not be affected */
$restrictupload = array( 1, 14, 17, 37, 14263, 14289 );
@nfsarmento
nfsarmento / funtions.php
Last active November 19, 2018 15:17
Change login logo and URL - WordPress
/**
* Add CSS in the file referenced below, then create the appropriate logo in assets/img/logo-login.png
*/
function ns_login_logo_one() {
?>
<style type="text/css">
body.login div#login h1 a {
background-image: url(https://danielgb.wpengine.com/wp-content/uploads/2018/10/Daniel-Greenberg-logo1.png);
background-size: 200px 65px;
padding-bottom: 30px;
@nfsarmento
nfsarmento / script.js
Created November 27, 2018 16:58
Disable Submission when Pressing Enter for Gravity Forms
<script type="text/javascript">
/**
* Gravity Wiz // Gravity Forms // Disable Submission when Pressing Enter
* https://gravitywiz.com/disable-submission-when-pressing-enter-for-gravity-forms/
*/
jQuery(document).on( 'keypress', '.gform_wrapper', function (e) {
var code = e.keyCode || e.which;
if ( code == 13 && ! jQuery( e.target ).is( 'textarea,input[type="submit"],input[type="button"]' ) ) {
e.preventDefault();
return false;
@nfsarmento
nfsarmento / functions.php
Created December 6, 2018 14:53
WordPress SVG support
/**
* SVG Support
*
*/
function ns_svg_mime_types($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'ns_svg_mime_types');
@nfsarmento
nfsarmento / funtions.php
Created January 31, 2019 14:57
WooCommerce Custom Thankyou redirection based on Product ID
add_action( 'template_redirect', 'wc_custom_redirect_after_purchase' );
function wc_custom_redirect_after_purchase() {
if ( ! is_wc_endpoint_url( 'order-received' ) ) return;
// Define the product IDs in this array
$product_ids = array( 37, 25, 50 ); // or an empty array if not used
// Define the product categories (can be IDs, slugs or names)
$product_categories = array( 'clothing' ); // or an empty array if not used
$redirection = false;
@nfsarmento
nfsarmento / functions.php
Created February 4, 2019 17:57
Check if Product Category is in the Cart – WooCommerce
add_action('woocommerce_before_cart', 'ns_check_category_in_cart');
function ns_check_category_in_cart() {
// Set $cat_in_cart to false
$cat_in_cart = false;
// Loop through all products in the Cart
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
@nfsarmento
nfsarmento / acf_fields.json
Created February 5, 2019 15:19
Slick slider (sevens columns responsive) with ACF Repeater using ACF options page (theme settings)
{
"key": "group_5c599a7119fec",
"title": "Clients slider shortcode",
"fields": [
{
"key": "field_5c59a7e3fe75a",
"label": "How to use the slider",
"name": "",
"type": "message",
"instructions": "",
@nfsarmento
nfsarmento / functions.php
Last active December 11, 2019 17:41
Slick Slider ACF/Options shortcode
// ACF options
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Theme General Settings',
'menu_title' => 'Theme Settings',
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
@nfsarmento
nfsarmento / jquery-make-entire-div-clickable.js
Created February 27, 2019 17:35
Make entire div(s) clickable
<script>
$(".myDIV-0, .myDIV-1").click(function() {
window.location = $(this).find("a").attr("href");
return false;
});
</script>