Skip to content

Instantly share code, notes, and snippets.

@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;
@patrickposner
patrickposner / functions.php
Created August 31, 2022 15:18
Simply Static - Run static exports daily with WP-Cron
<?php
register_activation_hook( __FILE__, 'ssp_setup_static_daily_export_cron' );
/**
* Setup a cron job to run daily.
*
* @return void
*/
function ssp_setup_static_daily_export_cron() {
if ( ! wp_next_scheduled( 'ssp_static_export_daily_cron' ) ) {
@patrickposner
patrickposner / functions.php
Created August 29, 2022 14:56
Filr add custom columns with example.
<?php
// First we add the titles for the columns.
add_filter( 'filr_header_columns', function( $columns ) {
// You can add as many columns as you like here.
$columns['purchase-order-number'] = array(
'title' => esc_html__( 'Purchase Order Number', 'textdomain' ),
'hide' => 'off',
);
@patrickposner
patrickposner / functions.php
Last active March 30, 2023 07:34
Simply Static: Export all pages with shortcode in Single Export
<?php
add_filter( 'ssp_single_export_additional_urls', function ( $related_urls ) {
global $wpdb;
// Get all pages that have a recent posts shortcode.
$page_ids = $wpdb->get_row( "SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%[recent_posts AND post_type='page'", ARRAY_A );
foreach ( $page_ids as $id ) {
$related_urls[] = get_permalink( $id );
@patrickposner
patrickposner / functions.php
Last active July 20, 2022 07:55
Filr: Send e-mail before file expires.
<?php
add_action( 'filr_before_check_expire_date', function( $expiration_date, $today ) {
$difference = $expiration_date->diff( $today );
// Get difference in days.
if ( $difference->d <= 2 ) {
// prepare and send the e-mail.
$to = 'you@company.com';
$subject = 'File will expire in 2 days.';
@patrickposner
patrickposner / functions.php
Created July 7, 2022 13:23
Allow uploading XML files to media library
<?php
add_filter('upload_mimes', 'custom_upload_xml');
function custom_upload_xml($mimes) {
$mimes = array_merge($mimes, array('xml' => 'application/xml'));
return $mimes;
}
@patrickposner
patrickposner / functions.php
Created June 23, 2022 09:21
Fix canoncials on Simply Static exported static website
<?php
add_filter('ss_match_tags', function( $match_tags ) {
$match_tags['link'] = array( 'href' );
return $match_tags;
});
@patrickposner
patrickposner / functions.php
Created June 23, 2022 09:13
Fire webhook after static export is done.
<?php
add_action('ss_after_cleanup', function(){
// Get options from Simply Static.
$options = get_option( 'simply-static' );
$basic_auth = $options['http_basic_auth_digest'];
// Prepare URL and data.
$url = 'https://test.com';
$data = [];
@patrickposner
patrickposner / functions.php
Last active June 22, 2022 12:05
Adding a custom description for WooCommerce Attributes.
<?php
function add_description_attribute_field() {
$id = isset( $_GET['edit'] ) ? absint( $_GET['edit'] ) : 0;
$value = $id ? get_option( "wc_attribute_custom_description-$id" ) : '';
?>
<tr class="form-field">
<th scope="row" valign="top">
<label for="custom-description"><?php esc_html_e('Description', ''); ?></label>
</th>