Skip to content

Instantly share code, notes, and snippets.

View gianghl1983's full-sized avatar

Giang Le gianghl1983

View GitHub Profile
@gianghl1983
gianghl1983 / acf-change-file-upload-directory.php
Created January 23, 2021 15:39 — forked from BODA82/acf-change-file-upload-directory.php
Change the upload directory of Advanced Custom Fields file upload field.
<?php
// ACF upload prefilter
function gist_acf_upload_dir_prefilter($errors, $file, $field) {
// Only allow editors and admins, change capability as you see fit
if( !current_user_can('edit_pages') ) {
$errors[] = 'Only Editors and Administrators may upload attachments';
}
// This filter changes directory just for item being uploaded
<?php
/*
Plugin Name: Import demo
Plugin URI: http://royduineveld.nl
Description: A demo import for my blog
Version: 1.0
Author: Roy Duineveld
Author URI: http://royduineveld.nl
*/
@gianghl1983
gianghl1983 / WPS_Extend_Plugin.php
Created January 18, 2021 09:08 — forked from wpsmith/WPS_Extend_Plugin.php
PHP: WPS_Extend_Plugin Class designed to declare a plugin dependency and used for extending a plugin.
<?php
/**
* Contains WPS_Extend_Plugin class. and wps_extend_plugins function.
*
* @package WPS_Core
* @author Travis Smith <t@wpsmith.net>
* @copyright 2015 WP Smith, Travis Smith
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @version 1.0.0
* @since File available since Release 1.0.0
@gianghl1983
gianghl1983 / disable-plugins-by-url.php
Created December 29, 2020 05:14 — forked from damiencarbery/disable-plugins-by-url.php
Class To Disable WordPress Plugins By URL - Disable specified plugins except for certain pages - enhanced with caching. http://www.damiencarbery.com/2019/03/class-to-disable-wordpress-plugins-by-url/
<?php
/*
Plugin Name: Class To Disable WordPress Plugins By URL
Plugin URI: http://www.damiencarbery.com/2019/03/class-to-disable-wordpress-plugins-by-url/
Description: Disable specified plugins except for certain pages - enhanced with caching.
Version: 0.1
Author: Damien Carbery
Author URI: http://www.damiencarbery.com/
*/
@gianghl1983
gianghl1983 / ff-user-email-verification.php
Created December 15, 2020 05:13 — forked from alex-authlab/ff-user-email-verification.php
Email verification add-on plugin for user created with Fluent Form Plugin
<?php
/*
Plugin Name: Fluent Form User Email Verification
Description: Fluent Form User Email Verification
Version: 1.0
Author: WPManageNinja Support Team
Author URI: https://wpmanageninja.com
Plugin URI: https://wpmanageninja.com
License: GPLv2 or later
Text Domain: fluentform
@gianghl1983
gianghl1983 / gist:b7b54b3995b8ba7fe70b56d4efd886ff
Created December 6, 2020 05:34 — forked from thachpham92/gist:d57b18cf02e3550acdb5
Tất cả các tham số trong WP_Query
// Source: https://gist.github.com/luetkemj/2023628
// Xem hướng dẫn WP_Query toàn tập: http://goo.gl/kRpzTz
<?php
$args = array(
//////Author Parameters - Tham số lấy bài viết theo tác giả
//http://codex.wordpress.org/Class_Reference/WP_Query#Author_Parameters
'author' => '1,2,3,', //(int) - Các ID tác giả cần lấy bài viết (thêm dấu - vào để loại trừ tác giả, ví dụ: -14, -20)
'author_name' => 'luetkemj', //(string) - Lấy bài viết dựa theo tên nick name của tác giả
'author__in' => array( 2, 6 ), //(array) - Lấy bài dựa theo ID của tác giả
@gianghl1983
gianghl1983 / add-to-cart.php
Created April 5, 2020 19:30 — forked from webaware/add-to-cart.php
WooCommerce purchase page add-to-cart with quantity and AJAX, by customising the add-to-cart template in the WooCommerce loop. See blog post for details: http://snippets.webaware.com.au/snippets/woocommerce-add-to-cart-with-quantity-and-ajax/
<?php
/**
* Loop Add to Cart -- with quantity and AJAX
* requires associated JavaScript file qty-add-to-cart.js
*
* @link http://snippets.webaware.com.au/snippets/woocommerce-add-to-cart-with-quantity-and-ajax/
* @link https://gist.github.com/mikejolley/2793710/
*/
// add this file to folder "woocommerce/loop" inside theme
<?php
/**
* Hides current user from search query in member directory
*/
add_filter('um_prepare_user_query_args', 'um_remove_current_user_from_query', 10, 2);
function um_remove_current_user_from_query( $query_args, $args ){
$query_args['exclude'] = array( get_current_user_id() );
return $query_args;
<?php
// Requires Ultimate Member v1.3.68+
// Change Displayname for Business category profiles
add_filter("um_user_display_name_filter","um_custom_businessname", 10, 2);
function um_custom_businessname( $name, $profile_id ){
um_fetch_user( $profile_id );
if( um_user('role') == 'business' ){
$name = um_user("first_name");
}
<?php
add_filter( 'caldera_forms_private_upload_directory', function( $directory, $field_id, $form_id, $transient_id ){
//IMPORTANT -- Change this to the ID of your field, or remove this conditional to affect all fields.
if( 'fld111' === $field_id ){
//see: https://developer.wordpress.org/reference/functions/wp_get_upload_dir/
$uploads = wp_get_upload_dir();
$directory = $uploads[ 'basedir' ] . '/somepath';
}
return $directory;
},10,4);