Skip to content

Instantly share code, notes, and snippets.

View felipelavinz's full-sized avatar

Felipe Lavín Z. felipelavinz

View GitHub Profile
@felipelavinz
felipelavinz / gist:1373985
Created November 17, 2011 18:20
mappress_fix
<?php
// mappress-api.php ~ 277
// now:
$this->mapid = (int)$wpdb->get_var("SELECT LAST_INSERT_ID()");
// proposed:
$this->mapid = (int)$wpdb->insert_id;
@felipelavinz
felipelavinz / apache
Created February 9, 2012 14:00
Canonical redirects for Apache, lighttpd and nginx
## Canonical redirect for Apache
# BEGIN Canonical Redirect
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC] ## will match any domain that's not our main domain
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
</IfModule>
# END Canonical Redirect
@felipelavinz
felipelavinz / sitemap.php
Created March 29, 2012 15:04
generate a dynamic sitemap from wordpress emnus
<?php
class av_sitemap{
private $args;
public $transient_id;
public $transient_data;
function __construct( $args ){
$this->args = wp_parse_args( $args, array(
'main_menu' => 'principal',
'skip' => null,
@felipelavinz
felipelavinz / limit-login-attemts.php.diff
Created May 16, 2012 16:26
Add a whitelist option for limit-login-attempts plugin for WordPress
=== modified file 'htdocs/wp-content/plugins/limit-login-attempts/limit-login-attempts.php'
--- htdocs/wp-content/plugins/limit-login-attempts/limit-login-attempts.php 2012-05-16 14:12:30 +0000
+++ htdocs/wp-content/plugins/limit-login-attempts/limit-login-attempts.php 2012-05-16 15:05:44 +0000
@@ -75,6 +75,9 @@
/* If notify by email, do so after this number of lockouts */
, 'notify_email_after' => 4
+
+ /* A list of IPs that won't be blocked, one per line */
+ , 'exclude_ips' => ''
@felipelavinz
felipelavinz / csv_export.php
Created May 25, 2012 17:12
quickest way to export to CSV in php
<?php
global $wpdb;
// obtener resultados para una consulta cualquiera
// el parámetro ARRAY_N indica que wpdb debe retornar los resultados
// como un array con índices numéricos
$entries = $wpdb->get_results("SELECT * FROM $wpdb->contact_form ORDER BY id DESC", ARRAY_N);
if ( $entries ) {
@felipelavinz
felipelavinz / gist:2843682
Created May 31, 2012 14:19
group results by frequency
# originally seen on: http://psoug.org/snippet/Grouping_rows_by_frequency_299.htm
SELECT DISTINCT field_name, COUNT(*) AS num
FROM table_name
GROUP BY field_name
ORDER BY num DESC
@felipelavinz
felipelavinz / gist:3083296
Created July 10, 2012 13:38 — forked from pochitax/gist:3083209
Menu Footer Admin
<div class="footer-admin">
<div class="center">
<img src="images/logo/clerk-footer.gif">
<div class="menu-footer-admin">
<ul>
<li class="active">
<a title="Dashboard" href="/dashboard">Dashboard</a>
</li>
<li>
<a title="Reservas" href="/bookings">Reservas</a>
@felipelavinz
felipelavinz / array_to_object.php
Created August 25, 2012 02:14
Deprecated functions exception handling
<?php
// versión re-escrita
function array_to_object($array = array()) {
try {
throw new flv_exception_deprecated( __FUNCTION__ );
} catch ( flv_exception_deprecated $e ) {
flv_handle_exceptions( $e );
return (object)$array;
}
@felipelavinz
felipelavinz / multiple-analytics-accounts-event-tracking.js
Created October 18, 2012 15:38
Event tracking when using multiple Google Analytics accounts
(function($){
$(document).ready(function(){
$('a[href$=".pdf"]').click(function(){
var trackers = _gat._getTrackers(),
specific_tracker = trackers[ trackers.length - 1 ], // assuming that the last tracker it's the one where you want to track the events
dl_url = $(this).attr('href'),
tracked = specific_tracker._trackEvent('Downloads', 'PDF', dl_url);
if ( typeof console.log == 'function' ) console.log( specific_tracker._getName(), tracked, dl_url );
});
});
@felipelavinz
felipelavinz / gist:3914346
Created October 18, 2012 19:41
sanitize data on "IN" clauses with wpdb
<?php
$menu_items = array();
foreach ( $menus[$menu] as $item ) $menu_items[] = $item['id'];
$placeholders = implode(', ', array_fill(0, count($menu_items), '%s'));
$query = "SELECT post_name, ID, post_title FROM $wpdb->posts WHERE post_name IN($placeholders)";
$results = $wpdb->get_results( $wpdb->prepare($query, $menu_items), OBJECT_K );