Skip to content

Commit 7b60e8e

Browse files
committed
chore(*): STF-3523: Update button app WordPress plugin to support testing against dev
1 parent 5ac40ed commit 7b60e8e

3 files changed

Lines changed: 28 additions & 8 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.idea
33
.vscode
44
*.code-workspace
5-
.svn
5+
.svn
6+
/wordpress-plugin.iml

README.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: sendthisfile
44
Requires at least: 4.7
55
Requires PHP: 5.6
66
Tested up to: 6.8.2
7-
Stable tag: 1.0.7
7+
Stable tag: 1.1.0
88
License: GPLv3
99

1010
A WordPress plugin that allows your visitors to send you files on your pages and posts using a SendThisFile website button.
@@ -45,6 +45,8 @@ You are now ready to use your [sendthisfile] shortcode.
4545

4646

4747
== Changelog ==
48+
= 1.1.0 =
49+
* Enhance local development support
4850

4951
= 1.0.7 =
5052
* Updated tested up to version

sendthisfile-button.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Author: SendThisFile
66
Author URI: https://sendthisfile.com
77
Description: Enables [sendthisfile] shortcode that displays a file sharing button and dialog to your website.
8-
Version: 1.0.7
8+
Version: 1.1.0
99
Requires at least: 4.7
1010
Tested up to: 6.8.2
1111
Text Domain: sendthisfile-button
@@ -19,6 +19,8 @@
1919
define( 'SENDTHISFILE_BUTTON_OPTSGROUP_NAME', 'sendthisfile_button_optsgroup' );
2020
define( 'SENDTHISFILE_BUTTON_OPTIONS_NAME', 'sendthisfile_button_options' );
2121
define( 'SENDTHISFILE_BUTTON_SCRIPT_URL', 'https://cdn.sendthisfile.com/button/sendthisfile-button.min.js' );
22+
define( 'SENDTHISFILE_BUTTON_SCRIPT_DEV_URL', 'https://cdn.dev.sendthisfile.com/button/sendthisfile-button.min.js' );
23+
define( 'SENDTHISFILE_BUTTON_SCRIPT_LOCAL_URL', 'http://localhost:8081/button/sendthisfile-button.min.js' );
2224
define( 'SENDTHISFILE_BUTTON_LOGO_URL', plugins_url( 'images/logo.svg', __FILE__ ) );
2325
define( 'SENDTHISFILE_BUTTON_VER', '1.0.0' );
2426

@@ -31,21 +33,26 @@ public static function get_instance() {
3133
return self::$instance;
3234
}
3335

36+
private $scriptUrl = SENDTHISFILE_BUTTON_SCRIPT_URL;
37+
3438
private static $instance = null;
3539

3640
private function __clone() { }
3741

3842
public function __wakeup() { }
3943

4044
private function __construct() {
41-
// Actions
45+
// General Initialization
4246
add_action( 'init', array( $this, 'init' ) );
4347
add_action( 'admin_init', array( $this, 'register_settings' ) );
4448
add_action( 'admin_menu', array( $this, 'add_menu_item' ) );
45-
add_action( 'wp_enqueue_scripts', array( $this, 'register_assets' ) );
4649

47-
// Shortcode
50+
// Set up Shortcode
4851
add_shortcode( 'sendthisfile', array( $this, 'output_shortcode' ) );
52+
53+
// The script must be installed after adding the shortcode because the process depends on
54+
// information obtained during the shortcode setup.
55+
add_action( 'wp_enqueue_scripts', array( $this, 'register_assets' ) );
4956
}
5057

5158
public function init() {
@@ -72,19 +79,29 @@ public function render_options_page() {
7279
}
7380

7481
public function register_assets() {
75-
wp_register_script( 'sendthisfile-button', SENDTHISFILE_BUTTON_SCRIPT_URL, array(), SENDTHISFILE_BUTTON_VER, true );
82+
wp_register_script( 'sendthisfile-button', $this->scriptUrl, array(), SENDTHISFILE_BUTTON_VER, true );
7683
}
7784

7885
public function output_shortcode( $atts, $content, $tag ) {
7986
wp_enqueue_script( 'sendthisfile-button' );
8087

8188
extract( shortcode_atts( array(
8289
'buttonid' => $this->get_option( 'buttonid' ),
83-
'button_label' => $this->get_option( 'button_label', __( 'Send files', 'sendthisfile-button' ) )
90+
'button_label' => $this->get_option( 'button_label', __( 'Send files', 'sendthisfile-button' ) ),
91+
'env' => $this->get_option( 'env' )
8492
), $atts, $tag ) );
8593

8694
if ( empty( $buttonid ) ) return __( 'Invalid button id', 'sendthisfile-button' );
8795

96+
switch ( $env ) {
97+
case 'dev':
98+
$this->scriptUrl = SENDTHISFILE_BUTTON_SCRIPT_DEV_URL;
99+
break;
100+
case 'local':
101+
$this->scriptUrl = SENDTHISFILE_BUTTON_SCRIPT_LOCAL_URL;
102+
break;
103+
}
104+
88105
return '<sendthisfile-button label="' . esc_attr( $button_label ) . '" buttonid="' . esc_attr( $buttonid ) . '"></sendthisfile-button>';
89106
}
90107

0 commit comments

Comments
 (0)