Skip to content

Commit

Permalink
Merge pull request #49 from gumroad/product-url-support
Browse files Browse the repository at this point in the history
Add product URL support
  • Loading branch information
vishaltelangre authored May 3, 2021
2 parents 0695173 + a9afebd commit 299235d
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 33 deletions.
22 changes: 14 additions & 8 deletions gumroad/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@
Contributors: karloscarweber, pderksen, nickyoung87, gumroad
Tags: gumroad, gumroad product pages, gumroad overlay, gumroad embed, ecommerce, e-commerce, pdf, javascript, overlay, embed
Requires at least: 3.9
Tested up to: 4.9.6
Stable tag: 2.1
Tested up to: 5.7.1
Stable tag: 3.0.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Make your Gumroad products available for purchase right within WordPress.

== Description ==

This plugin lets you embed Gumroad into your website, using our Overlay and Embed widgets: https://gumroad.com/widgets
This plugin lets you embed Gumroad into your website, using our Overlay and Embed widgets: https://gumroad.com/widgets.

Zero coding knowledge is required. Once installed, all links to Gumroad will automatically open the Gumroad Overlay (lightbox popup).

For more information on how this plugin works, you can see a video on our Overlay here: https://www.youtube.com/watch?v=u80Ey6lSRyE
For more information on how this plugin works, you can see a video on our Overlay here: https://www.youtube.com/watch?v=u80Ey6lSRyE.

You can also use shortcodes:

Basic overlay example: `[gumroad id="DviQY"]`
Basic overlay example: `[gumroad url="https://gumroad.com/l/DviQY"]`

Basic embed example: `[gumroad id="GAPdj" type="embed"]`
Basic embed example: `[gumroad url="https://gumroad.com/l/GAPdj" type="embed"]`

Overlay that will automatically show the payment form: `[gumroad id="DviQY" text="Purchase Item" wanted="true"]`
Overlay that will automatically show the payment form: `[gumroad url="https://gumroad.com/l/DviQY" text="Purchase Item" wanted="true"]`

The ID ("GAPdJ") is the same as your Gumroad product URL ("gumroad.com/l/GAPdJ"). See the full documentation in Settings > Gumroad after the plugin is activated.
Overlay for an affiliated product: `[gumroad url="https://gumroad.com/a/919237747/llNDe" type="overlay"]`

See the full documentation in Settings > Gumroad after the plugin is activated.

== Installation ==

Expand Down Expand Up @@ -69,6 +71,10 @@ See the official Gumroad [overlay](https://gumroad.com/overlay) or [embed](https

== Changelog ==

= 3.0.0 - April 30, 2021 =

* Add support for specifying both regular and affiliated product URLs in Gumroad Block as well as short codes.

= 1.2.4 - January 30, 2019 =

* Add Gutenberg Blocks
Expand Down
Binary file added gumroad/assets/images/gumroad-wp-007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion gumroad/dist/blocks.build.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions gumroad/includes/misc-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
*/
function gum_link( $args ) {
$url = 'https://gum.co/' . $args['id'];
$url = $args['url'];
$wanted = '';
$button = '';

Expand All @@ -34,7 +34,7 @@ function gum_link( $args ) {
*
*/
function gum_overlay( $args ) {
$url = 'https://gum.co/' . $args['id'];
$url = $args['url'];
$wanted = '';
$button = '';

Expand All @@ -55,8 +55,8 @@ function gum_overlay( $args ) {
* @since 1.1.0
*
*/
function gum_embed( $id ) {
return sprintf( '<div class="gumroad-product-embed" data-gumroad-product-id="%s"></div>', esc_attr( $id ) );
function gum_embed( $args ) {
return sprintf( '<div class="gumroad-product-embed"><a href="%s"></a></div>', esc_attr( $args['url'] ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion gumroad/includes/scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function gum_post_scanner( $post_object ) {
function scanner( $post_content ) {

// counts to see if we find any gumroad product links.
if (count(preg_grep('/(gumroad.com\/l\/[[:alnum:]]|gum.co\/[[:alnum:]])/', explode("\n", $post_content))) > 0) {
if (count(preg_grep('/(gumroad.com\/a\/[[:alnum:]]+\/[[:alnum:]]|gumroad.com\/l\/[[:alnum:]]|gum.co\/[[:alnum:]])/', explode("\n", $post_content))) > 0) {
gum_load_js('overlay');
}
if (count(preg_grep('/(class=\"gumroad-product-embed\")/', explode("\n", $post_content))) > 0) {
Expand Down
15 changes: 13 additions & 2 deletions gumroad/includes/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function gum_gumroad_shortcode( $attr ) {

$defaults = array(
'id' => '',
'url' => '',
'type' => 'none', // none, overlay, embed
'class' => '',
'text' => 'I want this!',
Expand All @@ -33,11 +34,21 @@ function gum_gumroad_shortcode( $attr ) {

$attr = array_merge( $defaults, $attr );

if( ! empty( $id ) ) {
if( ! empty( $id ) || ! empty( $url ) ) {

// link behaviour
if ( ! empty( $url ) ) {
// Embed widget doesn't work with alias domain URLs
$attr['url'] = str_replace('gum.co/a/', 'gumroad.com/a/', $attr['url']);
$attr['url'] = str_replace('gum.co/', 'gumroad.com/l/', $attr['url']);
}

if ( empty( $attr['url'] ) && ! empty( $id ) ) {
$attr['url'] = 'https://gumroad.com/l/' . $id;
}

if ( $type == 'embed') { // Embed
$html = gum_embed( $id );
$html = gum_embed( $attr );
} else if ( $type == 'overlay' ) { // Overlay
$html = gum_overlay( $attr );
} else { // Default
Expand Down
2 changes: 1 addition & 1 deletion gumroad/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wp-gumroad",
"version": "2.1.0",
"version": "3.0.0",
"private": true,
"scripts": {
"start": "cgb-scripts start",
Expand Down
9 changes: 7 additions & 2 deletions gumroad/src/gumroad-block/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const {

const gumroadURL = 'https://gumroad.com/l/demo';
const defaultID = 'demo';
const gumroadURLRegex = /(https:\/\/gumroad\.com\/l\/)|(https:\/\/gumroad\.com\/)|(https:\/\/gum\.co\/l\/)|(https:\/\/gum\.co\/)/g;
const gumroadURLRegex = /(https:\/\/gumroad\.com\/a\/[[:alnum:]]+\/)|(https:\/\/gumroad\.com\/l\/)|(https:\/\/gumroad\.com\/)|(https:\/\/gum\.co\/)/g;

class GumControls extends Component {
constructor( props ) {
Expand Down Expand Up @@ -223,6 +223,11 @@ registerBlockType( 'gumroad/gumroad-block', {

var urlString = url, wantedString = '', classesString = classes;

// Embed widget doesn't work with alias domain URLs
urlString = urlString
.replace("gum.co/a/", "gumroad.com/a/")
.replace("gum.co/", "gumroad.com/l/");

// Wanted
if (wanted == 'true' || wanted == true) {
wantedString = '?wanted=true';
Expand All @@ -237,7 +242,7 @@ registerBlockType( 'gumroad/gumroad-block', {
if ( type == 'embed' ) {

return ( // return if link behavior normal
<div class="gumroad-product-embed" data-gumroad-product-id={"" + id + ""}></div>
<div class="gumroad-product-embed"><a href={urlString}></a></div>
)
} else if ( type == 'overlay' ) { // overlay links

Expand Down
Loading

0 comments on commit 299235d

Please sign in to comment.