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 / 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 / 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 );
sed -i 's/old.com/new.com/g' *.sql
@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;
}
}
@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 / 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 / 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 / plugin-template-part.php
Created August 2, 2021 23:01
Load plugin template part | WordPress
$plugin_path = plugin_dir_path( __DIR__ );
$template_path = sprintf( '%stemplate-parts/header/navbar-primary.php', $plugin_path );
include $template_path;
@andrii-kvlnko
andrii-kvlnko / resize.js
Created August 15, 2021 11:50 — forked from vishalsrini/resize.js
A simple JavaScript to resize an image and create a blob out of it
window.resize = (function () {
'use strict';
function Resize() {}
Resize.prototype = {
init: function(outputQuality) {
this.outputQuality = (outputQuality === 'undefined' ? 0.8 : outputQuality);
},
@andrii-kvlnko
andrii-kvlnko / index.php
Created September 15, 2021 14:07
WordPress | Polylang | Set languages to all posts
add_action( 'wp', function () {
$posts = get_posts(
[
'post_type' => 'post',
'lang' => '',
'paged' => 1,
'posts_per_page' => - 1,
]
);