Skip to content

Instantly share code, notes, and snippets.

@dexit
dexit / _readme.md
Created February 21, 2022 13:12 — forked from crazyyy/_readme.md
#wordpress #php || Snipets

Other Snippets

If / Else load Pages

  if ( is_front_page() && is_home() ){
      // Default homepage
  } elseif ( is_front_page()){
      //Static homepage
  } elseif ( is_home()){
@ekanant
ekanant / backup_mysql.sh
Created August 7, 2021 17:32
Backup mysql 5 each database to each file and change structure to mysql 8
MYSQL_USER=xxxx
MYSQL_PASS=yyyyy
MYSQL_CONN="-u${MYSQL_USER} -p${MYSQL_PASS}"
/usr/local/mysql/bin/mysql ${MYSQL_CONN} -N -e 'show databases' \
| while read dbname; \
do /usr/local/mysql/bin/mysqldump ${MYSQL_CONN} --complete-insert --routines --triggers --single-transaction --databases "$dbname" \
| sed -r "s/ENGINE=MyISAM/ENGINE=InnoDB/g" \
| sed -r "s/COLLATE=(latin1|utf8_bin|utf8|utf8_unicode_ci|utf8_unicode_ci|)/COLLATE=utf8mb4_0900_ai_ci/g" \
| sed -r "s/COLLATE (latin1|utf8_bin|utf8|utf8_general_ci|utf8_unicode_ci)/COLLATE utf8mb4_0900_ai_ci/g" \
@lukeurban
lukeurban / docker_database.md
Created August 4, 2021 15:58
Importing database backup with progress bar to running docker container

Importing database backup with progress bar to running docker container.

Use a MySQL image with pv installed.

FROM mysql:8.0

RUN apt-get update 
RUN apt-get install -y pv

COPY my.cnf /etc/mysql/conf.d/my.cnf
@stuartduff
stuartduff / wc-store-onwer-pending-payment-email.php
Created May 26, 2021 15:01
This code will send an email to the WooCommerce store owner for Pending Payment orders
// New order notification only for "Pending" Order status
add_action( 'woocommerce_checkout_order_processed', 'pending_new_order_notification', 20, 1 );
function pending_new_order_notification( $order_id ) {
// Get an instance of the WC_Order object
$order = wc_get_order( $order_id );
// Only for "pending" order status
if( ! $order->has_status( 'pending' ) ) return;
// Get an instance of the WC_Email_New_Order object
@stenito
stenito / publicip.php
Last active March 3, 2025 06:17
Get public IP address (or wan IP address) with php function
<?php
function getPublicIP() {
// create & initialize a curl session
$curl = curl_init();
// set our url with curl_setopt()
curl_setopt($curl, CURLOPT_URL, "http://httpbin.org/ip");
// return the transfer as a string, also with setopt()
@bitsnaps
bitsnaps / php_json_compression.php
Created December 13, 2020 11:20
PHP json string compression different examples and comparison
<?php
$users = file_get_contents('https://jsonplaceholder.typicode.com/users');
$gz = base64_encode(gzencode($users));
if (!$gz){
die('content contains non base64 alpha');
}
echo $gz;
@harshvardhanmalpani
harshvardhanmalpani / woo-get_order-api-update.php
Last active June 24, 2021 02:01
overriding wc api response
<?php
//// FOR LEGACY API ONLY
add_filter('woocommerce_api_order_response', 'harsh_add_shipping_phone_legacy', 99, 1);
function harsh_add_shipping_phone($order_data)
{
$order_data["billing_address"]["email"] = "XXXX";
$shipping_phone = get_post_meta($order_data["id"],"_shipping_phone",1);
if($shipping_phone!==false && strlen($shipping_phone))
{
@prabhu
prabhu / bitbucket-reusable-pipelines.yml
Created July 26, 2020 13:56
Reusable Bitbucket pipelines configuration with YAML anchors
definitions:
steps:
- step: &build
name: Build microservices jar
script:
- mvn package
artifacts:
- target/**
- step: &build-react
name: Build React app
@marcometz
marcometz / traefik basic auth htpasswd
Last active August 13, 2025 20:02
user and password generator for traefik basic auth middleware
traefik.frontend.auth.basic.users:
echo $(htpasswd -nbB username "passwort") | sed -e s/\\$/\\$\\$/g
@eusonlito
eusonlito / .htaccess
Created February 4, 2020 15:17
Accept all CORS requests on Apache and nginx. Improve website performance accepting all OPTIONS requests.
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
# Allow Access Control Headers
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET,PUT,POST,DELETE,PATCH,OPTIONS"
Header set Access-Control-Allow-Headers "Accept, Accept-Datetime, Accept-Language, App-Version, Authorization, Cache-Control, Content-Type, Date, Device-Token, Location, Origin, Time-Zone, User-Agent, X-Requested-With"
Header set Access-Control-Allow-Credentials "true"