55Author: SendThisFile
66Author URI: https://sendthisfile.com
77Description: Enables [sendthisfile] shortcode that displays a file sharing button and dialog to your website.
8- Version: 1.0.7
8+ Version: 1.1.0
99Requires at least: 4.7
1010Tested up to: 6.8.2
1111Text Domain: sendthisfile-button
1919define ( 'SENDTHISFILE_BUTTON_OPTSGROUP_NAME ' , 'sendthisfile_button_optsgroup ' );
2020define ( 'SENDTHISFILE_BUTTON_OPTIONS_NAME ' , 'sendthisfile_button_options ' );
2121define ( '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 ' );
2224define ( 'SENDTHISFILE_BUTTON_LOGO_URL ' , plugins_url ( 'images/logo.svg ' , __FILE__ ) );
2325define ( '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