Skip to content

Instantly share code, notes, and snippets.

View serguk89's full-sized avatar

Serhii serguk89

  • Kyiv, Ukraine
View GitHub Profile
@serguk89
serguk89 / sync-prod.sh
Created July 5, 2017 07:58 — forked from retlehs/sync-prod.sh
WP-CLI aliases sync example
read -r -p "Would you really like to reset your development database and pull the latest from production? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
wp @development db reset --yes &&
wp @production db export - > sql-dump-production.sql &&
wp @development db import sql-dump-production.sql &&
wp @development search-replace https://example.com https://example.dev
fi
@serguk89
serguk89 / [WP] Automatically select parent terms
Last active November 15, 2018 01:14
automatically select parent terms
add_action('set_object_terms', 'auto_set_parent_terms', 9999, 6); // automatically select parent terms
function auto_set_parent_terms( $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ) {
foreach( $tt_ids as $tt_id ) {
if ($parenttags = get_ancestors($tt_id, $taxonomy))
{
wp_set_object_terms( $object_id, $parenttags, $taxonomy, true );
}
}
}
@serguk89
serguk89 / wp_rewrite_rules.log
Created October 2, 2018 12:26 — forked from thenbrent/wp_rewrite_rules.log
Default WordPress Rewrite Rules
[rules] => Array (
[category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?category_name=$matches[1]&feed=$matches[2]
[category/(.+?)/(feed|rdf|rss|rss2|atom)/?$] => index.php?category_name=$matches[1]&feed=$matches[2]
[category/(.+?)/page/?([0-9]{1,})/?$] => index.php?category_name=$matches[1]&paged=$matches[2]
[category/(.+?)/?$] => index.php?category_name=$matches[1]
[tag/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?tag=$matches[1]&feed=$matches[2]
[tag/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?tag=$matches[1]&feed=$matches[2]
[tag/([^/]+)/page/?([0-9]{1,})/?$] => index.php?tag=$matches[1]&paged=$matches[2]
[tag/([^/]+)/?$] => index.php?tag=$matches[1]
[type/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?post_format=$matches[1]&feed=$matches[2]
function Generate_Image( $file, $post_id = 0 ){
$filepath = '/frontend/web';
if (file_exists(realpath($_SERVER['DOCUMENT_ROOT']) . $filepath . $file)) {
$file = str_replace(['/wp', ''], '', home_url($file));
} elseif (file_exists(realpath($_SERVER['DOCUMENT_ROOT'].'../www/') . $filepath . $file)) {
$file = str_replace(['/wp', 'test.'], '', home_url($file));
} else {
return false;
@serguk89
serguk89 / delete_custom_post_type.php
Created October 27, 2018 12:54 — forked from jazibsawar/delete_custom_post_type.php
WordPress $wpdb: Delete all posts of a custom post type with its associated meta data (taxonomies, post meta) using SQL query & $wpdb
<?php
function delete_custom_posts($post_type = 'post'){
global $wpdb;
$result = $wpdb->query(
$wpdb->prepare("
DELETE posts,pt,pm
FROM wp_posts posts
LEFT JOIN wp_term_relationships pt ON pt.object_id = posts.ID
LEFT JOIN wp_postmeta pm ON pm.post_id = posts.ID
WHERE posts.post_type = %s
@serguk89
serguk89 / get_meta_values.php
Created October 28, 2018 17:33 — forked from tybruffy/get_meta_values.php
Get all distinct values of a meta field in Wordpress
function _get_all_meta_values($key) {
global $wpdb;
$result = $wpdb->get_col(
$wpdb->prepare( "
SELECT DISTINCT pm.meta_value FROM {$wpdb->postmeta} pm
LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id
WHERE pm.meta_key = '%s'
AND p.post_status = 'publish'
ORDER BY pm.meta_value",
$key
@serguk89
serguk89 / gist:602bbbb8e37d5f3d13d6df9da142e568
Created November 2, 2018 00:54
One Liner to test php sending mail from a bash script
php -r 'var_dump(mail("test@gmail.com", "test subject", "test body"));'
@serguk89
serguk89 / october-deployment.sh
Created November 3, 2018 20:21 — forked from khoatran/october-deployment.sh
Bamboo deployment script
export DEPLOYMENT_FOLDER=/deployment-folder
export RELEASE_ROOT_FOLDER=$DEPLOYMENT_FOLDER/releases
export RELEASE_FOLDER=$DEPLOYMENT_FOLDER/releases/intermediate
cd $DEPLOYMENT_FOLDER/build
tar -xvf artifact.tar
rm -rf artifact.tar
cd $DEPLOYMENT_FOLDER
shopt -s dotglob
# Unzip and copy all files in artifact into the release folder
mkdir $RELEASE_FOLDER
@serguk89
serguk89 / rsync-remote.sh
Created November 3, 2018 20:21 — forked from khoatran/rsync-remote.sh
Rsync from remote
rsync -avz --progress -e "ssh -i ssh_key" root@ip_of_the_remote:/folder/* /target-folder
@serguk89
serguk89 / october.conf
Created November 3, 2018 20:21 — forked from khoatran/october.conf
Nginx fast cgi cache for OctoberCMS
#Set the path where the cache is stored; Set the zone name, totalsize (400m),and max life time(60m)
fastcgi_cache_path /var/run/nginx-cache levels=1:2 keys_zone=AICUNGXINH:400m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
#fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
server {
set $skip_cache 0;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {