Skip to content

Instantly share code, notes, and snippets.

@robertuniqid
robertuniqid / example.php
Last active June 27, 2022 09:58
WordPress Remote Users Sync - use Action Scheduler during WooCommerce checkout
<?php
// Replace my_prefix with something else, includes AS Group
/**
* @param string $endpoint
* @param \Wprus_Api_Abstract $object
*/
function _my_prefix_wp_notify_remote_after_init_notification_hooks( $endpoint, $object ) {
if( !function_exists( 'as_enqueue_async_action' ) )
@robertuniqid
robertuniqid / example.php
Created June 25, 2022 10:24
WordPress WooCommerce Subscriptions, Action Scheduler list actions as metabox
<?php
add_action( 'add_meta_boxes', function() {
add_meta_box(
'wc-subscription-scheduled-actions',
__( 'WC Subscription Scheduled Actions' ),
function( $post ) {
$actions = as_get_scheduled_actions( [
'args' => [
'subscription_id' => $post->ID
@robertuniqid
robertuniqid / script.js
Created February 16, 2022 02:01
Fix : Request listener already exists for zoid_allow_delegate_three_domain_secure on domain * for wildcard window
// PayPal, please don't change the name of this.
if( typeof window.paypal.__internal_destroy__ === 'function' )
window.paypal.__internal_destroy__();
@robertuniqid
robertuniqid / example.php
Created January 29, 2022 21:30
Elementor Color Element to CSS value
<?php
function _lorem_ipsum_setting_to_css_variable_color( $settings, $index ) {
if( isset( $settings[ '__globals__' ] ) && isset( $settings[ '__globals__' ][ $index ] ) ) {
if( strpos( $settings[ '__globals__' ][ $index ],'?id=' ) !== false ) {
$identifier = substr( $settings[ '__globals__' ][ $index ], strpos( $settings[ '__globals__' ][ $index ],'?id=' ) + 4 );
return 'var( --e-global-color-' . $identifier . ' )';
}
}
@robertuniqid
robertuniqid / file-in-wp-root.php
Last active February 22, 2023 15:21
Clear WP Rocket Cache & WP Rocket Cloudflare automatically if the Frontpage doesn't display all the recent posts. Requires adjustments on per site basis, but, the idea is here, ensure the Cloudflare cache is reset properly.
<?php
// Load WordPress.
require( 'wp-load.php' );
$site_url = get_site_url();
$latest_5_post_ids = get_posts([
'posts_per_page' => 5,
'paged' => 1,
'post_type' => [ 'post' ],
@robertuniqid
robertuniqid / code.php
Created September 23, 2021 17:24
PHP - 2 Letter ISO Country Code To 3 Letter ISO Currency
<?php
return [
'AF' => 'AFN',
'AL' => 'ALL',
'DZ' => 'DZD',
'AS' => 'USD',
'AD' => 'EUR',
'AO' => 'AOA',
'AI' => 'XCD',
@robertuniqid
robertuniqid / sample.php
Created September 23, 2021 09:21
Romania Validate CNP - PHP
<?php
// The goal is to prevent human error, not cheating the system.
class Sample {
private static $_cnpValidationConstant = "279146358279";
public static function isValidCNP( $cnp ) {
$cnp = intval( $cnp );
@robertuniqid
robertuniqid / file.txt
Created June 1, 2021 23:17
backup, reddit post.
Some context :
I need to do instant push notifications with one-signal when someone posts a comment, and I must ensure there's no compromise on the speed, it seems to add to the load time from 1 device to 5 devices receiving notifications, and gets slower and slower as I'm going to 100 devices, because of the way these tokens work, a user could artifically get 1000s of device tokens in onesignal ( assumption ), cleaning them up trough a cron job would be another thing I'll tackle, but later ( if someone gets here with similar requirements, a heads up )
I'm looking for suggestions, or weak points in my logic, if anyone ever encountered this, or simply want to talk about it, maybe there's a better way of approaching this, or WP Core has something better available.
Why I want to use an Async Request :
I can't work with cron jobs, because I want this to happen instantly, I'm essentially turning 1 POST request into another GET request, my other option would be to have an infinite loop somewhere always happening,
@robertuniqid
robertuniqid / editable-mentions.js
Created May 10, 2021 21:27
Editable Mentions Attempt - eLearnCommerce.
eLearnCommerce.Library.Editablementions = {
configuration : {
container_class : 'wpep-discussion-mention-item',
container_user_id_attr : 'data-wpep-mention-user-id',
image_class : 'wpep-discussion-mention-item-image',
name_class : 'wpep-discussion-mention-item-name'
},
_currentXHRSearch : false,
@robertuniqid
robertuniqid / code.php
Created April 14, 2021 11:53
WordPress Deepl Locale -> Lang Map
<?php
if( !function_exists( 'wp_get_available_translations') )
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
$deepl = [
"BG", "CS", "DA", "DE", "EL", "ES", "ET", "FI", "FR", "HU",
"IT", "JA", "LT", "LV", "NL", "PL", "RO", "RU", "SK", "SL", "SV", "ZH",
"EN-GB", "EN-US",
"PT-PT", "PT-BR"