Skip to content

Instantly share code, notes, and snippets.

View heldervilela's full-sized avatar

Helder Vilela heldervilela

View GitHub Profile
<?php
/**
* Login endpoint.
*
* @package @@pkg.name
* @version @@pkg.version
* @author @@pkg.author
* @license @@pkg.license
*/
@heldervilela
heldervilela / build-plugin.sh
Created July 24, 2018 23:07
WordPress plugin build script
#!/bin/bash
printf "Plugin name: "
read NAME
printf "Destination folder: "
read FOLDER
printf "Include Grunt support (y/n): "
read GRUNT
@heldervilela
heldervilela / wp-remove-default-image-sizes.php
Created July 22, 2018 11:59
Remove default WordPress and WooComerce image crops
<?php
/**
* Remove default WordPress and WooComerce image crops
*
* @since 1.0.0
* @access public
*
* @return void
*/
add_filter( 'intermediate_image_sizes_advanced', function( $sizes ) {
@heldervilela
heldervilela / smtp.config.php
Last active May 24, 2019 09:08
Easy SMTP email settings for WordPress
<?php
// The config.php file
/**
* Set the following constants in wp-config.php
* These should be added somewhere BEFORE the
* constant ABSPATH is defined.
*/
define( 'SMTP_USER', '[email protected]' ); // Username to use for SMTP authentication
define( 'SMTP_PASS', 'smtp password' ); // Password to use for SMTP authentication
@heldervilela
heldervilela / functions.php
Created April 30, 2018 09:08
Disables WordPress Rest API for external requests
/**
* Disables WordPress Rest API for external requests
*
* @since 1.0.0
* @access public
*
* @return void
*/
add_action( 'rest_api_init', function() {
$whitelist = array('127.0.0.1', "::1");
@heldervilela
heldervilela / jail.local
Created April 5, 2018 22:39 — forked from rutger1140/jail.local
Fail2Ban - block WordPress brute force hack attempts - Plesk 12
# Create a new jail via Plesk
# generated in /etc/fail2ban/jail.local
[wp-auth]
enabled = true
filter = wp-auth
action = iptables-multiport[name=NoAuthFailures, port="http,https"]
logpath = /var/www/vhosts/system/*/logs/*access*log
/var/log/httpd/*access_log
maxretry = 15
@heldervilela
heldervilela / woocommerce_payment_complete.php
Created February 2, 2018 10:02
How to Hook Into WooCommerce to Trigger Something After an Order is Placed
add_action('woocommerce_payment_complete', 'custom_process_order', 10, 1);
function custom_process_order($order_id) {
$order = new WC_Order( $order_id );
$myuser_id = (int)$order->user_id;
$user_info = get_userdata($myuser_id);
$items = $order->get_items();
foreach ($items as $item) {
if ($item['product_id']==24) {
// Do something clever
}
@heldervilela
heldervilela / functions.php
Last active March 26, 2019 05:25
WooCommerce Products Custom Fields
http://www.benblanco.com/how-to-add-custom-product-tab-to-woocommerce-single-product-page/
http://www.remicorson.com/mastering-woocommerce-products-custom-fields/
// Display Fields
add_action( 'woocommerce_product_options_general_product_data', __NAMESPACE__.'\woo_add_custom_general_fields' );
function woo_add_custom_general_fields() {
global $woocommerce, $post;
@heldervilela
heldervilela / functions.php
Created January 22, 2018 01:05
Add WooCommerce Version Check Support to Your Plugins
<?php
/*
* Plugin Name: WooCommerce Stripe Gateway
* Plugin URI: https://wordpress.org/plugins/woocommerce-gateway-stripe/
* Description: Take credit card payments on your store using Stripe.
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* Version: 3.2.3
* Requires at least: 4.4
* Tested up to: 4.8
@heldervilela
heldervilela / woo-tabs.php
Created December 19, 2017 21:49
WooCommerce Admin Custom Product Data Tab
// First Register the Tab by hooking into the 'woocommerce_product_data_tabs' filter
add_filter( 'woocommerce_product_data_tabs', 'add_my_custom_product_data_tab' );
function add_my_custom_product_data_tab( $product_data_tabs ) {
$product_data_tabs['my-custom-tab'] = array(
'label' => __( 'My Custom Tab', 'woocommerce' ),
'target' => 'my_custom_product_data',
'class' => array( 'show_if_simple' ),
);
return $product_data_tabs;
}