Skip to content

Instantly share code, notes, and snippets.

View ValeriiVasyliev's full-sized avatar
🏄
Focusing

Valerii Vasyliev ValeriiVasyliev

🏄
Focusing
View GitHub Profile
@ValeriiVasyliev
ValeriiVasyliev / 0-toc.md
Created September 3, 2022 16:14 — forked from benlk/0-toc.md
Collection of notes on WP_UnitTestCase
  1. Table of contents
  2. General information
    1. Terms
    2. General structure of a test
    3. WordPress-specific assertions and test functions
      • enqueues
      • creating posts
      • creating terms
      • attaching images
  • ?
public function shutdown_action() {
$keys = $this->get_data_keys();
$data = [];
foreach ( $keys as $key ) {
$this->data[ $key ] = isset( $this->data[ $key ] ) ? $this->data[ $key ] : [];
$data[ $key ] = array_replace( $this->data[ $key ], $this->{$key} );
}
wp_cache_set( $this->get_cache_key(), $this->maybe_reduce_cache_size( $data ) );
@ValeriiVasyliev
ValeriiVasyliev / .gitconfig
Created August 18, 2022 15:30
My aliases for git
[alias]
# archive a branch
ab = !sh -c 'git checkout $1 && git pull && git tag archive/$1 && git push origin $1 && git push origin archive/$1 && git checkout master && git branch -D $1 && git push origin --delete $1' -
# archive a branch (to a remote other than origin)
abb = !sh -c 'git checkout $1 && git pull $2 $1 && git tag archive/$1 && git push $2 $1 && git push $2 archive/$1 && git checkout master && git branch -D $1 && git push $2 --delete $1' -
# list aliases
aliases = !git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /'
@ValeriiVasyliev
ValeriiVasyliev / Hide wp-config.php and .htaccess
Created August 17, 2022 05:14 — forked from Phlow/Hide wp-config.php and .htaccess
Harden your WordPress and hide wp-config.php and .htaccess for attackers.
# Prevent wp-config.php and .htaccess
# from being accessed use this code
<Files wp-config.php>
order allow,deny
deny from all
</Files>
<Files .htaccess>
order allow,deny
@ValeriiVasyliev
ValeriiVasyliev / wordpress-extend-export-for-media.php
Created July 1, 2022 02:43
Extend the export of WordPress for media
<?php
define( 'DOING_AJAX', true );
define( 'WP_ADMIN', true );
define( 'WP_IMPORTING', true );
$err = array();
/** Load WordPress Bootstrap */
require_once 'wp-load.php';
@ValeriiVasyliev
ValeriiVasyliev / wordpress-import-media.php
Created July 1, 2022 02:41
Import images in the uploads folder to the WordPress Media
<?php
define( 'DOING_AJAX', true );
define( 'WP_ADMIN', true );
define( 'WP_IMPORTING', true );
$err = array();
/** Load WordPress Bootstrap */
require_once 'wp-load.php';
// Create token header as a JSON string
$header = json_encode(['typ' => 'JWT', 'alg' => 'HS256']);

// Create token payload as a JSON string
$payload = json_encode(['user_id' => 123]);

// Encode Header to Base64Url String
$base64UrlHeader = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($header));
@ValeriiVasyliev
ValeriiVasyliev / woocommerce-optimize-scripts.php
Created May 11, 2022 16:09 — forked from DevinWalker/woocommerce-optimize-scripts.php
Only load WooCommerce scripts on shop pages and checkout + cart
/**
* Optimize WooCommerce Scripts
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*/
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//remove generator meta tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
@ValeriiVasyliev
ValeriiVasyliev / repo-reset.md
Created April 25, 2022 04:23 — forked from heiswayi/repo-reset.md
GitHub - Delete commits history with git commands

First Method

Deleting the .git folder may cause problems in our git repository. If we want to delete all of our commits history, but keep the code in its current state, try this:

# Check out to a temporary branch:
git checkout --orphan TEMP_BRANCH

# Add all the files:
git add -A
@ValeriiVasyliev
ValeriiVasyliev / manage_columns_wp_admin.php
Created April 14, 2022 02:30 — forked from vishalkakadiya/manage_columns_wp_admin.php
Manage custom columns with sortable in WordPress Admin side
<?php
/*
* =================================================================================================
* Below both hooks works for custom post types.
* e.g. Suppose we have custom post-type name : Books
* @ref https://codex.wordpress.org/Plugin_API/Action_Reference/manage_$post_type_posts_custom_column
* =================================================================================================
*/