Skip to content

Instantly share code, notes, and snippets.

@jprieton
jprieton / behavior.js
Created August 27, 2016 23:11
Mask input type file with Bootstrap
(function ($) {
'use strict';
// Used to mask behavior of input type file
$('.input-group-file').each(function (e, i) {
var inputFile = $(i).find('input[type="file"]');
var inputText = $(i).find('input[type=text]');
var inputLabel = $(i).find('label');
// Bind click to use the label behavior in the input text
<?php
add_action( 'rest_api_init', function () {
register_rest_route( 'me/favorite', 'add', array(
'methods' => 'GET',
'callback' => 'rest_test',
) );
} );
function wp_send_rest_success( $response = array() ) {
@jprieton
jprieton / wp-query-ref.php
Created August 8, 2016 19:52 — forked from luetkemj/wp-query-ref.php
WP: Query $args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
*/
$args = array(
@jprieton
jprieton / accept-terms.php
Last active April 14, 2016 14:51
Example of hook pre_jptt_user_register to accept Terms & Conditions
<?php
/**
* To validate if user accepts terms & conditions
*/
add_action( 'pre_jptt_user_register', function () {
$accept_terms = (bool) trim( filter_input( INPUT_POST, 'accept_terms', FILTER_SANITIZE_STRING ) );
if ( !$accept_terms ) {
$error = new WP_Error( 'no_accept_terms', __( "You must accept terms & conditions to continue", TEXT_DOMAIN ) );
@jprieton
jprieton / delete-products-woocommerce.sql
Created April 13, 2016 16:19
Delete all products in woocommerce with comments
delete from wp_posts where post_type in ('product', 'product_variation', 'shop_order');
delete from wp_postmeta where post_id not in (select ID as post_id from wp_posts);
delete from wp_comments where comment_post_ID not in (select ID as comment_post_ID from wp_posts);
delete from wp_commentmeta where comment_id not in (select comment_ID as comment_id from wp_comments);
@jprieton
jprieton / .htaccess
Created April 6, 2016 15:39
Block any attempted XML-RPC requests
## Block any attempted XML-RPC requests
<Files xmlrpc.php>
order deny,allow
deny from all
## allow from 123.123.123.123
</Files>
@jprieton
jprieton / post-hierarchical.php
Created March 2, 2016 15:30
Set WordPress post hierarchical
<?php
add_post_type_support( 'post', 'page-attributes' );
add_action( 'init', function() {
global $wp_post_types;
$wp_post_types['post']->hierarchical = true;
}, 99 );
@jprieton
jprieton / .htaccess
Last active January 28, 2016 14:02 — forked from felipepodesta/.htaccess
# ----------------------------------------------------------------------
# WORDPRESS HTACCESS FIREWALL
# @ http://codex.wordpress.org/Hardening_WordPress
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
# DISABLE DIRECTORY BROWSING
# ----------------------------------------------------------------------
Options All -Indexes
@jprieton
jprieton / user_poll_vote.php
Created August 21, 2015 16:14
user_poll_vote
<form class="col-sm-6" action="<?php echo admin_url('admin-ajax.php') ?>" method="post">
<?php
$poll = current(get_posts('post_type=poll&posts_per_page=1'));
$poll_options = (array) get_post_meta($poll->ID, '_poll_options', TRUE);
?>
<input type="hidden" name="poll_id" value="<?php echo $poll->ID ?>">
<input type="hidden" name="action" value="user_poll_vote">
<?php wp_nonce_field('user_poll_vote') ?>
@jprieton
jprieton / wp_url_update.sql
Created August 11, 2015 19:28
Actualizacion de url
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');