Skip to content

Instantly share code, notes, and snippets.

View andrii-kvlnko's full-sized avatar

Andrii Kovalenko andrii-kvlnko

View GitHub Profile
@andrii-kvlnko
andrii-kvlnko / migration.sql
Created March 27, 2019 22:00
Wordpress Database migration MySql Script
UPDATE wp_options SET option_value = replace(option_value, 'http://old.com', 'http://new.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://old.com','http://new.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://old.com', 'http://new.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://old.com','http://new.com');
@andrii-kvlnko
andrii-kvlnko / index.js
Created June 14, 2019 23:02
Process clicking | touching outside . Jquery
$(document).bind(
'touchend.namespace',
hideByClickingOutsideListener.bind(this, container)
);
function hideByClickingOutsideListener(containerElement, event) {
const container = $(containerElement);
if (!container.is(event.target) && container.has(event.target).length === 0) {
@andrii-kvlnko
andrii-kvlnko / create-admin-user.sql
Created August 20, 2019 21:46
Wordpress | Create Admin User | SQL | Script | Database
INSERT INTO `databasename`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('user_id', 'user_login', MD5('user_password'), 'User Name', 'user_email', 'http://usersite.example.com', '2019-06-07 00:00:00', '', '0', 'User Name');
INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, 'user_id', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, 'user_id', 'wp_user_level', '10');
@andrii-kvlnko
andrii-kvlnko / woocommerce-validate-checkout.php
Created August 29, 2019 00:33
Wordpress | Woocommerce | Custom validation
add_action( 'woocommerce_after_checkout_validation', 'prefix_validate', 10, 2);
function prefix_validate( $fields, $errors ){
if ( true ){
$errors->add( 'validation', 'Validation Message' );
}
}
@andrii-kvlnko
andrii-kvlnko / .htaccess
Created September 7, 2019 05:31
Apache | Prevent .git access
RedirectMatch 404 /\.git
RedirectMatch 404 ^.*\.log
@andrii-kvlnko
andrii-kvlnko / index.php
Last active September 15, 2019 14:34
Polylang | Woocommerce | Product Attributes | set Language
<?php
add_action( 'wp_loaded', 'action_wp_loaded_23235' );
function action_wp_loaded_23235() {
$taxonomies = wc_get_attribute_taxonomy_names();
$attributes_terms = get_terms(
[
'taxonomy' => $taxonomies,
@andrii-kvlnko
andrii-kvlnko / .gitignore
Created October 28, 2019 13:44
Wordpress .gitignore
/*
!wp-content/
wp-content/*
!wp-content/mu-plugins/
!wp-content/plugins/
!wp-content/themes/
wp-content/mu-plugins/*
wp-content/plugins/*
<?php
/**
* Filter Elasticsearch posts by current language.
*/
add_filter( 'ep_formatted_args', function( $formatted_args, $args ) {
if ( function_exists( 'pll_current_language' ) ) {
$lang = pll_current_language();
if ( $lang !== false ) {
@andrii-kvlnko
andrii-kvlnko / index.php
Created September 20, 2020 11:37
Set All pruduct categories Ukrainian Language
add_action( 'wp', 'porto_child_categories' );
function porto_child_categories() {
$categories = get_terms(
[
'taxonomy' => 'product_cat',
'lang' => ''
]
);
foreach( $categories as $category ) {
pll_set_term_language( $category->term_id, 'uk' );
@andrii-kvlnko
andrii-kvlnko / index.php
Created November 24, 2020 19:23
Set Post attachement from one lang to another
add_action( 'wp', function () {
return;
if ( $_COOKIE['PHPSESSID'] !== 'xxxx' ) {
return;
}
global $sitepress;
foreach ( range( 1, 100 ) as $iteration ) {