Skip to content

Instantly share code, notes, and snippets.

@patrickposner
patrickposner / functions.php
Created February 5, 2024 15:50
Klar Tracking in WooCommerce
<?php
// Klar:sendOrderEvent
add_action( 'woocommerce_thankyou', function ( $order_id ) {
?>
<script>
(function () {
window._k_q = window._k_q || [];
window._k_q.push(["Klar:sendOrderEvent", {
orderId: <?php echo esc_html( $order_id ); ?>,
@patrickposner
patrickposner / functions.php
Created July 26, 2023 17:33
InstaWP - Update temporary directory.
<?php
add_action( 'admin_init', function() {
// Get Simply Static options.
$options = get_option('simply-static');
// Check if directory exists, if not, create it.
$upload_dir = wp_upload_dir();
$temp_dir = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'simply-static' . DIRECTORY_SEPARATOR . 'temp-files';
@patrickposner
patrickposner / lemonsqueezy-modal.html
Created June 3, 2023 10:32
lemonsqueezy-modal.html
<p>
<a href="https://simply-cdn.lemonsqueezy.com/checkout/buy/your-api-key?embed=1&amp;" class="lemonsqueezy-button">
Pay now!
</a>
<script src="https://app.lemonsqueezy.com/js/lemon.js" defer=""></script>
</p>
@patrickposner
patrickposner / functions.php
Created April 17, 2023 13:00
Freemius Basic Auth License Activation
<?php
/* FREEMIUS API BASIC AUTH WORKAROUND */
add_filter( 'http_request_args', 'my_http_request_args_filter', 1, 2 );
add_filter( 'http_request_args', 'my_http_request_args_filter', 9999, 2 );
function my_http_request_args_filter( $parsed_args, $url ) {
if ( false === strpos( $url, '://api.freemius.com' ) ) {
return $parsed_args;
}
document.addEventListener("DOMContentLoaded", function () {
const language_links = document.querySelectorAll('.wpml-ls-link');
for (const language_link of language_links) {
language_link.addEventListener('click', function handleClick(event) {
event.preventDefault();
let languages = this.getElementsByClassName('wpml-ls-native');
for (const language of languages) {
@patrickposner
patrickposner / functions.php
Last active October 8, 2022 09:31
Simply Static: Run a full static export daily.
<?php
register_activation_hook( __FILE__, 'ss_setup_static_daily_export_cron' );
/**
* Setup a cron job to run daily.
*
* @return void
*/
function ss_setup_static_daily_export_cron() {
@patrickposner
patrickposner / workflow.yml
Created October 8, 2022 07:54
Worfklow to export from Simply Static to AWS S3
name: Upload Website
on:
repository_dispatch:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
@patrickposner
patrickposner / functions.php
Created September 26, 2022 14:31
Remove Emoji scripts from WordPress
<?php
add_action( 'init', function() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
});
@patrickposner
patrickposner / functions.php
Created September 15, 2022 09:28
Fix Freemius API with existing Basic Auth
<?php
add_filter( 'http_request_args', 'freemius_http_request_args_filter', 1, 2 );
add_filter( 'http_request_args', 'freemius_http_request_args_filter', 9999, 2 );
function freemius_http_request_args_filter( $parsed_args, $url ) {
if ( false === strpos( $url, '://api.freemius.com' ) ) {
return $parsed_args;
}
@patrickposner
patrickposner / form-handler.php
Created September 2, 2022 12:43
Send Mail from Webhook with plain PHP
<?php
// Check if the webhook should be fired.
if ( ! isset( $_GET['mailme'] ) ) {
return;
}
// Check if there is POST request.
if ( empty( $_POST ) ) {
return;