Skip to content

Instantly share code, notes, and snippets.

View raazon's full-sized avatar
❤️
Eat - Sleep - Code

Razon Komar Pal raazon

❤️
Eat - Sleep - Code
View GitHub Profile
@raazon
raazon / generate-unique-username.php
Created September 18, 2020 20:25
Generate a unique username in WordPress
<?php
/**
* Recursive function to generate a unique username.
*
* If the username already exists, will add a numerical suffix which will increase until a unique username is found.
*
* REF: https://gist.github.com/philipnewcomer/59a695415f5f9a2dd851deda42d0552f
*
* @param string $username
*
@raazon
raazon / wordpress_post_query_result_count.php
Last active October 20, 2021 22:34
WooCommerce result count / Post result count
<?php
/**
* WorpPress post query result
* @since 1.0.0
* @author Razon Komar Pal
* @return string - like: Showing 1–12 Of 29 Results
*/
if (get_query_var('paged')) {
@raazon
raazon / admin-access-restrict.php
Created September 2, 2020 06:12
Restrict access to admin pages
<?php defined('ABSPATH') || die('Cheatin&#8217; uh?'); // Cannot access pages directly.
/**
* Restrict access to admin pages
* @author Razon Kommar Pal
*/
add_action('admin_init', 'slug_restrict_access_for_specific_path');
function slug_restrict_access_for_specific_path()
{
$requested_url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
@raazon
raazon / ngrok.command
Created September 1, 2020 08:44
Ngrok Documentation https://ngrok.com/docs
#https://ngrok.com/docs#http-bind-tls
#https://ngrok.com/docs#http-host-header
ngrok http -bind-tls=false -host-header=rewrite wp.local:80
@raazon
raazon / wp-cli-cheat-sheet.sh
Last active August 20, 2020 19:15
WordPress quick install via WP-CLI and WP-CLI cheat sheet
# WordPress WP-CLI cheat sheet
UPCOMING MORE...
@raazon
raazon / heartbeat-api.js
Created August 18, 2020 05:50
How to enable WordPress Heartbeat API
(function ($) {
"use strict";
$(document).ready(function () {
// Sending Data to the Server
jQuery(document).on('heartbeat-send', function (event, data) {
// Add additional data to Heartbeat data.
data.myplugin_customfield = 'some_data';
});
@raazon
raazon / woocommerce-get-variation-details.php
Last active June 23, 2020 17:09
WooCommerce get variation details by product id
<?php
$product_id = 10;
$product = wc_get_product($product_id);
$variations = $product->get_available_variations();
$variation_names = array();
foreach ( $variations as $variation ) {
// Get attribute taxonomies
$taxonomies = array_keys($variation['attributes']);
// Loop through variation taxonomies to get variation name and slug
@raazon
raazon / filter-content.php
Last active May 17, 2020 04:31
WordPres filter content if find any certain word
<?php
/**
* Filter content if find any certain word.
* @author Razon Komar Pal
*/
function ic_filter_content_sample($content)
{
// for single post
if (is_single()) {
$new_content = '<p>This is added to the bottom of all post and page content</p>';
@raazon
raazon / functions.php
Last active March 12, 2020 07:55
Woocommerce hide price and add to cart for logged out user programmatically
<?php
/**
* @snippet Woocommerce hide price & add to cart if not logged in
* @author Razon Komar pal
*/
add_action('init', 'woo_hide_price_add_cart_for_not_logged_in_user');
add_action('template_redirect', 'woo_hide_price_add_cart_for_not_logged_in_user');
function woo_hide_price_add_cart_for_not_logged_in_user()
{
@raazon
raazon / breadcrumbs-functions.php
Last active February 21, 2020 10:05
Custom WordPress breadcrumbs no plugin
<?php defined('ABSPATH') || die('Cheatin&#8217; uh?'); // Cannot access pages directly.
/************************************************************************************************************************
* BREADCRUMBS
*************************************************************************************************************************/
function the_breadcrumb()
{
$showOnHome = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show
$delimiter = '&raquo;'; // delimiter between crumbs