Skip to content

Instantly share code, notes, and snippets.

@amielucha
amielucha / wordpress-hack.sql
Created March 5, 2018 10:45
WordPress MySQL admin injection
INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`)
VALUES ('hackadmin', MD5('password123'), 'Andy Admin', '[email protected]', '0');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, (Select max(id) FROM wp_users), 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, (Select max(id) FROM wp_users), 'wp_user_level', '10');
@amielucha
amielucha / functions.php
Created February 15, 2018 20:06
WordPress disable REST API for visitors
<?php
// Disable REST API for logged out users
add_filter( 'rest_authentication_errors', function( $result ) {
if ( ! empty( $result ) ) {
return $result;
}
if ( ! is_user_logged_in() ) {
return new WP_Error( 'rest_not_logged_in', 'You are not currently logged in.', array( 'status' => 401 ) );
}
@amielucha
amielucha / Bootstrap-4-beta-responsive.md
Created December 7, 2017 16:15
Bootstrap 4 beta responsive classes
  • hidden-xs-down = d-none d-sm-block
  • hidden-sm-down = d-none d-md-block
  • hidden-md-down = d-none d-lg-block
  • hidden-lg-down = d-none d-xl-block
  • hidden-xl-down = d-none (same as hidden)
  • hidden-xs-up = d-none (same as hidden)
  • hidden-sm-up = d-sm-none
  • hidden-md-up = d-md-none
  • hidden-lg-up = d-lg-none
  • hidden-xl-up = d-xl-none
@amielucha
amielucha / acf-pro-filter-add-tabs-to-content.php
Created October 27, 2017 10:50
ACF PRO - WordPress - render repeated as tabs
<?php
/*
* Append Bootstrap tabs to the post's content using ACF Pro repeater field.
*
* Prequisites:
* - ACF PRO plugin
* - Repeater field `tabs` containing `tab_title` (text) and `tab_content` (WYSIWYG) fields.
* - Bootstrap 4.0 with util.js and tab.js loaded (or bootrap.js)
*/
@amielucha
amielucha / functions-sort-prev-next-by-menu-order.php
Created September 12, 2017 11:12
WordPress: sort Previous and Next post by menu_order
<?php
function my_previous_post_where() {
global $post, $wpdb;
return $wpdb->prepare( "WHERE p.menu_order < %s AND p.post_type = %s AND p.post_status = 'publish'", $post->menu_order, $post->post_type);
}
add_filter( 'get_previous_post_where', 'my_previous_post_where' );
function my_next_post_where() {
global $post, $wpdb;
return $wpdb->prepare( "WHERE p.menu_order > %s AND p.post_type = %s AND p.post_status = 'publish'", $post->menu_order, $post->post_type);
}
@amielucha
amielucha / free-ebooks.sh
Created March 20, 2017 11:17
Free O'Reilly ebooks
wget http://www.oreilly.com/programming/free/files/modern-java-ee-design-patterns.epub
wget http://www.oreilly.com/programming/free/files/object-oriented-vs-functional-programming.epub
wget http://www.oreilly.com/programming/free/files/java-the-legend.epub
wget http://www.oreilly.com/programming/free/files/introducing-java-8.epub
wget http://www.oreilly.com/programming/free/files/a-whirlwind-tour-of-python.epub
wget http://www.oreilly.com/programming/free/files/20-python-libraries-you-arent-using-but-should.epub
wget http://www.oreilly.com/programming/free/files/hadoop-with-python.epub
wget http://www.oreilly.com/programming/free/files/how-to-make-mistakes-in-python.epub
wget http://www.oreilly.com/programming/free/files/functional-programming-python.epub
wget http://www.oreilly.com/programming/free/files/python-in-education.epub
@amielucha
amielucha / .htaccess
Created March 9, 2017 16:07
WordPress force SSL .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
@amielucha
amielucha / toolset_types_disable_url_validation.php
Created February 5, 2017 18:31
Disable Toolset WP Types URL validation in the backend
<?php
/*
* Issue: the validation was preventing me from using non-standard domains when developing on localhost.
* Solution: disabled the URL verification, so I can use relative URLs and non-standard domains.
*
*/
/*
* Disable admin URL validation for Files, Images, Audio, and Video.
@amielucha
amielucha / functions.php
Created January 24, 2017 15:49 — forked from fuyuko/functions.php
Cheatsheet - WooCommerce Customization in functions.php
<?php
//Add a stylesheet after default style.css
wp_enqueue_style( 'my-css', get_template_directory_uri() . 'my-css.css', array('themename-style'));
//WooCommerce - Sort products by SKU
add_filter('woocommerce_get_catalog_ordering_args', 'custom_woocommerce_catalog_orderby');
function custom_woocommerce_catalog_orderby( $args ) {
$args['meta_key'] = '_sku';
$args['orderby'] = 'meta_value';
$args['order'] = 'asc';
@amielucha
amielucha / scrollTo.js
Created December 5, 2016 12:53
Scroll To Hash with jQuery
// First enqueue this funciton in functions.php
`wp_enqueue_script( 'scrollto', '//cdn.jsdelivr.net/jquery.scrollto/2.1.2/jquery.scrollTo.min.js', array( 'jquery' ), '20161205', true );`
// Bind to the click of all links with a #hash in the href
if ( $.isFunction($.fn.scrollTo) ) {
$('a[href^="#"]').click(function(e) {
e.preventDefault();
// Scroll the window, stop any previous animation, stop on user manual scroll
// Check https://github.com/flesler/jquery.scrollTo for more customizability
$(window).stop(true).scrollTo(this.hash, {duration:1000, interrupt:true});