Skip to content

Commit

Permalink
Improve plugin for backward compatibility and small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nicumicle committed Aug 1, 2024
1 parent a1ac672 commit fa057b8
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 18 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/multiple-php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: "Check plugin with multiple PHP versions"

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
# Check there is no syntax errors in the project
php-linter:
name: Check plugin code compatibility with multiple PHP versions
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.0.0

- name: PHP syntax checker 5.5
uses: prestashop/github-action-php-lint/5.5@master
with:
working-directory: /

- name: PHP syntax checker 5.6
uses: prestashop/github-action-php-lint/5.6@master
with:
working-directory: /

- name: PHP syntax checker 7.1
uses: prestashop/github-action-php-lint/7.1@master
with:
working-directory: /

- name: PHP syntax checker 7.2
uses: prestashop/github-action-php-lint/7.2@master
with:
working-directory: /

- name: PHP syntax checker 7.3
uses: prestashop/github-action-php-lint/7.3@master
with:
working-directory: /

- name: PHP syntax checker 7.4
uses: prestashop/github-action-php-lint/7.4@master
with:
working-directory: /

- name: PHP syntax checker 8.0
uses: prestashop/github-action-php-lint/8.0@master
with:
working-directory: /

- name: PHP syntax checker 8.1
uses: prestashop/github-action-php-lint/8.1@master
with:
working-directory: /

- name: PHP syntax checker 8.2
uses: prestashop/github-action-php-lint/8.2@master
with:
working-directory: /
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ It allows you to automatically login users from the newsletter sent by MailPoet
## Requirements

- [MailPoet](https://wordpress.org/plugins/mailpoet/) WordPress plugin
- [Simple-JWT-Login](https://wordpress.org/plugins/simple-jwt-login/) Wordpress plugin
- [Simple-JWT-Login](https://wordpress.org/plugins/simple-jwt-login/) WordPress plugin

## Usage

Expand Down Expand Up @@ -46,6 +46,12 @@ Full short code example:

This example will generate a red link, with the text "Login".

You can also customize the shortcode to just return the URL.

```
[custom:simple-jwt-login text="Login" validity="604800" isUrl="on"]
```


## Installation

Expand Down
14 changes: 12 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Contributors: nicu_m
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PK9BCD6AYF58Y&source=url
Tags: jwt, API, auto login, tokens, REST, auth, generate jwt, mailpoet
Tags: jwt, auto login, tokens, auth, generate jwt, mailpoet
Requires at least: 4.4.0
Tested up to: 6.6
Requires PHP: 5.5
Expand Down Expand Up @@ -34,11 +34,17 @@ Available shortcode parameters:
Full short code example:

``
[custom:simple-jwt-login text="Login" class="myClassName" style="color:red;" validity="604800" authCode="1"]
[custom:simple-jwt-login text="Login" class="myClassName" style="color:red;" validity="604800" authCode="1"]
``

This example will generate a red link, with the text "Login".

You can also customize the shortcode to just return the URL.

``
[custom:simple-jwt-login text="Login" validity="604800" isUrl="on"]
``

== Screenshots ==

1. Short code generator
Expand Down Expand Up @@ -75,6 +81,10 @@ Yes. You can add as many short-codes as you want in a single email template.

== Changelog ==

= 1.0.1 ( 31 Jul 2024)
- Fix Shortcode handler
- Update WordPress 6.6 compatibility

= 1.0.0 ( 03 May 2024)
- Test with latest WordPress version

Expand Down
2 changes: 1 addition & 1 deletion assets/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ jQuery(document).ready(
function ($) {
const shortcode = 'custom:simple-jwt-login';
const shortCodePreview = document.getElementById('simple-jwt-login-mailpoet-short-code');
const linkPreview = document.getElementById('simple-jwt-login-mailport-preview');
const linkPreview = document.getElementById('simple-jwt-login-mailpoet-preview');

renderCode();

Expand Down
8 changes: 4 additions & 4 deletions mailpoet.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ function simple_jwt_login_mailpoet_shortcode(
$arguments
)
{
$pluginshortcode = 'custom:simple-jwt-login';
$isValidShortcode = strpos($shortcode, '[' . $pluginshortcode) === 0;
$re = '/^\[custom:simple[-]?jwt[-]?login(.*)\]$/m';
preg_match_all($re, $shortcode, $matches, PREG_SET_ORDER, 0);

// always return the shortcode if it doesn't match your own!
if ($isValidShortcode === false || $subscriber === null) {
if (empty($matches)) {
return $shortcode;
}

Expand Down Expand Up @@ -64,7 +64,7 @@ function simple_jwt_login_mailpoet_shortcode(
$url .= '&' . $jwtSettings->getAuthCodesSettings()->getAuthCodeKey() . '=' . $arguments['authcode'];
}
if (isset($arguments['redirectUrl']) && $arguments['redirectUrl'] !== '') {
$url .= '&redirectUrl=' . $arguments['redirectUrl'];
$url .= '&redirectUrl=' . urlencode($arguments['redirectUrl']);
}

$loginText = isset($arguments['text']) ? $arguments['text'] : 'Login';
Expand Down
2 changes: 1 addition & 1 deletion simple-jwt-login-mailpoet.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

add_action('admin_menu', 'simple_jwt_login__mailpoet_plugin_create_menu_entry', 11);
if (check_simple_jwt_login_activated() == false) {
if (!check_simple_jwt_login_activated()) {
add_action('admin_notices', 'simple_jwt_login_plugin_missing_notice');
}

Expand Down
21 changes: 12 additions & 9 deletions views/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<?php
}
?>

<div id="simple-jwt-login-mailpoet">
<div class="row">
<div class="col-md-12">
Expand Down Expand Up @@ -67,7 +68,8 @@
?>
</div>
<div class="item">
<label for="text-auth-code"><?php echo __('JWT Validity', 'simple-jwt-login-mailpoet'); ?></label>
<label
for="text-jwt-validity"><?php echo __('JWT Validity', 'simple-jwt-login-mailpoet'); ?></label>
<p>
<?php
echo __(
Expand All @@ -76,7 +78,7 @@
);
?>
</p>
<input type="text" id="text-jwt-validity" class="input form-control" value="604800" />
<input type="text" id="text-jwt-validity" class="input form-control" value="604800"/>

</div>

Expand All @@ -91,7 +93,8 @@
?>
</p>
<input type="checkbox" id="text-jwt-isUrl" class="input form-control">
<label for="text-jwt-isUrl"><?php echo __('Shortcode should return only the autologin URL', 'simple-jwt-login-mailpoet'); ?></label>
<label
for="text-jwt-isUrl"><?php echo __('Shortcode should return only the autologin URL', 'simple-jwt-login-mailpoet'); ?></label>
</div>
<div class="item">
<label for="text-redirectUrl"><?php echo __('RedirectUrl', 'simple-jwt-login-mailpoet'); ?></label>
Expand All @@ -106,9 +109,10 @@
<input type="text" id="text-redirectUrl" class="input form-control" value="">

</div>
<hr/>
<h2><?php echo __('Design', 'simple-jwt-login-mailpoet'); ?></h2>
<div class="item">
<label for="text-value"><?php echo __('Text', 'simple-jwt-login-mailpoet'); ?>:</label>
<label for="text-value"><?php echo __('Text', 'simple-jwt-login-mailpoet'); ?></label>
<p>
<?php
echo __(
Expand All @@ -120,7 +124,7 @@
<input type="text" id="text-value" class="input form-control" value="Login">
</div>
<div class="item">
<label for="class-value"><?php echo __('Class', 'simple-jwt-login-mailpoet'); ?>:</label>
<label for="class-value"><?php echo __('Class', 'simple-jwt-login-mailpoet'); ?></label>
<p>
<?php
echo __(
Expand All @@ -132,7 +136,7 @@
<input type="text" id="class-value" class="input form-control" value="">
</div>
<div class="item">
<label for="class-style"><?php echo __('Style', 'simple-jwt-login-mailpoet'); ?>:</label>
<label for="class-style"><?php echo __('Style', 'simple-jwt-login-mailpoet'); ?></label>
<p>
<?php
echo __(
Expand All @@ -141,7 +145,7 @@
);
?>
</p>
<textarea id="class-style" class="input form-control" value=""></textarea>
<textarea id="class-style" class="input form-control"></textarea>
</div>
</div>
</div>
Expand All @@ -162,11 +166,10 @@
<div class="preview-container">
<h3><?php echo __('Shortcode Preview', 'simple-jwt-login-mailpoet'); ?></h3>
<div class="preview-button-container">
<div id="simple-jwt-login-mailport-preview"></div>
<div id="simple-jwt-login-mailpoet-preview"></div>
</div>
</div>
</div>

</div>
</div>
</div>

0 comments on commit fa057b8

Please sign in to comment.