Giter VIP home page Giter VIP logo

getalby / lightning-publisher-wordpress Goto Github PK

View Code? Open in Web Editor NEW
20.0 6.0 10.0 3.12 MB

WordPress plugin to integrate Bitcoin Lightning payments (for Value 4 Value payments, paywalls and tipping)

Home Page: https://wordpress.org/plugins/bitcoin-lightning-publisher/

License: GNU General Public License v3.0

PHP 73.03% CSS 1.39% JavaScript 25.40% Shell 0.18%
bitcoin donations lightning-network paywall value4value wordpress wordpress-plugin

lightning-publisher-wordpress's Introduction

Bitcoin Lightning Publisher for WordPress

Lightning Publisher

Bitcoin Lightning Publisher is a Paywall, Donation and Value 4 Value plugin for WordPress to accept instant Bitcoin Lightning payments. It allows you to monetize any digital content with instant microtransactions and receive payments from your visitors directly to your preferred wallet - no need for expensive service providers.

The plugin is the easiest and most flexible plugin to sell your digital content and to receive donations or Value 4 Value payments. Using the Bitcoin Lightning Network you can create the best visitor experience with seamless one-click payments.

Features

Paywall to sell content

Sell any digital content (pay-per-post, pay-per-view, pay-per-download, etc.) with a highly configurable paywall

  • WebLN enabled by default for easy on-click payments
  • Add a paywall to posts and pages to easily charge for any published content
  • Crowdfund option: make the content freely available after a certain amount is received
  • Time-in option: keep the article freely available for a certain time and then enable the paywall after that
  • Time-out option: make the article freely available after a certain time
  • Configure the price in Satoshis, EUR, USD, or GBP (with real-time exchange rate)
  • Configure the paywall with a shortcode ([lnpaywall])
  • Or configure the paywall with a Gutenberg Block
  • Integrate with other tools and plugins like membership tools to control if the paywall should be enabled (see Paywall Hook section)

Donation/Value4Value payments

The plugin comes with various options to receive donations and Value 4 Value payments.

  • Gutenberg block for a donation widget
  • Donation widget for themes
  • Enable Value 4 Value tags for your website and feeds:
  • Enable the Lightning meta tag to allow users to send payments (Value 4 Value)
  • Enable the podcast:value tag in your RSS feed to receive payments for your podcast

Lightning Node connections

Connect to your existing Bitcoin Lightning node or simply create a new Alby account to instantly receive Lightning payments.

REST-API for full advanced custom usage

For more advanced, custom Lightning integrations you can use the REST API to create and verify invoices. The API also provides a LNURL-pay endpoint. See the REST-API section for details.

Requirements

Demo

Here quick Demo videos showing how to setup and use the plugin:

Installation

Install from the WordPress Plugin directory or:

Download the zip from the latest release and install/activate it through the WordPress Plugin admin panel.

To build the plugin yourself: clone the repository and install the dependency using Composer

git clone https://github.com/getAlby/lightning-publisher-wordpress.git
cd lightning-publisher-wordpress
composer install # (maybe you need to add `--ignore-platform-reqs` if it asks you to update PHP)

To build a .zip file of the WordPress plugin run:

./build.sh # this builds a `wordpress-lightning-publisher.zip`

Then upload and activate the plugin through the WordPress Plugin admin panel.

Paywall Hook to have custom logic when to enable/disable the paywall

To integrate with other plugins or to write custom conditions on when the paywall should be enabled a hook can be used. This means you can use a custom PHP function to decide if content should be behind the paywall or not.

This for example allows you to make the content available for all users/subscribers but enable the paywall for all other users.

Example

you can add such functions anywhere in your code. e.g. in functions.php

// your function receives two arguments:
// 1. a boolean with the current check (true if the full content would be shown)
// 2. the ID of the post the user accesses
//
// return true if the full content should be shown or false to enable the paywall
function show_full_content_for_post($show_full_content, $post_id) {
  // Add your logic to check if the current user can see the post with ID $post_id

  // return true; // return true to show the full content (disable the paywall)

  // for example:
  // if the user has a subscription always show the full content.
  // otherwise let the plugin decide (e.g. show the full content if the user already had paid)
  if (user_has_a_subscription()) {
    return true;
  } else {
    return $show_full_content
  }
}

// Check out the `add_filter` documentation for more information: https://developer.wordpress.org/reference/functions/add_filter/
add_filter('wp_bln_has_paid_for_post', 'show_full_content_for_post', 10, 2);

Alternatively you can define a global function wp_bln_has_paid_for_post which gets called. Return true to disable the paywall and show the full content.

function wp_bln_has_paid_for_post($show_full_content, $post_id) {
  return true; // show full content - disable the paywall
}

Overriding template for unpaid button

Warning: Do not edit these files within the core plugin itself as they are overwritten during the upgrade process and any customizations will be lost. Use variable $plugin to access plugin options inside of the template file.

Required markup for custom button:

<div class="wp-lnp-wrapper">
    <button class="wp-lnp-btn">Custom labeled button</button>
</div>
Option 1

Copy file wp-content/plugins/lightning-publisher-wordpress/public/templates/paywall-button-unpaid.php to wp-content/themes/yourtheme/lightning-publisher-wordpress/paywall-button-unpaid.php

The copied file will now override the default template file.

Option 2

If you would prefer to place template file in a custom location, then you can use filter: bln_paywall_unpaid_button_template

  1. Copy file wp-content/plugins/lightning-publisher-wordpress/public/templates/paywall-button-unpaid.php to custom location, eg wp-content/themes/yourtheme/plugin-mods/paywall-button-unpaid.php
  2. Use filter bln_paywall_unpaid_button_template to override button template path. You can e.g. in functions.php
// your function receives 1 argument:
// $template_path string, absolute path to template file used to render the button template
//
// return HTML template
function update_bln_paywall_unpaid_button($template_path) {
    // Absolute path to template file
    $new_path = get_stylesheet_directory() . '/plugin-mods/paywall-button-unpaid.php';

    return $new_path;
}

// Check out the `add_filter` documentation for more information: https://developer.wordpress.org/reference/functions/add_filter/
add_filter( 'bln_paywall_unpaid_button_template', 'update_bln_paywall_unpaid_button' );

Shortcode

If you do not use the Gutenberg editor you can use the [lnpaywall] shortcode. The content after the shortcode will be behind the paywall. The following configuration options are possible:

  • amount
  • currency
  • description
  • button_text
  • total
  • timeout
  • timein

Example

[lnpaywall amount=2121]

Plugin folder structure

Folder structure is based on https://github.com/DevinVinson/WordPress-Plugin-Boilerplate

  • bln-publisher.php is the entrypoint of the plugin
  • includes is where functionality shared between the admin area and the public-facing parts of the site reside
  • admin is for all admin-specific functionality
  • public is for all public-facing functionality
  • includes/class-bln-publisher.php is the main plugin class which handles including all the related classes.
  • includes/class-bln-publisher-loader.php is responsible for registering the action and filter hooks, and shortcodes.

REST API

The plugin also provides a set of REST API Endpoints for handling payments and donations.

Initiate Payment for Paywall

  • URL: /lnp-alby/v1/paywall/pay
  • Method: POST
  • Auth Required: No
  • Data example
{
    post_id: "xxx"
}

Verify Payment for Paywall

  • URL: /lnp-alby/v1/paywall/verify
  • Method: POST
  • Auth Required: No
  • Data example
{
    post_id: "xxx",
    token: "xxx",
    preimage: "xxx"
}

LNURL-pay

  • URL: /lnp-alby/v1/lnurlp
  • Method: GET
  • Auth Required: No
{
    "status":"OK",
    "callback":"http:\/\/wp.play.getalby.com\/wp-json\/lnp-alby\/v1\/lnurlp\/callback",
    "minSendable":10000,
    "maxSendable":1000000000,
    "tag":"payRequest",
    "metadata":"[[\"text\/identifier\", \"http:\/\/wp.play.getalby.com\"][\"text\/plain\", \"Alby\"]]"
}
  • URL: /lnp-alby/v1/lnurlp/callback
  • Method: GET
  • Auth Required: No

Initiate a general payment to generate an invoice

  • URL: /lnp-alby/v1/invoices
  • Method: POST
  • Auth Required: No
  • Data example
{
    amount: 123,
    currency: 'btc'
}

Verify Payment for an invoice

  • URL: /lnp-alby/v1/invoices/verify
  • Method: POST
  • Auth Required: No
  • Data example
{
    token: "xxx", // the token from the invoice creation enpoint
    preimage: "xxx"
}

Get support

Do you need help? Create an issue or reach out to us: support[at]getalby.com

About Alby

This plugin is powered by Alby - We create tools to rethink content monetization on the web.

License

GPL 3.0 (as WordPress)

lightning-publisher-wordpress's People

Contributors

bobz-zg avatar bumi avatar im-adithya avatar moritzka avatar musayann avatar omoyi avatar prajan-karmacharya avatar promessed avatar reneaaron avatar rottingcleaner avatar shesek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

lightning-publisher-wordpress's Issues

Option to not use WebLN and display QR code

Hey guys,

Great plugin. My only gripe is that there should be some ability for users who do not have a WebLN plugin like Alby installed to be able to pay via QR or copying a payment request.

The current design isn't great as it just fails out if you don't have a compatible plugin. Some sort of explainer instead would also go a long way.

"Undefined" for Paywall and Donation not working at all

I've been running the v1.2.0 and the latest version (ZIP download) from now. I added an getalby.com address and got the "connected" message at the Wallet setting (also a BTCPay sever before).

When I add the Lightning Paywall and click "Pay", I only get some text "undefined".

The donation button just switches right to the "Donation successful" confirmation message without displaying any donation dialogue.

Where can I find more debugging information? I'm on WordPress 6.0.2.

Woocommerce integration

Hi. Thank you so much for developing this awesome plugin.

I wanted to ask: does this integrate with Woocommerce so that people can buy products and pay with Lightning?

If not yet, can you please consider adding this feature in the future?

Some starter problems after installation

I just installed the plugin and did some testing, I am currently running WP 6.0 on PHP 8.1.

  • Saving of settings does not work for new installations (array_diff(): Argument #2 must be of type array, string given in /var/www/html/wp-content/plugins/lightning-publisher-wordpress/admin/class-wp-lightning-admin.php:224)
  • Frontend doesn't work after installation (Cannot access offset of type string on string in /var/www/html/wp-content/plugins/lightning-publisher-wordpress/includes/class-wp-lightning-paywall.php:111)
  • Editing posts in admin doesn't work as the same error as above

I just wanted to check back and make sure there is no major version mismatch that could cause those errors before I start debugging any further.

Payment to lightning meta tag not possible

Example page: https://morkam4.dreamhosters.com/
Expected behavior: The Alby extension recognizes the lightning meta, asks for an invoice and pays the invoice
J6gZIaq8Bq

Error message
uidhxp6meL

console of pop up:

ignoring bech32 parsing error Error: Unknown character /
    at Object.decode (popup.bundle.js?b74b3a41284dcc8a4338:2:24506)
    at popup.bundle.js?b74b3a41284dcc8a4338:2:1532424
    at Pc (popup.bundle.js?b74b3a41284dcc8a4338:2:1532497)
    at Object.getDetails (popup.bundle.js?b74b3a41284dcc8a4338:2:1532860)
    at onClick (popup.bundle.js?b74b3a41284dcc8a4338:2:1534180)
    at Object.Pe (popup.bundle.js?b74b3a41284dcc8a4338:2:697991)
    at Fe (popup.bundle.js?b74b3a41284dcc8a4338:2:698145)
    at popup.bundle.js?b74b3a41284dcc8a4338:2:718027
    at jr (popup.bundle.js?b74b3a41284dcc8a4338:2:718121)
    at Br (popup.bundle.js?b74b3a41284dcc8a4338:2:718535)

Page source: <meta name="lightning" content="lnurlp:morkam4.dreamhosters.com/wp-json/lnp-alby/v1/lnurlp" /></head>

morkam4.dreamhosters.com/wp-json/lnp-alby/v1/lnurlp

leads to
{"status":"OK","callback":"https:\/\/morkam4.dreamhosters.com\/wp-json\/lnp-alby\/v1\/lnurlp\/callback","minSendable":10000,"maxSendable":1000000000,"tag":"payRequest","commentAllowed":128,"payerData":{"name":{"mandatory":false}},"metadata":"[[\"text\\\/identifier\",\"https:\\\/\\\/morkam4.dreamhosters.com\"],[\"text\\\/plain\",\"Just another WordPress site\"]]"}

https://morkam4.dreamhosters.com//wp-json//lnp-alby//v1//lnurlp//callback
adding ?amount=10000 to https://morkam4.dreamhosters.com//wp-json//lnp-alby//v1//lnurlp//callback manually gives
{"code":"rest_no_route","message":"No route was found matching the URL and request method.","data":{"status":404}}

if I change it to https://morkam4.dreamhosters.com//index.php//wp-json//lnp-alby//v1//lnurlp//callback I get an invoice which I can pay manually.

other example page: http://wp.albylabs.com/
Page source: <meta name="lightning" content="lnurlp:wp.albylabs.com/index.php/wp-json/lnp-alby/v1/lnurlp" /></head>

adding ?amount=10000 to http://wp.albylabs.com//index.php//wp-json//lnp-alby//v1//lnurlp//callback manually gives me an invoice which I can pay manually

is_singular was called incorrectly.

I get this error in the admin panel with the latest version from the master branch.
the is_singular check was recently introduced. Are we missing a special check for the admin panel? @Bobz-zg do you have an idea here?

Notice: Function is_singular was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see [Debugging in WordPress](https://wordpress.org/documentation/article/debugging-in-wordpress/) for more information. (This message was added in version 3.1.0.) in /var/www/html/wp-includes/functions.php on line 5865
image

Add "Buy Now" style payment widget

I believe the issue with payment notes would need to be addressed first:
getAlby/lightning-browser-extension#2312

I have an idea that I think would probably be really useful in expand the WordPress LN publisher. I've attempted to make it work with the donate widget, and the twentyuno, but not quite there yet.

So, if there was a widget or shortcode that allowed you to do essentially what the donate widget does now, but also attach a string to the beginning of the payment note, it could be very useful as a "buy it now" type addition to a product listing. I'd love the ability to allow a customer to click "buy now with Lightning" and have it generate a QR code but append a product number to the note, while still allowing them to enter an email address or shipping address in the note. There may be easier ways to do that, but I think it would really expand the lightning marketplace.

One issue I found with the donation widget is that even if I pay an invoice with say, Wallet of Satoshi, the information I put in the payment note does not display in Alby. Not sure why it doesn't. (getAlby/lightning-browser-extension#2312)

Anyways, nothing critical but I thought I would pass the idea on. Perhaps there is already a solution to this I'm not yet aware of.

Provide defaults for paywall settings

I think we could make the setup process a bit easier if we would just provide some good defaults for the global settings so the user can see the paywall in action by just adding his lightning credentials.

  • Default amount: 1000 sats
  • Default Title: Pay 1.000 sats
  • Default Description: Pay to read on...

Review and update for WP 6.1

WordPress 6.1 is scheduled to be released on November 1st. Are your plugins ready?

After testing your plugins and ensuring compatibility, it only takes a few moments to change the readme "Tested up to" value to 6.1. This information provides peace of mind to users and helps encourage them to update to the latest version of WordPress. You can find more information about plugin readmes here: https://developer.wordpress.org/plugins/wordpress-org/how-your-readme-txt-works/.

Here are the current "Tested up to:" values for each of your plugins:

For each compatible plugin, you do not need to release a new version — instead, you can update the "Tested up to" value to 6.1 in your readme.txt file.

Remember that plugins that are not updated as tested with the latest 3 major releases of WordPress have a notice displayed on their WordPress.org plugin page noting that the plugin may no longer be maintained or supported. It's in everyone's best interest to continue testing plugins against WordPress versions and updating that value.

If you would rather close your plugin because you no longer wish to maintain it, you may do so yourself via the advanced tab on your plugin page: https://developer.wordpress.org/plugins/wordpress-org/plugin-developer-faq/#how-do-i-close-my-plugin

Looking to get more familiar with 6.1? Read this roundup post on the core development blog to learn more about the various changes coming to core with this major release:
https://make.wordpress.org/core/2022/10/12/wordpress-6-1-field-guide/

There are a few areas that need specific focus as plugin-related changes are coming in 6.1; please review those that are most relevant to your plugin functionality:

  1. Content-only editing for blocks, patterns, and templates now allows limiting users to only change the nested content inside said blocks/patterns: https://make.wordpress.org/core/2022/10/11/content-locking-features-and-updates/

  2. The new "Style Engine" API provides a single, centralized agent responsible for generating and rendering consistent block supports styles on the client-side and server-side: https://make.wordpress.org/core/2022/10/10/block-styles-generation-style-engine/

  3. New server-side filters allow hooking into the theme.json data provided at the different data layers (default, blocks, theme, user): https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/

  4. Query block can be further extended and customized through block variations: https://make.wordpress.org/core/2022/10/10/extending-the-query-loop-block/

  5. Block API changes in WordPress 6.1, including PHP templates for rendering blocks and the ability to use multiple scripts per block: https://make.wordpress.org/core/2022/10/12/block-api-changes-in-wordpress-6-1/

  6. Two new functions, wp_required_field_indicator() and wp_required_field_message(), help manage required fields in forms: https://make.wordpress.org/core/2022/10/10/functions-and-hooks-for-required-fields-in-wordpress-6-1/

  7. The @wordpress/core-data JavaScript package in 6.1 ships new React hooks that make accessing WordPress data easier than before: https://make.wordpress.org/core/2022/10/11/simplified-data-access-with-new-react-hooks-in-wordpress-6-1/

  8. New is_login() function for determining if a page is the login screen: https://make.wordpress.org/core/2022/09/11/new-is_login-function-for-determining-if-a-page-is-the-login-screen/

To ensure compatibility, here is how to download the latest Release Candidate for testing with your plugin: https://make.wordpress.org/core/handbook/testing/beta-testing/.

Thank you for all you do for the WordPress community, and we hope you will enjoy 6.1 as much as we do.

— WordPress core contributors

Paywall not showing up when no options set

When I add only [lnpaywall] this is showing up as text on the post:
image

When I add for example the currency like: [lnpaywall currency="EUR"] it is working fine.

Additional: I'm using Classic Editor as editor instead of Gutenberg.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.