Skip to content

Instantly share code, notes, and snippets.

Luis luistinygod

View GitHub Profile
@luistinygod
luistinygod / tinygod-recover-roles.php
Created May 24, 2020
WordPress Plugin: Restores all the default roles and caps in the WordPress
View tinygod-recover-roles.php
<?php
/**
* Recover or Reset the default WordPress user roles and caps
* Install it as a WordPress plugin, activate it and deativate. That's it.
*
* @wordpress-plugin
* Plugin Name: tinyGod Recover User Roles
* Plugin URI:
* Author: luistinygod
* Author URI: https://tinygod.pt
@luistinygod
luistinygod / data-persist.js
Last active Feb 2, 2020
Simple Vuex plugin to keep data across pages
View data-persist.js
const persistInterval = 24*60*60*1000; // 1 day
const plugin = store => {
store.subscribe( ( mutation, state ) => {
// Save to local storage all the changes made in the cart state
if( 'shop/addToCart' === mutation.type || 'shop/removeFromCart' === mutation.type ) {
let record = { data: state.shop.cart, ts: new Date().getTime() + persistInterval };
try {
@luistinygod
luistinygod / featured-posts-pattern-helper-functions.php
Last active Jun 1, 2018
WordPress: Manage featured posts using WordPress menus
View featured-posts-pattern-helper-functions.php
@luistinygod
luistinygod / cache-patterns-in-wordpress.php
Last active Apr 30, 2020
WordPress: Cache patterns for complex queries
View cache-patterns-in-wordpress.php
<?php
/**
* Retrieve a WP_Query object
*/
function my_complex_query( $refresh = false ) {
$last_changed = wp_cache_get_last_changed( 'my_group_my_post_type' );
$cache_key = 'my_result'.md5( $param1 . $param2 ).$last_changed;
@luistinygod
luistinygod / gv-snippet.php
Last active May 11, 2016
GravityView: Add multiple og:image tags on the single entry view
View gv-snippet.php
<?php
/**
* Displays multiple "og:image" opengraph meta tags according to the single entry available gallery images
*/
function my_gv_add_opengraph_multi_image() {
if( ! function_exists('gravityview_is_single_entry') || ! function_exists( 'gravityview_get_entry') ) {
return;
}
// get single entry id
@luistinygod
luistinygod / redirect.php
Last active Mar 8, 2016
GravityView: redirect a user to a different location after updating an entry
View redirect.php
<?php
/**
* Redirect the visitor to the single entry view after updating the entry
*/
function my_gv_redirect_after_update_to_single_entry_view( $form, $entry_id ) {
?>
<script>
jQuery(document).ready( function() {
window.location.replace( window.location.href.split('?')[0] );
});
View gravityview-convert-list-of-links-to-anchors.php
@luistinygod
luistinygod / maps-coordinates.php
Created Sep 2, 2015
GravityView Maps Premium View: Specify the Latitude and Longitude form field IDs (to be used instead of the address field)
View maps-coordinates.php
<?php
/**
* Use the cordinates (Latitude and Longitude) instead of the address to position the markers over the Maps
* Replace 'MY_LATITUDE_FIELD_ID' and 'MY_LONGITUDE_FIELD_ID' by the form field ids containing the latitude and longitude
* @param array $fields Gravity Forms fields IDs containing the latitude and longitude
* @param GravityView_View object $view Current View object
*/
function my_gv_maps_lat_long_fields( $fields, $view ) {
return array( 'MY_LATITUDE_FIELD_ID', 'MY_LONGITUDE_FIELD_ID' );
@luistinygod
luistinygod / grid-view.php
Created Aug 18, 2015
GravityView: Convert a list view into a grid style (3-col)
View grid-view.php
<?php
/**
* Add the `gv-grid` class to the list container
*/
function my_gv_list_container( $classes ) {
return $classes . ' gv-grid';
}
add_filter( 'gravityview/render/container/class', 'my_gv_list_container', 10, 1 );
/**
@luistinygod
luistinygod / gv-cancel-link.php
Created Aug 8, 2015
GravityView: Change the Cancel Edit Entry link to link directly to the multiple entries view
View gv-cancel-link.php
You can’t perform that action at this time.