Skip to content

Instantly share code, notes, and snippets.

View gianghl1983's full-sized avatar

Giang Le gianghl1983

View GitHub Profile
@gianghl1983
gianghl1983 / form-content.html
Created August 6, 2019 14:25 — forked from alexmustin/form-content.html
WordPress AJAX Live Search of Post Title
<!-- // The HTML (could be part of page content) // -->
<input type="text" name="keyword" id="keyword" onkeyup="fetch()"></input>
<div id="datafetch">Search results will appear here</div>
@gianghl1983
gianghl1983 / pmpromyCRED.php
Created June 20, 2019 14:31 — forked from strangerstudios/pmpromyCRED.php
Award MyCRED points for members who sign up for Membership Level 1.
<?php
/*
Use this recipe in combination with MyCRED to award points to members when signing up
for Level 1 membership. This code gist could be customized to give points for another
membership level ID, award recurring points for each subscription payment, and more.
MyCRED can be downloaded/configured here: https://wordpress.org/plugins/mycred/
*/
// Register Hook for PMPro Membership Points at Signup
add_action("init","um_custom_init");
function um_custom_init(){
remove_action('wp_head', 'um_profile_dynamic_meta_desc', 9999999);
}
add_action('wp_head', 'um_custom_profile_dynamic_meta_desc', 9999999);
function um_custom_profile_dynamic_meta_desc() {
global $ultimatemember;
if ( um_is_core_page('user') && um_get_requested_user() ) {
um_fetch_user( um_get_requested_user() );
<?php
add_filter("um_profile_edit_menu_items","um_custom_profile_edit_menu_items",10,2);
function um_custom_profile_edit_menu_items( $items, $profile_id ){
$items[ ] = array(
"my_custom_menu_item" => '<a href="http://example.com/" class="real_url">'.__('My Custom Menu Item','ultimatemember').'</a>',
);
return $items;
@gianghl1983
gianghl1983 / usermeta-shortcode.php
Created March 19, 2019 12:15 — forked from dave-mills/usermeta-shortcode.php
A WordPress custom shortcode to display a piece of user metadata from the wp_usermeta table. Relies on Ultimate Member plugin
/* Create new shortcode for quickly displaying user metadata.
*** NOTE: This only works if you have the Ultimate Member plugin installed.
*** Use like regular wordpress shortcodes. Enter [USERMETA user_id="*id*" meta="*field_name*"] (replace *id* and *field_name* with actual values)
*** If you use it on an Ultimate Member profile page/tab, it will use the user currently being viewed.
*** On other pages, you must include the "user_id" within the shortcode.
*/
//Add the shortcode to WordPress
add_shortcode('USER_META', 'user_meta_shortcode_handler');
//create the function referenced by the add_shortcode()
<?php
add_filter('um_profile_tabs', 'pages_tab', 1000 );
function pages_tab( $tabs ) {
$user_id = um_get_requested_user();
// Show to profile owners only
if ( is_user_logged_in() && get_current_user_id() == $user_id ) {
$tabs['faves'] = array(
'name' => 'Faves',
'icon' => 'fa fa-star',
function wpuf_post_umgroup( $post_id, $form_id ) {
/* Build the post content by adding the referer URL to the comment and update the post */
$lv_comment = $_POST['_my_comment'] . PHP_EOL . PHP_EOL . home_url() . wp_get_referer();
$lv_post = array();
$lv_post['ID'] = $post_id;
$lv_post['post_author'] = get_current_user_id();
$lv_post['post_content'] = $lv_comment;
<?php
include ('database/connect.php');
//print_r($db_qltc);
/**
* BÀI TOÁN PHÂN TRANG
* B1: Khai báo $limit_per_page (Số bản ghi trên trang)
* B2: Lấy $current_page (Trang hiện tại): $current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
* B3: Tính $offset = ($current_page - 1) * $limit;
* B4: Đếm tổng số bản ghi (Có kèm điều kiện hoặc không có điều kiện): $totalRecord
* B5: Tính $totalPage = ceil($totalRecord/$limit)
<?php
include ('database/connect.php');
// <a href="account.del.php?id=<?php echo $account['id'];
/**
* Xóa dữ liệu: Có 2 cách (Logic, Vật ly)
* + Logic (Cập nhật 1 trạng thái nào đó mà mình quy định nó sẽ được hiểu là bản ghi được xóa). delete_flag (1: Xóa, o: Tồn tại)
* => Dữ liệu không mất, khi cần có thể backup lại. Tuy nhiên, khi xử lý, phức tạp hơn xóa vật lý vì các dữ liệu sẽ liên đới với nhau.
* + Vật lý: Xóa mất luôn data trong CSDL. Dễ thao tác, dễ triển khai, nhưng rủi ro mất dữ liệu cao.
* Luân chuyển dữ liệu:
* Thay vì xóa đi, thì mình chuyển dữ về sang 1 table nháp, hoặc database nào đó, hoặc cập nhật sang 01 danh mục.
<?php
include ('database/connect.php');
//B1 = check ID
//B2= nap lai data
//B3= update
$errors = [];
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;