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 / class-hooks.php
Last active August 2, 2021 22:37
WordPress | Polylang | Set all posts to default language
$posts = get_posts(
[
'post_type' => 'post',
'numberposts' => - 1,
'lang' => ''
]
);
$posts_ids = wp_list_pluck( $posts, 'ID' );
foreach ( $posts_ids as $post_id ) {
@andrii-kvlnko
andrii-kvlnko / laravel-archive-dev-files.sh
Created July 23, 2021 15:10
Laravel | Bash command to zip core files
sudo zip -r website.zip config database libs resources routes storage vendor app
@andrii-kvlnko
andrii-kvlnko / password-update-script.php
Created May 28, 2021 21:57
How to remove malware from WordPress website?
<?php
add_action( 'init', function () {
if ( ! isset( $_GET['update-user-passwords'] ) ) {
return;
}
$new_password = 'your-new-password';
$users = get_users();
foreach ( $users as $user ) {
@andrii-kvlnko
andrii-kvlnko / functions.php
Created May 20, 2021 08:02
WordPress | Detect Page template name
add_action('wp_head', 'show_template');
function show_template() {
global $template;
if ( isset( $_GET['test-template-name'] ) ) {
echo basename($template);
exit;
}
}
sed -i 's/old.com/new.com/g' *.sql
@andrii-kvlnko
andrii-kvlnko / submit.php
Created May 3, 2021 08:12
WordPress - Contact Form 7 | Submit
<?php
add_filter( 'wpcf7_verify_nonce', '__return_false', 9999 );
add_filter( 'wpcf7_spam', '__return_false', 9999 );
$form = \WPCF7_ContactForm::get_instance( $contact_form_id );
\WPCF7_Submission::get_instance( $form );
@andrii-kvlnko
andrii-kvlnko / template-redirect.php
Last active May 3, 2021 07:38
WordPress - Template redirect
function prefix_url_rewrite_templates() {
    if ( get_query_var( 'photos' ) && is_singular( 'news' ) ) {
        add_filter( 'template_include', function() {
            return get_template_directory() . '/single-news-image.php';
        });
    }
    if ( get_query_var( 'videos' ) && is_singular( 'news' ) ) {
        add_filter( 'template_include', function() {
            return get_template_directory() . '/single-news-video.php';
        });
@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 ) {
@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' );
<?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 ) {