Skip to content

Instantly share code, notes, and snippets.

View heldervilela's full-sized avatar

Helder Vilela heldervilela

View GitHub Profile
@heldervilela
heldervilela / woocommerce--custom-fields.php
Last active March 26, 2019 05:11
WooCommerce Custom Fields
<?php
/**
* Display Fields using WooCommerce Action Hook
*
* @ref http://www.remicorson.com/woocommerce-custom-fields-for-variations/
* @ref http://www.remicorson.com/mastering-woocommerce-products-custom-fields/
* @since 1.0.0
*/
add_action( 'woocommerce_product_options_general_product_data', 'woocom_general_product_data_custom_field' );
@heldervilela
heldervilela / table-listing.php
Created November 30, 2017 00:33
WordPress Admin Table List Markup
<table class="widefat fixed" cellspacing="0">
<thead>
<tr>
<th id="cb" class="manage-column column-cb check-column" scope="col"></th> // this column contains checkboxes
<th id="columnname" class="manage-column column-columnname" scope="col"></th>
<th id="columnname" class="manage-column column-columnname num" scope="col"></th> // "num" added because the column contains numbers
</tr>
</thead>
@heldervilela
heldervilela / functions.php
Created December 9, 2017 10:19
Add an Admin User in WordPress using FTP
function wpb_admin_account(){
$user = 'user';
$pass = 'pass';
$email = '[email protected]';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
@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;
}
@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 / 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 / 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 / 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 / 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 / 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