Skip to content

Instantly share code, notes, and snippets.

View gianghl1983's full-sized avatar

Giang Le gianghl1983

View GitHub Profile
@gianghl1983
gianghl1983 / log.php
Created May 20, 2018 12:36
Kiểm tra người dùng đã đăng nhập chưa
<?php
if ($_GET['submit']) {
//do SMT
}
?>
$answers = [
['question_id' => 1, 'option' => 'C'],
['question_id' => 2, 'option' => 'A'],
['question_id' => 3, 'option' => 'C'],
['question_id' => 4, 'option' => 'B'],
['question_id' => 5, 'option' => 'C'],
['question_id' => 6, 'option' => 'C'],
['question_id' => 7, 'option' => 'D'],
['question_id' => 8, 'option' => 'D']
];
<?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;
<?php
$server = 'localhost';
$username = 'giang2424_demo';
$password = '05012011';
$database = "giang2424_quanlythuchi";
$db_qltc = new mysqli($server, $username, $password, $database);//Thay tên $db_qltc
$db_qltc->set_charset('utf8');
if ($db_qltc->connect_error) {
echo "<br>Lỗi kết nối";
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
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',
@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_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;