Skip to content

Instantly share code, notes, and snippets.

View nfsarmento's full-sized avatar

NS nfsarmento

View GitHub Profile
@nfsarmento
nfsarmento / wordpress-twitter.php
Last active October 4, 2018 15:56
WordPress Twitter Feed - TwitterOauth
<?php
/* REQUIRES: TwitterOAuth
* https://github.com/abraham/twitteroauth/tree/master/twitteroauth
*
* Download and place in a /twitteroauth/ folder in your theme/plugin.
*/
session_start();
require "twitteroauth/autoload.php";
@nfsarmento
nfsarmento / functions.php
Last active October 30, 2018 14:39
WP Function to show current online users
/** WP Function to show current online users
*
* https://www.nuno-sarmento.com
*/
function ns_user_online_update(){
if ( is_user_logged_in()) {
// get the user activity the list
@nfsarmento
nfsarmento / functions.php
Last active October 30, 2018 14:39
WooCommerce: Auto complete paid Orders depending on payment methods
/** WooCommerce: Auto complete paid Orders depending on payment methods
*
* https://www.nuno-sarmento.com
*/
add_action( 'woocommerce_thankyou', 'ns_wc_auto_complete_paid_order', 20, 1 );
function ns_wc_auto_complete_paid_order( $order_id ) {
if ( ! $order_id )
return;
@nfsarmento
nfsarmento / functions.php
Last active October 30, 2018 14:38
Add "Note to Customer" to the PDF invoice, this code needs WooCommerce PDF Invoices & Packing Slips plugin
/** Add "Note to Customer" to the PDF invoice, this code needs WooCommerce PDF Invoices & Packing Slips plugin
*
* https://www.nuno-sarmento..com
*/
add_action( 'wpo_wcpdf_after_order_details', 'ns_add_note_to_customer_to_PDF_invoice' );
function ns_add_note_to_customer_to_PDF_invoice() {
global $wpo_wcpdf;
$wpo_wcpdf->order_notes();
}
@nfsarmento
nfsarmento / functions.php
Last active October 30, 2018 14:38
WordPress, redirect WP admin URLs for all users apart for the ones declare on the users array
/** WordPress, redirect WP admin URLs for all users apart for the ones declare on the users array
*
* https://www.nuno-sarmento..com
*/
function ns_redirect_users_by_role() {
global $pagenow;
if ( ! defined( 'DOING_AJAX' ) ) {
@nfsarmento
nfsarmento / functions.php
Created October 19, 2018 11:35
Extend WordPress search to include custom fields
/**
* Extend WordPress search to include custom fields
*
* https://www.nuno-sarmento..com
*/
/**
* Join posts and postmeta tables
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join
@nfsarmento
nfsarmento / functions.php
Last active October 30, 2018 14:39
"Read more" link to post excerpts of custom post types
/**
* Adds a custom "Read more" link to post excerpts of custom post types.
* Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and "Read more".
*
* https://www.nuno-sarmento.com
*/
function ns_cpt_excerpt_more( $more ) {
global $post;
$anchor_text = 'Read more';
@nfsarmento
nfsarmento / functions.php
Last active October 30, 2018 14:35
Predefine category for new products - this function will add a category automatically when the user creates a Product
/* Predefine category for new products - this function will add a category automatically when the user creates a Product
*
* https://www.nuno-sarmento..com
*/
add_action( 'save_post', 'ns_auto_add_product_category', 50, 3 );
function ns_auto_add_product_category( $post_id, $post, $update ) {
if ( $post->post_type != 'product') return; // Only products
@nfsarmento
nfsarmento / functions.php
Created October 30, 2018 16:04
User admin page - events tribe admin counting events column
/*
* Add Admin Event Column
*
* https://www.nuno-sarmento.com
*
*/
function ns_users_events_column( $cols ) {
$cols['user_events'] = 'Events';
return $cols;
}
@nfsarmento
nfsarmento / functions.php
Created October 31, 2018 15:15
Admin user page custom column - Print User Web Visits Column Value
/*
* Admin user page custom column - Print User Web Visits Column Value
*
* https://www.nuno-sarmento.com
*
*/
class NSLogin_Counter {
public function init() {
add_action( 'wp_login', array( $this, 'count_user_login' ), 10, 2 );