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 / woocommerce-single-product.php
Created August 18, 2020 08:34
WooCommerce Single Product Page Default Actions
<?php
/**
* @snippet List of Default Actions @ WooCommerce Single Product
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @updated WooCommerce 4.0
* @donate $9 https://businessbloomer.com/bloomer-armada/
*/
// Before content
@ValeriiVasyliev
ValeriiVasyliev / acf5_get_acf_field_groups_by_cpt.php
Created May 13, 2020 19:54 — forked from sunriseweb/acf5_get_acf_field_groups_by_cpt.php
Get ACF (Advanced Custom Field) field groups with their fields for a given custom post type. i.e. where the ACF location rule is "post_type == cpt".
/**
* Returns an array of field groups with fields for the passed CPT, where field group ACF location rule of "post_type == CPT" exists.
* - each field group points at an array of its fields, in turn pointed at an array of that field's detailed information:
* - array of info for each field [ ID, key, label, name, type, menu_order, instructions, required, id, class, conditional_logic[array()], etc. ]
*
* @since 1.0.0
*/
function get_acf_field_groups_by_cpt($cpt) {
// need to create cache or transient for this data?
@ValeriiVasyliev
ValeriiVasyliev / .htaccess
Created May 5, 2020 09:44 — forked from siffring/.htaccess
htaccess to password protect a specific server
# ----------------------------------------------------------------------
# Password protect staging server
# Use one .htaccess file across multiple environments
# (e.g. local, dev, staging, production)
# but only password protect a specific environment.
# ----------------------------------------------------------------------
SetEnvIf Host staging.domain.com passreq
AuthType Basic
AuthName "Password Required"

Trip sorter

You are given a stack of boarding cards for various transportation types that will take you from a point A to point B via several stops on the way. All of the boarding cards are out of order and you don't know where your journey starts, nor where it ends. Each boarding card contains information about seat assignment, and means of transportation (such as flight number, bus number etc).

Write an API that lets you sort this kind of list and present back a description of how to complete your journey.

For instance the API should be able to take an unordered set of boarding cards, provided in a format defined by you, and produce this list:

  1. Take train 78A from Madrid to Barcelona. Sit in seat 45B.
  2. Take the airport bus from Barcelona to Gerona Airport. No seat assignment.
@ValeriiVasyliev
ValeriiVasyliev / aux-functions.php
Created August 8, 2019 08:25 — forked from eduwass/duplicate-post.php
Programmatically duplicating a WordPress post
<?php
/**
* Duplicates a post & its meta and it returns the new duplicated Post ID
* @param [int] $post_id The Post you want to clone
* @return [int] The duplicated Post ID
*/
function duplicate($post_id) {
$title = get_the_title($post_id);
$oldpost = get_post($post_id);
@ValeriiVasyliev
ValeriiVasyliev / acf-get-field-key.php
Created July 4, 2019 08:30 — forked from mcguffin/acf-get-field-key.php
WordPress Advanced Custom Fields get field key from field name
<?php
/**
* Get field key for field name.
* Will return first matched acf field key for a give field name.
*
* ACF somehow requires a field key, where a sane developer would prefer a human readable field name.
* http://www.advancedcustomfields.com/resources/update_field/#field_key-vs%20field_name
*
* This function will return the field_key of a certain field.

Optimizations and enhancements for prestashop 1.6

Sometimes, prestashop turns very slow due to ads, and module recomendations. Here are some modifications to version 1.6 removing these things and speed up the admin panels. Enjoy and share your tricks about how optimize prestashop.

Modify Tools class

[https://github.com/PrestaShop/PrestaShop/blob/1.6.1.x/classes/Tools.php#L3351-L3356] Find the file /public/classes/Tools.php and modify as next:

public static function addonsRequest($request, $params = array())
@ValeriiVasyliev
ValeriiVasyliev / function.php
Created April 16, 2019 15:12 — forked from mattclements/function.php
Wordpress Disable Comments (add to function.php)
<?php
// Add to existing function.php file
// Disable support for comments and trackbacks in post types
function df_disable_comments_post_types_support() {
$post_types = get_post_types();
foreach ($post_types as $post_type) {
if(post_type_supports($post_type, 'comments')) {
remove_post_type_support($post_type, 'comments');
@ValeriiVasyliev
ValeriiVasyliev / wp-config.php
Created January 23, 2019 17:41
Set WordPress site URL in the config file instead of the database
<?php
// WordPress stores the site URL in the database by default (which I have never
// understood), and it's a pain to have to type out the UPDATE SQL or search in
// phpMyAdmin to change it. This is a simple way to put the URL into
// wp-config.php instead.
// Note that you will still need to update any URLs that appear in the content,
// especially when you copy a database from a development site to production:
// https://gist.github.com/davejamesmiller/a8733a3fbb17e0ff0fb5
@ValeriiVasyliev
ValeriiVasyliev / Wordpress Rewrite Rules Example
Created January 18, 2019 15:29 — forked from benvisser/Wordpress Rewrite Rules Example
Sample Wordpress rewrite rule filters
///////////////////////////////////
// Rewrite Rules
///////////////////////////////////
//rewrite rules
add_filter('rewrite_rules_array','wp_insertMyRewriteRules');
add_filter('query_vars','wp_insertMyRewriteQueryVars');
add_filter('init','flushRules');
// Remember to flush_rules() when adding rules