Skip to content

Instantly share code, notes, and snippets.

View larbous's full-sized avatar

Luiz Sobral larbous

View GitHub Profile
@Shelob9
Shelob9 / simple-pods-plugin.php
Last active March 28, 2021 21:45
Simple plugin for safely adding code for extending Pods. Instructions: 1) Create a folder in your plugins file. 2) Add this file and a second file, called 'custom-code.php' to it. 3) Add custom code to custom-code.php. 4) Activate plugin. For a complete Pods plugin starter plugin, see: https://github.com/pods-framework/pods-extend
<?php
/*
Plugin Name: Pods Starter Plugin
Version: 0.0.1
License: GPL v2 or later
*/
//note: change 'slug' to your own custom prefix.
add_action( 'plugins_loaded', 'slug_extend_safe_activate');
function slug_extend_safe_activate() {
@tillsanders
tillsanders / intro.markdown
Last active June 24, 2021 20:17
Laravel: drag-and-drop repositioning with auto-save of DB entries

Laravel: drag-and-drop repositioning with auto-save of DB entries

Use case: Database entries are represented in a table. By grabbing and moving a row up or down the table, you can change the entries' order/position. The changes are submitted automatically via ajax.

  • Uses jQueryUI (custom download: sortable is needed)
  • newly created elements are added to the top (see route /jobs/create)
@micc83
micc83 / skip-to-check-out.php
Last active October 28, 2024 06:18
Skip cart and redirect to direct checkout on WooCommerce
<?php
/**
* Skip cart and redirect to direct checkout
*
* @package WooCommerce
* @version 1.0.0
* @author Alessandro Benoit
*/
// Skip the cart and redirect to check out url when clicking on Add to cart
@woogist
woogist / functions.php
Last active February 1, 2023 11:09
Redirect to a custom page after login based on the user role
<?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
@danielnass
danielnass / gist:d41d47a9b6e05918a56c
Created February 5, 2015 21:46
jQuery Validation Additional Method CNH - Carteira Nacional de Habilitação - Carteira de Motorista
$.validator.addMethod('CNH', function(value, element) {
var ret,
cnh = value,
firstChar = cnh.charAt(0);
if (cnh.replace(/[^\d]/g, '').length === 11 && firstChar.repeat(11) !== cnh) {
var dsc = 0;
for (var i = 0, j = 9, v = 0; i < 9; ++i, --j) {
@jonaslejon
jonaslejon / php-mass-mailer.php
Created March 17, 2015 09:01
PHP Mass Mailer
<?php
/*
The code below was found during a forensic investigation. It seems to be a mass mailer that is using the PHPMailer class to send mail
from compromised web hosting providers.
The "password" is 5307c392-ad5e-4909-adec-c9fd12572686, see below.
Investigation was made by Jonas Lejon <jonas.githubgist at- triop.se>
The signature for PHP.Trojan.Mailer-1 can only find the packed version of this file.
@yajra
yajra / ajax-datatables-expired-session.js
Last active June 30, 2022 20:34
Laravel 5.x solution to redirect AJAX expired session to login page and disable DataTables error prompt
/**
* Requirements:
* - jQuery (http://jquery.com/)
* - DataTables (http://datatables.net/)
* - BootboxJS (http://bootboxjs.com/)
* ---------------------------------------------------------------------------
* Credits to https://gist.github.com/flackend/9517696
* ---------------------------------------------------------------------------
* This monitors all AJAX calls that have an error response. If a user's
* session has expired, then the system will return a 401 status,
@hereswhatidid
hereswhatidid / acf-fields.php
Last active April 18, 2018 17:31
Create custom product details tabs within WooCommerce using an ACF (Advanced Custom Fields) Repeater field.
<?php
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array (
'key' => 'acf_product_options',
'title' => 'Product Options',
'fields' => array (
array (
'key' => 'acf_product_options_tabbedcontent_label',
'label' => 'Tabbed Content',
@crissoca
crissoca / rebuild_image_metadata.php
Last active May 16, 2018 17:19
Rebuilds WordPress image metadata after a manual media library migration
<?php
//Source: http://www.adam-makes-websites.com/discoveries/fixing_messed_up_image_attachments_in_wordpress_that_have_no_postmeta_values
function fixWPImageMetaData() {
// Notes:
// 1) This function will not alter existing meta entries for your images. The function is to ADD meta data for the images
// without it due to manually importing them or some other kind of mess-up in your wordpress wp_postmeta table.
// 2) Always remember to take a full database backup before each run of the function!
// 3) Although only tested on fairly recent WP versions it may work as far back as v1.5+. Give it a go and let me know!
@alanhartless
alanhartless / cron.php
Created August 31, 2015 14:43
Script to run Symfony commands from web
<?php
require_once __DIR__.'/app/bootstrap.php.cache';
require_once __DIR__.'/app/AppKernel.php';
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\BufferedOutput;
try {