Skip to content

Instantly share code, notes, and snippets.

@MCKLtech
Created November 25, 2020 20:27
Show Gist options
  • Save MCKLtech/d2dac5e4e4d3b0d82b1885790c40a467 to your computer and use it in GitHub Desktop.
Save MCKLtech/d2dac5e4e4d3b0d82b1885790c40a467 to your computer and use it in GitHub Desktop.
<?php
/*
* Plugin Name: Groundhogg - Loom Replacements
* Plugin URI:
* Description: Adds a replacement code to embed Loom videos in Groundhogg Emails
* Version: 1.0
* Author: Colin Longworth
* Author URI: http://www.wooninja.io
* Developer: Colin Longworth
* Developer URI: http://www.wooninja.io
* Text Domain: groundhogg-loom
* License: GPLv2
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
try {
$loom = new GroundhoggLoom();
}
catch(\Exception $e) {
error_log($e->getMessage());
}
class GroundhoggLoom {
public function __construct()
{
add_filter('groundhogg/replacements/defaults', [$this, 'add_replacements'], 99, 1);
}
public function add_replacements($replacements)
{
$replacements[] = [
'code' => 'loom',
'callback' => [$this, 'loom'],
'description' => _x( 'Inserts a Loom video from the specified link. Usage {loom.https://www.loom.com/share/xxx}', 'replacement', 'groundhogg' ),
];
return $replacements;
}
/**
* Return the Loom Embed Code
*
* @param $contact_id int
* @param $arg string the meta key
*
* @return mixed|string
*/
function loom( $arg, $contact_id ) {
$arg = apply_filters('groundhogg/loom/arg/pre', $arg, $contact_id);
$link = apply_filters('groundhogg/loom/link', str_replace("www.loom.com/share", "www.loom.com/embed", $arg), $contact_id);
$html = '<div style="position: relative; padding-bottom: 82%; height: 0;"><iframe src="'.$link.'" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe></div>';
return apply_filters('groundhogg/loom/html', $html, $link, $arg, $contact_id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment