Skip to content

Instantly share code, notes, and snippets.

@PhongGCS
PhongGCS / gist:40d7dcd8310c22952d2497a4296982b0
Created April 23, 2020 08:55
Nginx Vhost Configuration
server {
listen *:80;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/dokhacphong.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/dokhacphong.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
@PhongGCS
PhongGCS / gist:8c2c2d79b826e325a6d8e01406f0b394
Created May 4, 2020 08:19
Auto add coupon in woocommerce with sample attribute variation
add_action( 'woocommerce_before_cart', 'cs_apply_matched_coupons' );
function cs_apply_matched_coupons() {
global $woocommerce;
$coupon1 = 'coupon 1'; // your coupon code here
$coupon2 = 'coupon 2'; // your coupon code here
$coupon3 = 'coupon 3'; // your coupon code here
$coupon4 = 'coupon 4'; // your coupon code here
@PhongGCS
PhongGCS / gist:faf8471e6c6afd09ad819e066e8d229d
Last active May 13, 2020 03:21
Deploy Root theme to Hostinger
Deploy Bedrock on CPANEL
1. Prepare database
# Requirement
+ Got the root folder of CPANEL !important
# Change url and DB by Migrate DB Pro
Go to Migrate DB Pro at *.dokhacphong.com
At Migrate Tab => Choose Export File
//phong.dokhacphong.com =======> //domain live site
/var/www/clients/client3/web144/web/phong-com/site/web ===========> ROOT_FOLDER + '/web'
Hit botton Export
// Create new user, new db and grant privilege
> CREATE USER 'phong'@'localhost' IDENTIFIED BY 'phong!';
> CREATE DATABASE phong
> GRANT ALL PRIVILEGES ON phong.* TO 'phong'@'localhost';
> FLUSH PRIVILEGES
sudo mysql -u phong -p phongdatabase < file.sql
$data['args']['tax_query'] = [
[
'taxonomy' => 'brand',
'field' => 'id',
'terms' => get_field('brands', $id)
]
];
@PhongGCS
PhongGCS / gist:fe1989cb1e3f0d3ee58ed36f1beca24a
Created June 12, 2020 06:40
handleUploadFile by Symfomy
<?php
namespace ABC\Controllers;
use Stem\Controllers\PageController;
use Stem\Core\Context;
use Stem\Core\Response;
use ABC\Traits\Content\HasContent;
use ABC\Traits\Content\HasContentInterface;
use ABC\Traits\Content\HasHero;
use ABC\Traits\Content\HasOptions;
@PhongGCS
PhongGCS / Add rewrite for wordpress
Created June 18, 2020 16:54
Add rewrite for wordpress
function prefix_movie_rewrite_rule() {
add_rewrite_tag('%state_id%', '([A-Za-z0-9\-\_]+)');
add_rewrite_tag('%state%', '([A-Za-z0-9\-\_]+)');
add_rewrite_rule ( 'states/([A-Za-z0-9\-\_]+)/([A-Za-z0-9\-\_]+)', 'index.php?
state_id=$matches[1]&state=$matches[2]', 'top' );
}
add_action( 'init', 'prefix_movie_rewrite_rule');
**GET Request using Guzzle**
If you look at the REQ|RES website they provided a few endpoints for ‘GET’ request. I will take the example of ‘LIST USERS’ endpoint. For getting users list, they ask to send a GET request to this endpoint
https://reqres.in/api/users?page=2.
<?php
require_once "vendor/autoload.php";
use GuzzleHttp\Client;
$client = new Client([
Restart bitnami apache
`sudo /opt/bitnami/ctlscript.sh restart`