I am setting up a wordpress page for an artist who also offers Patreon subscriptions for additional content...
Patreon offers a plugin to connect your page using oauth2. It works well but we want to add a custom login button as the way they handle this in terms of UI is kind of horrible.
This button was easy enough to set up in the visual editor and works great!
It is essentially just a button with a link behind it:
https://example.com/patreon-flow/?patreon-login=yes&patreon-final-redirect=https://example.com
On the end of the link you can set where you will be redirected to after the login... For now we just set it to the start page since that at least works. BUT we would like to use a variable there so the user would get sent back to the page where he clicked it! (It is kind of inconvenient otherwise..)
Is it possible to use a variable there in some way? I have already searched for plugins that could do this in some way. (found nothing which surprised me) And also for other scripted solutions for this but most of them recommend setting a bunch of custom page IDs but i don't know how that would help me as i don't want to manually edit the button for every page... (i just added it like this in the theme)
EDIT: To make the question a tiny bit clearer.. I need the solution to work in the "Site Editor"!
Solution i setteled on based on answer from @WebElaine:
<?php
/**
* Plugin Name: Patreon Login Button
* Description: "Fancy" Patreon login button that redirects back to the page where the button was Clicked. Inserted by using shortcode: [Patreon_Login_Button]
* Version: 1.0.0
*/
// Exit if accessed directly.
if ( !defined( 'ABSPATH' ) ) {
exit;
}
// Create a shortcode.
add_shortcode( 'Patreon_Login_Button', 'shortcode_link' );
/**
* Define what the shortcode does.
*
* @return string The output of the shortcode.
*/
function shortcode_link() {
// Get the current URL.
global $wp;
$current_url = home_url( $wp->request );
// Update this to whatever HTML output you want to display.
// This example is a link tag with a CSS "button" class, but
// you can make it anything you need.
return '<div class="wp-block-button is-style-fill"><a class="wp-block-button__link has-background wp-element-button" href="' . esc_url( $WP_HOME ) . '/patreon-flow/?patreon-login=yes&patreon-final-redirect=' . esc_url( $current_url ) . '" style="background-color:#f96854">Log in with patreon</a></div>';
}