Skip to content

Instantly share code, notes, and snippets.

View pavr0m's full-sized avatar

Pavel Romanenko pavr0m

View GitHub Profile
@pavr0m
pavr0m / wpinstall.sh
Created March 7, 2023 15:44
Bash script for WP-CLI to download and install WordPress
#!/bin/bash
read -p "Enter the WordPress version you want to install (e.g., 5.9.1): " wp_version
wp core download --version="$wp_version"
read -p "Enter the name of the database for WordPress: " db_name
read -p "Enter the database username: " db_user
read -s -p "Enter the database password: " db_password
mysql -u root -p -e "CREATE DATABASE $db_name;"
mysql -u root -p -e "CREATE USER '$db_user'@'localhost' IDENTIFIED BY '$db_password';"
mysql -u root -p -e "GRANT ALL PRIVILEGES ON $db_name.* TO '$db_user'@'localhost';"
@pavr0m
pavr0m / css-helper-mixins.scss
Last active November 26, 2020 13:51
CSS helper mixins
@mixin placeholder-color( $color: #000, $font-style: normal, $font-size: inherit ) {
&::-webkit-input-placeholder { /* Chrome/Opera/Safari */
color: $color;
font-style: $font-style;
font-size: $font-size;
}
&::-moz-placeholder { /* Firefox 19+ */
color: $color;
font-style: $font-style;
@pavr0m
pavr0m / Observe_DOM_Mutatinos.js
Created May 31, 2020 21:34
Observe DOM Mutatinos in the document
var say = (msg)=>{
console.log(msg);
}
const observer = new MutationObserver( (mutationList)=>{
say(mutationList);
});
var targetNode = document.querySelector(nodeSelector);
@pavr0m
pavr0m / ApacheHTTPSConfig.md
Created May 24, 2020 07:10 — forked from nrollr/ApacheHTTPSConfig.md
Enable SSL in Apache for 'localhost' (OSX, El Capitan)

Enable SSL in Apache (OSX)

The following will guide you through the process of enabling SSL on a Apache webserver

  • The instructions have been verified with OSX El Capitan (10.11.2) running Apache 2.4.16
  • The instructions assume you already have a basic Apache configuration enabled on OSX, if this is not the case feel free to consult Gist: "Enable Apache HTTP server (OSX)"

Apache SSL Configuration

Create a directory within /etc/apache2/ using Terminal.app: sudo mkdir /etc/apache2/ssl
Next, generate two host keys:

@pavr0m
pavr0m / woo_checkout_prevent_scroll_to_notices.php
Created March 12, 2020 14:27
WooCommerce. Checkout - prevent scroll to notices.
<?php
add_action( 'wp_footer','woo_checkout_prevent_scroll_to_notices' );
function woo_checkout_prevent_scroll_to_notices() {
if ( function_exists( 'is_checkout' ) && is_checkout() ) :
ob_start();?>
<script>
jQuery( function($) {
$( document ).ajaxComplete( function() { // prevents woocommerce checkout.js scroll to notices on ajax update
@pavr0m
pavr0m / woo_prevent_submit_on_keypress.php
Last active March 12, 2020 13:52
WooCommerce. Checkout form - prevent submit on Enter key pressed.
<?php
add_action( 'wp_footer', 'woo_prevent_submit_on_keypress' );
function woo_prevent_submit_on_keypress() {
ob_start();?>
<script>
jQuery(function($){
$('form.woocommerce-checkout input').keydown(function (e) {
if (e. keyCode == 13) {
e.preventDefault();
@pavr0m
pavr0m / wp_change_text_with_gettext.php
Created March 11, 2020 12:39
Wordpress. Change text using gettext function.
add_filter( 'gettext', 'change_woocommerce_return_to_shop_text', 20, 3 );
function change_woocommerce_return_to_shop_text( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Return to cart' :
$translated_text = __( 'Back to Shop', 'woocommerce' );
case 'Return to basket' :
$translated_text = __( 'Back to Shop', 'woocommerce' );
break;
}
return $translated_text;
@pavr0m
pavr0m / woo_add_coupon.php
Created March 11, 2020 11:28
WooCommerce. Add coupon.
/**
* Add coupon automatically: disabled
*/
add_action('woocommerce_before_checkout_form', 'preorder_coupon');
function preorder_coupon() {
if ( in_array( 'discount', WC()->cart->get_applied_coupons() ) ) {
return;
} else {
WC()->cart->apply_coupon('discount');
@pavr0m
pavr0m / wp_ajax_callback_template.php
Last active March 12, 2020 13:47
Wordpress template ajax callback
<?php
/**
* Template ajax callback
*/
add_action( 'wp_ajax_callback', 'callback' );
add_action( 'wp_ajax_nopriv_callback', 'callback' );
function callback($a) {
$data = dosomething($a);
@pavr0m
pavr0m / phpzip.php
Created March 2, 2020 21:55
Zip files recursively using ZipArchive class
<?php
$rootPath = realpath('folder');
$zip = new ZipArchive();
$zip->open('archive.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY
);