Skip to content

Instantly share code, notes, and snippets.

View autocircled's full-sized avatar

Moktadir Rahman autocircled

  • TIC Limited
  • Rajshahi, bangladesh
  • 22:29 (UTC +06:00)
View GitHub Profile
@autocircled
autocircled / wp-cronjob.php
Created March 29, 2025 05:51
WordPress custom scheduled event
public static function init() {
add_action( 'init', array( __CLASS__, 'trtrtr') );
add_action( 'weweweaaewa', array( __CLASS__, 'rererere') );
add_filter( 'cron_schedules', array( __CLASS__, 'ac_custom_cron_schedules') );
}
public static function ac_custom_cron_schedules( $schedules ) {
$schedules['every_minute'] = array(
'interval' => 60, // 60 সেকেন্ড = 1 মিনিট
<?php
function write_log( ...$data ) {
if ( true === WP_DEBUG ) {
$backtrace = debug_backtrace();
$backtrace = array_shift( $backtrace );
$output['backtrace'] = $backtrace['file'] . ':' . $backtrace['line'];
foreach ( $data as $key => $value ) {
@autocircled
autocircled / logger.js
Created January 17, 2025 06:18
use console.log with stack trace
const logger = new Proxy((...message) => {
console.log(...message);
}, {
apply(target, thisArg, argumentsList) {
const stack = new Error().stack.split('\n').slice(2, 4).join('\n');
console.log('Logger called with arguments:', argumentsList);
console.log('Stack Trace:\n', stack);
return target(...argumentsList);
}
});
@autocircled
autocircled / functions.php
Created December 23, 2024 11:20
WordPress Child Theme Cache Buster
define('DSK_VERSION', '1.1.4');
$cache_buster = DSK_VERSION;
if ( defined( 'WP_DEBUG' ) && WP_DEBUG) {
$cache_buster = date("YmdHi", filemtime( get_stylesheet_directory() . '/css/main.css'));
}
function my_scripts_and_styles(){
global $cache_buster;
wp_enqueue_style( 'main-style', get_stylesheet_directory_uri() . '/css/main.css', array( 'woodmart-style' ), $cache_buster, 'all' );
}
function qw( $data ) {
if ( true === WP_DEBUG ) {
$backtrace = debug_backtrace();
$backtrace = array_shift( $backtrace );
$output['backtrace'] = $backtrace['file'] . ':' . $backtrace['line'];
$output['data'] = $data;
error_log( print_r( $output, true ) );
@autocircled
autocircled / bd-districts.php
Created August 22, 2024 15:16
For woocommerce checkout
<?php
add_filter('woocommerce_states', 'stylish_woocommerce_states');
function stylish_woocommerce_states($states) {
$states['BD'] = array(
'BD-05' => 'Bagerhat - বাগেরহাট',
'BD-01' => 'Bandarban - বান্দরবান',
'BD-02' => 'Barguna - বরগুনা',
'BD-06' => 'Barishal - বরিশাল',
'BD-07' => 'Bhola - ভোলা',
'BD-03' => 'Bogura - বগুড়া',
#!/bin/sh
#ionCube Extension installer for PHP 8.1 LiteSpeed Servers
wget https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
tar -zxvf ioncube_loaders_lin_x86-64.tar.gz
cp ioncube/ioncube_loader_lin_8.1.so /usr/lib/php/20200930/
rm ioncube_loaders_lin_x86-64.tar.gz
rm -rf ioncube
#sudo echo "extension=ioncube_loader_lin_8.1.so" >> /usr/local/lsws/lsphp81/etc/php/8.1/mods-available/01-ioncube.ini
sudo echo "zend_extension=ioncube_loader_lin_8.1.so" >> /etc/php/8.1/cli/php.ini
sudo systemctl restart lsws
@autocircled
autocircled / functions.php
Created December 20, 2023 12:47
Checkout page customize
// Make postal code optional
add_filter( 'woocommerce_default_address_fields', 'customize_extra_fields', 1000, 1 );
function customize_extra_fields( $address_fields ) {
$address_fields['postcode']['required'] = false; //Postcode
return $address_fields;
}
// Hide checkout fields
function reorder_billing_fields($fields) {
$billing_order = [
@autocircled
autocircled / demo.php
Created September 7, 2022 11:11
Recursively remote call using wp_remote_post
<?php
// Increase day by 1 to call the API for next day
$current_date = date( 'Y-m-d', strtotime( $current_date . '+1 day' ));
// Checking if everything is working fine
$file = plugin_dir_path( __FILE__ ) . '/text.txt'; // This line is not tested yet! So careful before use
file_put_contents( $file, $this->fetched_day_counter . ': Current Date: ' . $current_date . "\n\n", FILE_APPEND );
// Ready for the next day
$this->fetched_day_counter += 1;