Skip to content

Instantly share code, notes, and snippets.

View ajgagnon's full-sized avatar
💻
typing some things

Andre Gagnon ajgagnon

💻
typing some things
View GitHub Profile
@ajgagnon
ajgagnon / machine.js
Created June 22, 2021 22:04
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@ajgagnon
ajgagnon / install-presto-player-core.php
Created June 9, 2021 20:59
Automatically Install Plugin From Repo Example
<?php
namespace PrestoPlayer\Pro\Services;
/**
* Install core plugin if not installed/activated
*/
class CoreInstaller
{
@ajgagnon
ajgagnon / woo-sl-licensing-fix.php
Created March 15, 2021 14:36
Fix licensing serving through woo-sl-licensing.
<?php
add_filter('WOOSL/API/get_downloadable_product_permission', function($permission, $download_id, $order_id) {
global $wpdb;
if (!$permission) {
if (!function_exists('wcs_get_subscriptions_for_order')) {
return $permission;
}
@ajgagnon
ajgagnon / woo-sl-cloudflare-fix.php
Created March 14, 2021 15:00
Use a hash instead of email to prevent issues with Cloudflare
<?php
$email_hash = function_exists( 'hash' ) ? hash( 'sha256', $downloadable_product_permission->user_email ) : sha1( $downloadable_product_permission->user_email );
$files[ $download_id ]['download_url'] = trailingslashit( get_option( 'home' )) .'?download_file='.$item_product_id.'&order='. $downloadable_product_permission->order_key .'&uid='. $email_hash .'&key='. $download_id;
module.exports = {
// Your LAN IP or host where you would want the live server
// Override this if you know your correct external IP (LAN)
// Otherwise, the system will always use localhost and will not
// work for external IP.
// This will also create some issues with file watching because for
// some reason, service-worker doesn't work on localhost?
// https://github.com/BrowserSync/browser-sync/issues/1295
// So it is recommended to change this to your LAN IP.
// If you intend to access it from your LAN (probably do?)
@ajgagnon
ajgagnon / ph-script-output.php
Created January 22, 2021 16:27
Script output example
<script>
(function(d, t, g) {
var ph = d.createElement(t),
s = d.getElementsByTagName(t)[0];
ph.type = 'text/javascript';
ph.async = true;
ph.charset = 'UTF-8';
ph.src = g + '&v=' + (new Date()).getTime();
s.parentNode.insertBefore(ph, s);
})(document, 'script', '<?php ph_the_api_url($post_id); ?>');
@ajgagnon
ajgagnon / disable-comments-approved-items.php
Created December 21, 2020 16:33
Disables comments on approved items (pages and images)
<?php
add_filter("rest_pre_insert_ph_comment_location", "wp_145_disable_comments_approved_items", 10, 2);
add_filter("rest_pre_insert_phw_comment_loc", "wp_145_disable_comments_approved_items", 10, 2);
function wp_145_disable_comments_approved_items($prepared_post, $request) {
// if the item is approved, disallow comments
if (PH()->approvals->getStatus($prepared_post->meta_input['parent_id'])) {
return new WP_Error('comments_disabled', 'You are not allowed to comment since this has been approved.');
}
@ajgagnon
ajgagnon / limit_website_tasks_for_clients.php
Last active December 16, 2020 17:03
Limit tasks for clients
<?php
add_filter("rest_pre_insert_phw_comment_loc", "wp_145_limit_tasks", 10, 2);
function wp_145_limit_tasks($prepared_post, $request) {
if(!$project_id = $prepared_post->meta_input['project_id']) {
return $prepared_post;
}
// if it's our project
<?php
class BunnyCDN {
public static function signUrl($url, $securityKey, $expiration_time = 3600, $user_ip = NULL, $is_directory_token = false, $path_allowed = NULL, $countries_allowed = NULL, $countries_blocked = NULL, $referers_allowed = NULL)
{
if (!$user_ip) {
$user_ip = self::getUserIP();
}
if (!is_null($countries_allowed)) {
@ajgagnon
ajgagnon / kyles-thing.php
Created October 5, 2020 18:06
Kyles thing
<?php
add_action( 'elementor/query/order_by_newdate', function( $query ) {
$query->set( 'meta_key', 'newdate' );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'DESC' );
} );