├── .gitignore ├── index.php ├── .gitattributes ├── languages ├── wp-line-notify-zh_TW.mo ├── wp-line-notify.pot └── wp-line-notify-zh_TW.po ├── includes ├── class-line.php ├── class-elementor.php ├── upgrade.php ├── class-woo.php └── page-setup.php ├── readme.txt └── wp-line-notify.php /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | .DS_Store 4 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | token = $token; 11 | } 12 | 13 | public function send($text='') { 14 | 15 | if ( empty($this->token) ) return __( 'LINE Notify token is required!' , 'wp-line-notify' ); 16 | 17 | if ( empty($text) ) return __( 'Plase write something !' , 'wp-line-notify' ); 18 | 19 | $request_params = array( 20 | "headers" => "Authorization: Bearer {$this->token}", 21 | "body" => array( 22 | "message" => "\n{$text}" 23 | ) 24 | ); 25 | 26 | $response = wp_remote_post( self::API_URL.'notify', $request_params ); 27 | $code = wp_remote_retrieve_response_code( $response ); 28 | $message = wp_remote_retrieve_response_message( $response ); 29 | 30 | if( $code === 200 ){ 31 | return 'ok'; 32 | }else{ 33 | return $message; 34 | } 35 | 36 | } 37 | 38 | public function check_token(){ 39 | 40 | $request_params = array( 41 | "headers" => "Authorization: Bearer ".$this->token 42 | ); 43 | $response = wp_remote_get( self::API_URL.'status', $request_params ); 44 | return ( 200 === wp_remote_retrieve_response_code( $response ) ) ? true : false ; 45 | } 46 | 47 | public function revoke(){ 48 | 49 | $request_params = array( 50 | "headers" => "Authorization: Bearer ".$this->token 51 | ); 52 | 53 | $response = wp_remote_post( self::API_URL.'revoke', $request_params ); 54 | $code = wp_remote_retrieve_response_code( $response ); 55 | $message = wp_remote_retrieve_response_message( $response ); 56 | 57 | echo json_encode(array( 58 | 'rs' => ($code==200) ? true : false, 59 | 'message' => $message 60 | )); 61 | die(); 62 | } 63 | } -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === WP LINE Notify === 2 | Contributors: simon_tw 3 | Tags: notify, plugin, line, WooCommerce, Elementor, Contact Form 4 | Requires at least: 5.4 5 | Tested up to: 6.7 6 | Requires PHP: 8.0 7 | Stable tag: 1.4.6 8 | License: GPLv3 9 | License URI: https://www.gnu.org/licenses/gpl-3.0.html 10 | 11 | This plugin can send a alert message by LINE Notify. 12 | 13 | 14 | == Description == 15 | 16 | This plugin can send a alert message by LINE Notify 17 | 18 | 19 | == Installation == 20 | 21 | This section describes how to install the plugin and get it working. 22 | 23 | e.g. 24 | 25 | 1. Upload the plugin files to the `/wp-content/plugins/plugin-name` directory, or install the plugin through the WordPress plugins screen directly. 26 | 2. Activate the plugin through the `Plugins` screen in WordPress. 27 | 28 | == Screenshots == 29 | 30 | 1. Basic option settings. 31 | 2. User Line Notify token setting. 32 | 33 | == Changelog == 34 | 35 | = 1.4.6 - 2024-11-15 = 36 | * Updated for WordPress 6.7 37 | * Fixed bug for PHP 8.2 38 | 39 | = 1.4.5 - 2023-08-24 = 40 | * Improved: Filter user ID. 41 | 42 | = 1.4.4 - 2023-08-19 = 43 | * Update: Form UI. 44 | * Improved: Remove revoke function. 45 | 46 | = 1.4.3 - 2023-08-17 = 47 | * Improved: Filtering of form fields. 48 | 49 | = 1.4.2 - 2023-01-16 = 50 | * Fixed: WooCommerce template bug. 51 | 52 | = 1.4 - 2023-01-13 = 53 | * Fixed some bug. 54 | * Update: Elementor Pro Form method. 55 | * Add: Different users can set their own token and notification items. 56 | 57 | = 1.3.3 - 2022-09-30 = 58 | * Improved: Use Contact Form 7 email template to send message. 59 | 60 | = 1.3.2 - 2022-09-19 = 61 | * Fixed some bug. (WooCommerce default template) 62 | * Add: Order status changed notify. 63 | 64 | = 1.3.1 - 2021-10-21 = 65 | * Fixed bug. 66 | * Update: Elementor form show text. 67 | 68 | = 1.3 - 2021-09-15 = 69 | * Fixed bug. 70 | * Add: Elementor form widget. 71 | * Add: WooCommerce SKU field. 72 | * Add: Support Checkout Field Editor (Checkout Manager). 73 | 74 | = 1.2 - 2021-09-02 = 75 | * Update something. 76 | 77 | = 1.1.2 - 2020-08-22 = 78 | * Add: Support Contact Form 7 for V.5.2.x 79 | 80 | = 1.1.1 - 2020-03-08 = 81 | * Add: Add two shortcodes for WooCommerce. 82 | 83 | = 1.1 - 2019-08-30 = 84 | * Add config for more Contact Form 7. 85 | 86 | = 1.0 - 2018-09-15 = 87 | * Add WooCommerce message template. 88 | 89 | = 0.2 - 2018-09-11 = 90 | * Add send message for new post. 91 | 92 | = 0.1.2 - 2018-09-07 = 93 | * Fixed bug. 94 | 95 | = 0.1.1 - 2018-09-05 = 96 | * Added new notify for Contact Form 7 97 | 98 | = 0.1.0 - 2018-09-03 = 99 | * Initial Public Release 100 | -------------------------------------------------------------------------------- /includes/class-elementor.php: -------------------------------------------------------------------------------- 1 | token = $token; 17 | } 18 | 19 | /** 20 | * Get Name 21 | * 22 | * Return the action name 23 | * 24 | * @access public 25 | * @return string 26 | */ 27 | public function get_name() { 28 | return 'Line notify'; 29 | } 30 | 31 | /** 32 | * Get Label 33 | * 34 | * Returns the action label 35 | * 36 | * @access public 37 | * @return string 38 | */ 39 | public function get_label() { 40 | return __( 'Line notify', 'wp-line-notify' ); 41 | } 42 | 43 | /** 44 | * Run 45 | * 46 | * Runs the action after submit 47 | * 48 | * @access public 49 | * @param \ElementorPro\Modules\Forms\Classes\Form_Record $record 50 | * @param \ElementorPro\Modules\Forms\Classes\Ajax_Handler $ajax_handler 51 | */ 52 | public function run( $record, $ajax_handler ) { 53 | 54 | if( !empty($this->token) ){ 55 | $settings = $record->get( 'form_settings' ); 56 | 57 | $message = ( !empty( $settings['line_notify_prompt_text'] ) ) ? $settings['line_notify_prompt_text'] : __( 'You have a message from the Elementor Form.', 'wp-line-notify' ); 58 | 59 | $form_data = $record->get( 'fields' ); 60 | 61 | // Normalize the Form Data 62 | foreach ( $form_data as $id => $field ) { 63 | $title = (!empty($field['title'])) ? $field['title'] : $id; 64 | $valeu = (!empty($field['value'])) ? $field['value'] : ''; 65 | $message .= "\n[{$title}] {$valeu}"; 66 | } 67 | 68 | $sender = new WpLineNotify(); 69 | $sender->send_msg( $this->token, $message ); 70 | } 71 | } 72 | 73 | /** 74 | * Register Settings Section 75 | * 76 | * Registers the Action controls 77 | * 78 | * @access public 79 | * @param \Elementor\Widget_Base $widget 80 | */ 81 | public function register_settings_section( $widget ) { 82 | 83 | $widget->start_controls_section( 84 | 'section_line_notify', 85 | [ 86 | 'label' => __( 'Line notify alert', 'wp-line-notify' ), 87 | 'condition' => [ 88 | 'submit_actions' => $this->get_name(), 89 | ], 90 | ] 91 | ); 92 | 93 | $widget->add_control( 94 | 'line_notify_prompt_text', 95 | [ 96 | 'label' => __( 'Prompt text', 'wp-line-notify' ), 97 | 'type' => \Elementor\Controls_Manager::TEXTAREA, 98 | 'placeholder' => '', 99 | 'description' => __( 'The reminder text is displayed at the beginning of the sent message.', 'wp-line-notify' ), 100 | ] 101 | ); 102 | 103 | $widget->end_controls_section(); 104 | } 105 | 106 | /** 107 | * On Export 108 | * 109 | * Clears form settings on export 110 | * @access Public 111 | * @param array $element 112 | */ 113 | public function on_export( $element ) { 114 | unset( 115 | $element['line_notify_prompt_text'] 116 | ); 117 | } 118 | } -------------------------------------------------------------------------------- /includes/upgrade.php: -------------------------------------------------------------------------------- 1 | option_name = $option_name; 22 | 23 | $this->option = get_option( $option_name, [] ); 24 | 25 | $this->option_ver = ( isset($this->option['version']) ) ? $this->option['version'] : '1.0'; 26 | 27 | $this->plugin_ver = $ver; 28 | } 29 | 30 | /** 31 | * 32 | */ 33 | public function run() { 34 | 35 | /** 36 | * 37 | * @since 1.3.3 38 | */ 39 | if( version_compare( $this->option_ver, '1.3.3', '<=' ) ) { 40 | 41 | if( !isset($this->option['post_status']) ) $this->option['post_status'] = []; 42 | 43 | if( isset($this->option['publish_post']) ){ 44 | $this->option['post_status']['publish'] = []; 45 | foreach( $this->option['publish_post'] as $role => $v ){ 46 | $this->option['post_status']['publish'][] = $role; 47 | } 48 | unset( $this->option['publish_post'] ); 49 | } 50 | 51 | if( isset($this->option['pending_post']) ){ 52 | $this->option['post_status']['pending'] = []; 53 | foreach( $this->option['pending_post'] as $role => $v ){ 54 | $this->option['post_status']['pending'][] = $role; 55 | } 56 | unset( $this->option['pending_post'] ); 57 | } 58 | 59 | if( !empty($this->option['comments']) ){ 60 | if( $this->option['comments'] == '1' ) $this->option['comments'] = 'yes'; 61 | } 62 | 63 | if( !empty($this->option['user_register']) ){ 64 | if( $this->option['user_register'] == '1' ) $this->option['user_register'] = 'yes'; 65 | } 66 | 67 | if( !empty($this->option['woocommerce']) ){ 68 | if( $this->option['woocommerce'] == '1' ) { 69 | $this->option['woo_order'] = 'yes'; 70 | } 71 | unset( $this->option['woocommerce'] ); 72 | } 73 | 74 | if( isset($this->option['woocommerce_tpl']) ){ 75 | $this->option['woo_tpl'] = $this->option['woocommerce_tpl']; 76 | unset( $this->option['woocommerce_tpl'] ); 77 | } 78 | 79 | if( !isset($this->option['wpcf7_form']) ) $this->option['wpcf7_form'] = []; 80 | if( !empty($this->option['wpcf7']) ){ 81 | foreach( $this->option['wpcf7'] as $id=>$val ){ 82 | $this->option['wpcf7_form'][] = $id; 83 | } 84 | unset( $this->option['wpcf7'] ); 85 | } 86 | 87 | if( !empty($this->option['elementor_form']) ){ 88 | if( $this->option['elementor_form'] == '1' ) $this->option['elementor_form'] = 'yes'; 89 | } 90 | 91 | update_option( $this->option_name, $this->option ); 92 | } 93 | 94 | /** 95 | * update version number 96 | */ 97 | if( version_compare( $this->option_ver, $this->plugin_ver, '<' ) ) { 98 | $this->option['version'] = $this->plugin_ver; 99 | update_option( $this->option_name, $this->option ); 100 | } 101 | 102 | } 103 | 104 | } -------------------------------------------------------------------------------- /languages/wp-line-notify.pot: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2024 Simon Chuang 2 | # This file is distributed under the GPLv2. 3 | msgid "" 4 | msgstr "" 5 | "Project-Id-Version: WordPress LINE Notify 1.4.6\n" 6 | "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wp-line-notify\n" 7 | "Last-Translator: FULL NAME \n" 8 | "Language-Team: LANGUAGE \n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "POT-Creation-Date: 2024-11-15T04:22:59+00:00\n" 13 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 | "X-Generator: WP-CLI 2.11.0\n" 15 | "X-Domain: wp-line-notify\n" 16 | 17 | #. Plugin Name of the plugin 18 | #: wp-line-notify.php 19 | msgid "WordPress LINE Notify" 20 | msgstr "" 21 | 22 | #. Description of the plugin 23 | #: wp-line-notify.php 24 | msgid "This plugin can send a alert message by LINE Notify" 25 | msgstr "" 26 | 27 | #. Author of the plugin 28 | #: wp-line-notify.php 29 | msgid "Simon Chuang" 30 | msgstr "" 31 | 32 | #. Author URI of the plugin 33 | #: wp-line-notify.php 34 | msgid "https://github.com/mark2me/wp-line-notify" 35 | msgstr "" 36 | 37 | #: includes/class-elementor.php:40 38 | msgid "Line notify" 39 | msgstr "" 40 | 41 | #: includes/class-elementor.php:57 42 | msgid "You have a message from the Elementor Form." 43 | msgstr "" 44 | 45 | #: includes/class-elementor.php:86 46 | msgid "Line notify alert" 47 | msgstr "" 48 | 49 | #: includes/class-elementor.php:96 50 | msgid "Prompt text" 51 | msgstr "" 52 | 53 | #: includes/class-elementor.php:99 54 | msgid "The reminder text is displayed at the beginning of the sent message." 55 | msgstr "" 56 | 57 | #: includes/class-line.php:15 58 | #: includes/page-setup.php:9 59 | msgid "LINE Notify token is required!" 60 | msgstr "" 61 | 62 | #: includes/class-line.php:17 63 | msgid "Plase write something !" 64 | msgstr "" 65 | 66 | #: includes/class-woo.php:9 67 | msgid "Billing First Name" 68 | msgstr "" 69 | 70 | #: includes/class-woo.php:10 71 | msgid "Billing Last Name" 72 | msgstr "" 73 | 74 | #: includes/class-woo.php:11 75 | msgid "Billing Company" 76 | msgstr "" 77 | 78 | #: includes/class-woo.php:12 79 | msgid "Billing Address 1" 80 | msgstr "" 81 | 82 | #: includes/class-woo.php:13 83 | msgid "Billing Address 2" 84 | msgstr "" 85 | 86 | #: includes/class-woo.php:14 87 | msgid "Billing City" 88 | msgstr "" 89 | 90 | #: includes/class-woo.php:15 91 | msgid "Billing State" 92 | msgstr "" 93 | 94 | #: includes/class-woo.php:16 95 | msgid "Billing Postal/Zip Code" 96 | msgstr "" 97 | 98 | #: includes/class-woo.php:17 99 | msgid "Billing Country / Region" 100 | msgstr "" 101 | 102 | #: includes/class-woo.php:18 103 | msgid "Email Address" 104 | msgstr "" 105 | 106 | #: includes/class-woo.php:19 107 | msgid "Billing Phone Number" 108 | msgstr "" 109 | 110 | #: includes/class-woo.php:22 111 | msgid "Shipping First Name" 112 | msgstr "" 113 | 114 | #: includes/class-woo.php:23 115 | msgid "Shipping Last Name" 116 | msgstr "" 117 | 118 | #: includes/class-woo.php:24 119 | msgid "Shipping Company" 120 | msgstr "" 121 | 122 | #: includes/class-woo.php:25 123 | msgid "Shipping Address 1" 124 | msgstr "" 125 | 126 | #: includes/class-woo.php:26 127 | msgid "Shipping Address 2" 128 | msgstr "" 129 | 130 | #: includes/class-woo.php:27 131 | msgid "Shipping City" 132 | msgstr "" 133 | 134 | #: includes/class-woo.php:28 135 | msgid "Shipping State" 136 | msgstr "" 137 | 138 | #: includes/class-woo.php:29 139 | msgid "Shipping Postal/Zip Code" 140 | msgstr "" 141 | 142 | #: includes/class-woo.php:30 143 | msgid "Shipping Country / Region" 144 | msgstr "" 145 | 146 | #: includes/class-woo.php:31 147 | msgid "Shipping Phone Number" 148 | msgstr "" 149 | 150 | #: includes/class-woo.php:34 151 | #: includes/class-woo.php:61 152 | msgid "Order id" 153 | msgstr "" 154 | 155 | #: includes/class-woo.php:35 156 | #: includes/class-woo.php:62 157 | msgid "Order item" 158 | msgstr "" 159 | 160 | #: includes/class-woo.php:36 161 | #: includes/class-woo.php:63 162 | msgid "Order name" 163 | msgstr "" 164 | 165 | #: includes/class-woo.php:37 166 | #: includes/class-woo.php:64 167 | msgid "Shipping name" 168 | msgstr "" 169 | 170 | #: includes/class-woo.php:38 171 | #: includes/class-woo.php:65 172 | msgid "Payment method" 173 | msgstr "" 174 | 175 | #: includes/class-woo.php:39 176 | #: includes/class-woo.php:66 177 | msgid "Total" 178 | msgstr "" 179 | 180 | #: includes/class-woo.php:40 181 | #: includes/class-woo.php:67 182 | msgid "Order time" 183 | msgstr "" 184 | 185 | #: includes/class-woo.php:41 186 | #: includes/class-woo.php:68 187 | msgid "Order notes" 188 | msgstr "" 189 | 190 | #: includes/class-woo.php:60 191 | msgid "You have a new order." 192 | msgstr "" 193 | 194 | #: includes/class-woo.php:98 195 | #: includes/class-woo.php:109 196 | msgid "WooCommerce" 197 | msgstr "" 198 | 199 | #: includes/class-woo.php:99 200 | #: includes/page-setup.php:144 201 | #: includes/page-setup.php:168 202 | msgid "This plugin is not install or active." 203 | msgstr "" 204 | 205 | #: includes/class-woo.php:112 206 | msgid "Add a new order" 207 | msgstr "" 208 | 209 | #: includes/class-woo.php:118 210 | msgid "You can use these tags in the message template:" 211 | msgstr "" 212 | 213 | #: includes/class-woo.php:119 214 | msgid "(Click tag to insert into the template)" 215 | msgstr "" 216 | 217 | #: includes/class-woo.php:123 218 | msgid "Default Item" 219 | msgstr "" 220 | 221 | #: includes/class-woo.php:133 222 | msgid "Billing Fields" 223 | msgstr "" 224 | 225 | #: includes/class-woo.php:139 226 | msgid "Shipping Fields" 227 | msgstr "" 228 | 229 | #: includes/class-woo.php:145 230 | msgid "Additional Fields" 231 | msgstr "" 232 | 233 | #: includes/class-woo.php:154 234 | msgid "Buyer Information" 235 | msgstr "" 236 | 237 | #: includes/class-woo.php:161 238 | msgid "Recipient Information" 239 | msgstr "" 240 | 241 | #: includes/class-woo.php:173 242 | msgid "Template" 243 | msgstr "" 244 | 245 | #: includes/class-woo.php:178 246 | msgid "* If you do not enter any text, the system will use the default template." 247 | msgstr "" 248 | 249 | #: includes/class-woo.php:184 250 | msgid "Order status changed" 251 | msgstr "" 252 | 253 | #: includes/page-setup.php:13 254 | msgid "From April 1, 2025, all LINE Notify features will become unavailable." 255 | msgstr "" 256 | 257 | #: includes/page-setup.php:18 258 | #: wp-line-notify.php:120 259 | #: wp-line-notify.php:155 260 | msgid "Line Notify Setting" 261 | msgstr "" 262 | 263 | #: includes/page-setup.php:26 264 | msgid "Line Notify Token" 265 | msgstr "" 266 | 267 | #: includes/page-setup.php:29 268 | #: includes/page-setup.php:194 269 | msgid "General" 270 | msgstr "" 271 | 272 | #: includes/page-setup.php:41 273 | msgid "Access token valid." 274 | msgstr "" 275 | 276 | #: includes/page-setup.php:41 277 | msgid "Invalid access token." 278 | msgstr "" 279 | 280 | #: includes/page-setup.php:44 281 | #: wp-line-notify.php:161 282 | msgid "* Generate access token on LINE website" 283 | msgstr "" 284 | 285 | #: includes/page-setup.php:52 286 | msgid "When to send message ?" 287 | msgstr "" 288 | 289 | #: includes/page-setup.php:56 290 | msgid "Post" 291 | msgstr "" 292 | 293 | #: includes/page-setup.php:58 294 | msgid "Publish" 295 | msgstr "" 296 | 297 | #: includes/page-setup.php:60 298 | #: includes/page-setup.php:75 299 | msgid "Select roles:" 300 | msgstr "" 301 | 302 | #: includes/page-setup.php:73 303 | msgid "Pending" 304 | msgstr "" 305 | 306 | #: includes/page-setup.php:88 307 | msgid "Comments" 308 | msgstr "" 309 | 310 | #: includes/page-setup.php:94 311 | msgid "Add a new comment" 312 | msgstr "" 313 | 314 | #: includes/page-setup.php:99 315 | msgid "Users" 316 | msgstr "" 317 | 318 | #: includes/page-setup.php:105 319 | msgid "User register" 320 | msgstr "" 321 | 322 | #: includes/page-setup.php:119 323 | msgid "Contact Form 7" 324 | msgstr "" 325 | 326 | #: includes/page-setup.php:125 327 | msgid "When a new contact message is received." 328 | msgstr "" 329 | 330 | #: includes/page-setup.php:137 331 | msgid "(Edit message template)" 332 | msgstr "" 333 | 334 | #: includes/page-setup.php:156 335 | msgid "Elementor Pro" 336 | msgstr "" 337 | 338 | #: includes/page-setup.php:164 339 | msgid "When a new message is received from the Elementor Pro form widget." 340 | msgstr "" 341 | 342 | #: includes/page-setup.php:166 343 | msgid "You have to find the \"Actions After Submit\" in the form editing function and add a new action called \"Line notify\"." 344 | msgstr "" 345 | 346 | #: includes/page-setup.php:181 347 | msgid "Test Line Notify" 348 | msgstr "" 349 | 350 | #: includes/page-setup.php:190 351 | msgid "Send to" 352 | msgstr "" 353 | 354 | #: includes/page-setup.php:207 355 | msgid "Test message" 356 | msgstr "" 357 | 358 | #: includes/page-setup.php:212 359 | msgid "Send test" 360 | msgstr "" 361 | 362 | #: wp-line-notify.php:109 363 | msgid "Settings" 364 | msgstr "" 365 | 366 | #: wp-line-notify.php:121 367 | msgid "WP Line Notify" 368 | msgstr "" 369 | 370 | #: wp-line-notify.php:158 371 | msgid "Line Notify Token:" 372 | msgstr "" 373 | 374 | #: wp-line-notify.php:200 375 | msgid "publish a post" 376 | msgstr "" 377 | 378 | #: wp-line-notify.php:201 379 | msgid "pending a post" 380 | msgstr "" 381 | 382 | #: wp-line-notify.php:255 383 | msgid "You have a new comment." 384 | msgstr "" 385 | 386 | #: wp-line-notify.php:273 387 | msgid "You have a new user register." 388 | msgstr "" 389 | 390 | #: wp-line-notify.php:274 391 | msgid "Username:" 392 | msgstr "" 393 | 394 | #. translators: %1$s is order id, %2$s is order state. 395 | #: wp-line-notify.php:392 396 | msgid "There is an order id %1$d, and the state is changed to %2$s." 397 | msgstr "" 398 | 399 | #: wp-line-notify.php:415 400 | msgid "" 401 | "You have a new contact message.\n" 402 | "" 403 | msgstr "" 404 | 405 | #: wp-line-notify.php:499 406 | msgid "This is a Line notify plugin test." 407 | msgstr "" 408 | 409 | #: wp-line-notify.php:508 410 | msgid "Please fill in the top Line Notify Token field." 411 | msgstr "" 412 | 413 | #: wp-line-notify.php:515 414 | msgid "Send test ok!" 415 | msgstr "" 416 | 417 | #: wp-line-notify.php:517 418 | msgid "Error on send LINE Notify." 419 | msgstr "" 420 | -------------------------------------------------------------------------------- /includes/class-woo.php: -------------------------------------------------------------------------------- 1 | array( 9 | 'billing_first_name' => __( 'Billing First Name', 'wp-line-notify' ), 10 | 'billing_last_name' => __( 'Billing Last Name', 'wp-line-notify' ), 11 | 'billing_company' => __( 'Billing Company', 'wp-line-notify' ), 12 | 'billing_address_1' => __( 'Billing Address 1', 'wp-line-notify' ), 13 | 'billing_address_2' => __( 'Billing Address 2', 'wp-line-notify' ), 14 | 'billing_city' => __( 'Billing City', 'wp-line-notify' ), 15 | 'billing_state' => __( 'Billing State', 'wp-line-notify' ), 16 | 'billing_postcode' => __( 'Billing Postal/Zip Code', 'wp-line-notify' ), 17 | 'billing_country' => __( 'Billing Country / Region', 'wp-line-notify' ), 18 | 'billing_email' => __( 'Email Address', 'wp-line-notify' ), 19 | 'billing_phone' => __( 'Billing Phone Number', 'wp-line-notify' ), 20 | ), 21 | 'shipping' => array( 22 | 'shipping_first_name'=> __( 'Shipping First Name', 'wp-line-notify' ), 23 | 'shipping_last_name' => __( 'Shipping Last Name', 'wp-line-notify' ), 24 | 'shipping_company' => __( 'Shipping Company', 'wp-line-notify' ), 25 | 'shipping_address_1' => __( 'Shipping Address 1', 'wp-line-notify' ), 26 | 'shipping_address_2' => __( 'Shipping Address 2', 'wp-line-notify' ), 27 | 'shipping_city' => __( 'Shipping City', 'wp-line-notify' ), 28 | 'shipping_state' => __( 'Shipping State', 'wp-line-notify' ), 29 | 'shipping_postcode' => __( 'Shipping Postal/Zip Code', 'wp-line-notify' ), 30 | 'shipping_country' => __( 'Shipping Country / Region', 'wp-line-notify' ), 31 | 'shipping_phone' => __( 'Shipping Phone Number', 'wp-line-notify' ), 32 | ), 33 | 'order' => array( 34 | 'order-id' => __( 'Order id' , 'wp-line-notify' ), 35 | 'order-product' => __( 'Order item' , 'wp-line-notify' ), 36 | 'order-name' => __( 'Order name' , 'wp-line-notify' ), 37 | 'shipping-name' => __( 'Shipping name' , 'wp-line-notify' ), 38 | 'payment-method' => __( 'Payment method' , 'wp-line-notify' ), 39 | 'total' => __( 'Total' , 'wp-line-notify' ), 40 | 'order-time' => __( 'Order time' , 'wp-line-notify' ), 41 | 'customer_note' => __( 'Order notes', 'wp-line-notify' ), 42 | ) 43 | ); 44 | 45 | return (isset($fields[$type])) ? $fields[$type] : array(); 46 | 47 | } 48 | 49 | public static function form() { 50 | $template = sprintf( 51 | '%1$s 52 | %2$s: [order-id] 53 | %3$s: [order-product] 54 | %4$s: [order-name] 55 | %5$s: [shipping-name] 56 | %6$s: [payment-method] 57 | %7$s: [total] 58 | %8$s: [order-time] 59 | %9$s: [customer_note]', 60 | __( 'You have a new order.' , 'wp-line-notify' ), 61 | __( 'Order id' , 'wp-line-notify' ), 62 | __( 'Order item' , 'wp-line-notify' ), 63 | __( 'Order name' , 'wp-line-notify' ), 64 | __( 'Shipping name' , 'wp-line-notify' ), 65 | __( 'Payment method' , 'wp-line-notify' ), 66 | __( 'Total' , 'wp-line-notify' ), 67 | __( 'Order time' , 'wp-line-notify' ), 68 | __( 'Order notes', 'wp-line-notify' ) 69 | ); 70 | 71 | return trim( $template ); 72 | } 73 | 74 | /* 75 | woo-checkout-field-editor 76 | */ 77 | public static function get_fields($type='') { 78 | 79 | $fields = []; 80 | if( class_exists('THWCFD_Utils') ){ 81 | $fields = THWCFD_Utils::get_fields($type); 82 | } 83 | return $fields; 84 | } 85 | 86 | private static function fields_tags_list($type='') { 87 | 88 | foreach( self::get_fields($type) as $tag => $v ){ 89 | echo ''.$v['label'].''; 90 | } 91 | } 92 | 93 | 94 | public static function woo_box_html($option_name='') { 95 | 96 | if( !is_plugin_active( 'woocommerce/woocommerce.php' ) ) { 97 | echo ''; 98 | echo ''; 99 | echo ''; 100 | echo '
'. __( 'WooCommerce' , 'wp-line-notify' ) .'

('. __( 'This plugin is not install or active.' , 'wp-line-notify' ) .')

'; 101 | return; 102 | } 103 | 104 | $options = get_option($option_name); 105 | $my_status = ( !empty($options['woo_status']) ) ? $options['woo_status']:[]; 106 | ?> 107 | 108 | 109 | 110 | 114 | 115 | 116 | 117 | 182 | 183 | 184 | 185 | 191 | 192 |
111 | > 112 |
113 |
  121 | 122 | 123 | 124 | 129 | 130 | 131 | 132 | 133 | 134 | 137 | 138 | 139 | 140 | 143 | 144 | 145 | 146 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 159 | 160 | 161 | 162 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 178 | 179 | 180 |
$label ){ 126 | echo ''.$label.''; 127 | } 128 | ?>
$label ){ 157 | echo ''.$label.''; 158 | }?>
$label ){ 164 | echo ''.$label.''; 165 | }?>

175 | 176 | 177 |

181 |
186 | $name): ?> 187 | > 188 |     189 | 190 |
193 | 194 | 198 | 199 | 213 | option['token']) || empty($this->option['token']) ): ?> 8 |
9 |

10 |
11 | 12 |
13 |

14 |
15 | 16 |
17 | 18 |

Ver.version?>

19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 | 47 | 48 |
28 | 37 | 38 | option['token']) ){ 40 | $line = new sig_line_notify( $this->option['token'] ); 41 | echo ( $line->check_token() ) ? __('Access token valid.', 'wp-line-notify' ) : __( 'Invalid access token.' , 'wp-line-notify' ); 42 | } 43 | ?> 44 |

LINE Notify

45 | 46 |
49 | 50 |
51 | 52 |

53 | 54 | 55 | 56 | 57 | 70 | 71 | 72 | 85 | 86 | 87 | 88 | 89 | 96 | 97 | 98 | 99 | 100 | 107 | 108 |
58 |   ( 59 | $name ){ 63 | ?> 64 | option['post_status']['publish'] ) && in_array( $role, $this->option['post_status']['publish']) ) echo ' checked="checked"'; ?>>   67 | )
73 |   ( 74 | $name ){ 78 | ?> 79 | option['post_status']['pending'] ) && in_array( $role, $this->option['post_status']['pending']) ) echo ' checked="checked"'; ?>>   82 | )
90 | option['comments'])) echo checked( 'yes', $this->option['comments'], false )?>> 93 | 94 | 95 |
101 | option['user_register'])) echo checked( 'yes', $this->option['user_register'], false )?>> 104 | 105 | 106 |
109 | 110 |
111 | 112 | 115 |
116 | 117 | 118 | 119 | 120 | 149 | 150 |
121 | ' .__( 'When a new contact message is received.' , 'wp-line-notify' ) .'

'; 126 | 127 | $items = WPCF7_ContactForm::find(); 128 | 129 | foreach ( $items as $item ) { 130 | $pid = $item->id(); 131 | $title = $item-> title(); 132 | ?> 133 |

134 | option['wpcf7_form']) && in_array( $pid, $this->option['wpcf7_form'] ) ) echo 'checked="checked"' ?>> 137 |    138 |

139 | (' . __( 'This plugin is not install or active.' , 'wp-line-notify' ) . ')

'; 145 | } 146 | ?> 147 | 148 |
151 | 152 |
153 | 154 | 155 | 156 | 157 | 171 | 172 | 173 |
158 | 159 | option['elementor_form'])) echo checked( 'yes', $this->option['elementor_form'], false )?>> 162 | 163 | 166 |

()

167 | 168 |

()

169 | 170 |
174 | 175 | 176 | 177 |
178 | 179 |


180 | 181 |

182 | 185 |
186 | 187 | 188 | 189 | 192 | 202 | 203 |
190 | 191 | 193 | 201 |
204 | 205 | 206 | 209 | 214 | 215 |
207 | 208 | 210 | 211 |
212 | 213 |
216 | 217 |
218 |
219 | 220 | 250 | -------------------------------------------------------------------------------- /wp-line-notify.php: -------------------------------------------------------------------------------- 1 | 'Version', 'langs' => 'Domain Path') ); 33 | $this->version = $data['ver']; 34 | $this->langs = $data['langs']; 35 | 36 | if ( ! function_exists( 'is_plugin_active' ) ) { 37 | require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); 38 | } 39 | 40 | $my_option_name = $this->current_user_option_name(); 41 | 42 | $upgrade = new sig_line_notify_upgrade( $my_option_name, $this->version ); 43 | $upgrade->run(); 44 | 45 | $this->option = get_option( $my_option_name ); 46 | if( empty($this->option) ) $this->option = []; 47 | 48 | 49 | 50 | // load textdomain 51 | add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) ); 52 | 53 | // add setting line 54 | add_filter( 'plugin_action_links_'.plugin_basename(__FILE__), array( $this, 'plugin_settings_link' ) ); 55 | 56 | // add menu 57 | add_action( 'admin_menu', array( $this,'add_option_menu') ); 58 | 59 | // add register setting 60 | add_action( 'admin_init', array( $this, 'add_register_setting' ) ); 61 | 62 | // update usermeta 63 | add_action( "pre_update_option_".$this->current_user_option_name(), array( $this, 'update_option_to_usermeta' ), 10, 3 ); 64 | 65 | // add user profile 66 | add_action( 'show_user_profile', array( $this, 'add_user_profile' ), 99 ); 67 | 68 | // save user profile 69 | add_action( 'personal_options_update', array( $this, 'save_user_profile' ) ); 70 | 71 | // alert: post status 72 | add_action( 'transition_post_status', array( $this, 'post_status_alert' ), 10, 3 ); 73 | 74 | // alert: post comments 75 | add_action( 'comment_post', array( $this, 'new_comments_alert' ), 10, 2 ); 76 | 77 | // alert: user register 78 | add_action( 'user_register' , array( $this, 'new_user_register_alert' ) , 10 , 1 ); 79 | 80 | // alert: woocommerce new order, order status change 81 | if( is_plugin_active( 'woocommerce/woocommerce.php' ) ){ 82 | add_action( 'woocommerce_new_order', array( $this, 'new_woocommerce_order_alert' ) ,10, 2); 83 | add_action( 'woocommerce_order_status_changed', array( $this, 'update_woocommerce_order_status' ) ,10, 4); 84 | } 85 | 86 | // alert: contact-form-7 87 | if( is_plugin_active( 'contact-form-7/wp-contact-form-7.php' ) ) { 88 | add_action("wpcf7_before_send_mail", array($this, "new_wpcf7_message")); 89 | } 90 | 91 | // alert: elementor-pro form 92 | if( is_plugin_active( 'elementor-pro/elementor-pro.php' ) ){ 93 | add_action( 'elementor_pro/forms/actions/register', array( $this, 'register_new_form_actions') ); 94 | } 95 | 96 | // test token 97 | add_action( 'wp_ajax_sig_line_notify_test', array( $this, 'sig_line_notify_test' ) ); 98 | 99 | } 100 | 101 | /////////////// 102 | 103 | public function load_textdomain(){ 104 | load_plugin_textdomain( 'wp-line-notify' , false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); 105 | } 106 | 107 | public function plugin_settings_link( $actions) { 108 | $settings_link = array( 109 | ''. esc_html__( 'Settings' , 'wp-line-notify' ).'' 110 | ); 111 | $actions = array_merge( $actions, $settings_link ); 112 | return $actions; 113 | } 114 | 115 | public function add_option_menu(){ 116 | 117 | $capability = apply_filters( 'wp_line_notify/plugin_capabilities', 'manage_options' ); 118 | 119 | add_options_page( 120 | __( 'Line Notify Setting' , 'wp-line-notify'), 121 | __( 'WP Line Notify' , 'wp-line-notify'), 122 | $capability, 123 | 'sig-wp-line-notify', 124 | array($this, 'html_settings_page') 125 | ); 126 | } 127 | 128 | 129 | public function html_settings_page() { 130 | 131 | $option_name = $this->current_user_option_name(); 132 | $user_id = $this->sig_get_option_uid(); 133 | 134 | global $wp_roles; 135 | $roles = $wp_roles->get_names(); 136 | 137 | $web_users = WpLineNotify::sig_get_all_users(); 138 | 139 | require_once SIG_LINE_NOTIFY_DIR . '/includes/page-setup.php'; 140 | } 141 | 142 | public function add_register_setting(){ 143 | register_setting( 'line-notify-option', $this->current_user_option_name(), array('type' => 'array') ); 144 | } 145 | 146 | public function update_option_to_usermeta( $value ,$old_value, $option){ 147 | if( !empty($value['uid']) ) update_user_meta( $value['uid'], SIG_LINE_NOTIFY_OPTIONS , $value['token'] ); 148 | return $value; 149 | } 150 | 151 | public function add_user_profile($user){ 152 | 153 | $token = get_user_meta( $user->ID, SIG_LINE_NOTIFY_OPTIONS, true ); 154 | ?> 155 |

156 | 157 | 158 | 159 | 163 | 164 |
160 | 161 |

LINE Notify

162 |
165 | post_type !== 'post' ) return; 194 | 195 | if( $new_status === $old_status ) return; 196 | 197 | $post_status = $new_status; 198 | 199 | $status = [ 200 | 'publish' => __( 'publish a post' , 'wp-line-notify' ), 201 | 'pending' => __( 'pending a post' , 'wp-line-notify' ) 202 | ]; 203 | 204 | if( !isset( $status[$post_status] ) ){ 205 | return; 206 | }else{ 207 | $alert_text = $status[$post_status]; 208 | } 209 | 210 | /// 211 | $author = get_userdata( $post->post_author ); 212 | if( !is_object($author) ){ 213 | return; 214 | }else{ 215 | $roles = (array)$author->roles; 216 | } 217 | 218 | $token = []; 219 | 220 | foreach( self::sig_get_all_options() as $option ){ 221 | 222 | if( !empty($option['token']) && isset($option['post_status']) && isset($option['post_status'][$post_status]) ) { 223 | 224 | $roles_alert = $option['post_status'][$post_status]; 225 | 226 | foreach( $roles as $role_name ){ 227 | if( in_array( $role_name, $roles_alert ) ){ 228 | $token[] = $option['token']; 229 | break; 230 | } 231 | } 232 | 233 | } 234 | } 235 | 236 | if( !empty( $token ) ){ 237 | $message = "{$author->display_name} {$alert_text} \n {$post->post_title} {$post->guid}"; 238 | $this->send_msg( $token, $message ); 239 | } 240 | 241 | } 242 | 243 | public function new_comments_alert( $comment_ID, $comment_approved ) { 244 | 245 | $token = []; 246 | 247 | foreach( self::sig_get_all_options() as $option ){ 248 | if( !empty($option['token']) && isset($option['comments']) && $option['comments'] === 'yes' ){ 249 | $token[] = $option['token']; 250 | } 251 | } 252 | 253 | if( !empty( $token ) ){ 254 | $comment = get_comment( $comment_ID ); 255 | $message = __( 'You have a new comment.' , 'wp-line-notify' ) . "\n" . $comment->comment_content; 256 | $this->send_msg( $token, $message ); 257 | } 258 | 259 | } 260 | 261 | public function new_user_register_alert( $user_id ) { 262 | 263 | $token = []; 264 | 265 | foreach( self::sig_get_all_options() as $option ){ 266 | if( !empty($option['token']) && isset($option['user_register']) && $option['user_register'] === 'yes' ){ 267 | $token[] = $option['token']; 268 | } 269 | } 270 | 271 | if( !empty( $token ) ){ 272 | $user_info = get_userdata($user_id); 273 | $message = __( 'You have a new user register.' , 'wp-line-notify' ); 274 | $message .= __( 'Username:' , 'wp-line-notify' ) . $user_info->user_login; 275 | $this->send_msg( $token, $message ); 276 | } 277 | } 278 | 279 | public function new_woocommerce_order_alert( $order_id, $order ) { 280 | 281 | $token = []; 282 | 283 | foreach( self::sig_get_all_options() as $option ){ 284 | if( !empty($option['token']) && isset($option['woo_order']) && $option['woo_order'] === 'yes' ){ 285 | $token[] = $option['token']; 286 | } 287 | } 288 | 289 | if( !empty( $token ) ){ 290 | 291 | if( isset($this->option['woo_tpl']) && !empty($this->option['woo_tpl']) ){ 292 | $message = $this->option['woo_tpl']; 293 | }else{ 294 | $message = sig_line_notify_woo::form(); 295 | } 296 | 297 | $order_data = $order->get_data(); 298 | $order_product = ''; 299 | 300 | if( isset($order_data['line_items'] ) && count( $order_data['line_items'] ) > 0 ){ 301 | foreach( $order_data['line_items'] as $item ){ 302 | if( isset($item['name']) && isset($item['quantity']) ){ 303 | $product = $order->get_product_from_item( $item ); 304 | $sku = $product->get_sku(); 305 | if( !empty($sku) ){ 306 | $order_product .= "\n {$item['name']} [" . $product->get_sku() . "] x {$item['quantity']}"; 307 | }else{ 308 | $order_product .= "\n {$item['name']} x {$item['quantity']}"; 309 | } 310 | 311 | } 312 | } 313 | } 314 | 315 | $order_name = (isset($order_data['billing']['first_name']) && isset($order_data['billing']['last_name'])) ? ($order_data['billing']['last_name'].$order_data['billing']['first_name']) : '-'; 316 | 317 | $shipping_name = (isset($order_data['shipping']['first_name']) && isset($order_data['shipping']['last_name'])) ? ($order_data['shipping']['last_name'].$order_data['shipping']['first_name']) : ''; 318 | 319 | $text = array( 320 | '[order-id]' => $order_id, 321 | '[order-product]' => $order_product, 322 | '[order-name]' => $order_name, 323 | '[shipping-name]' => $shipping_name, 324 | '[payment-method]' => (isset($order_data['payment_method_title'])) ? $order_data['payment_method_title'] : '', 325 | '[total]' => (isset($order_data['total'])) ? $order_data['total'] : '', 326 | '[order-time]' => (isset($order_data['date_created'])) ? $order_data['date_created']->date('Y-m-d H:i:s') : '', 327 | '[customer_note]' => (isset($order_data['customer_note'])) ? $order_data['customer_note'] : '', 328 | ); 329 | 330 | // Checkout Field Editor for WooCommerce 331 | if( class_exists('THWCFD_Utils') ) { 332 | 333 | $metas = get_post_meta( $order_data['id'] ); 334 | 335 | // billing 336 | foreach( sig_line_notify_woo::get_fields('billing') as $tag => $v ){ 337 | $text["[{$tag}]"] = ( isset($metas['_'.$tag]) ) ? $metas['_'.$tag][0] : ''; 338 | } 339 | 340 | // shipping 341 | foreach( sig_line_notify_woo::get_fields('shipping') as $tag => $v ){ 342 | $text["[{$tag}]"] = ( isset($metas['_'.$tag]) ) ? $metas['_'.$tag][0] : ''; 343 | } 344 | 345 | // Additional Fields 346 | foreach( sig_line_notify_woo::get_fields('additional') as $tag => $label ){ 347 | if( $tag === 'order_comments' ){ 348 | $text["[{$tag}]"] = ( isset($order_data['customer_note']) ) ? $order_data['customer_note']:''; 349 | }else{ 350 | $text["[{$tag}]"] = ( isset($metas[$tag]) ) ? $metas[$tag][0] : ''; 351 | } 352 | } 353 | 354 | }else{ 355 | // billing 356 | foreach( sig_line_notify_woo::init('billing') as $tag => $label ){ 357 | $field = str_replace('billing_' ,'' , $tag); 358 | if( isset($order_data['billing'][$field]) ){ 359 | $text["[{$tag}]"] = $order_data['billing'][$field]; 360 | } 361 | } 362 | 363 | // shipping 364 | foreach( sig_line_notify_woo::init('shipping') as $tag => $label ){ 365 | $field = str_replace('shipping_','',$tag); 366 | if( isset($order_data['shipping'][$field]) ){ 367 | $text["[{$tag}]"] = $order_data['shipping'][$field]; 368 | } 369 | } 370 | } 371 | 372 | $message = str_ireplace( array_keys($text), $text, $message ); 373 | $this->send_msg( $token, $message ); 374 | } 375 | 376 | } 377 | 378 | public function update_woocommerce_order_status($order_id, $old_status, $new_status, $order) { 379 | 380 | $token = []; 381 | 382 | foreach( self::sig_get_all_options() as $option ){ 383 | if( !empty($option['token']) && isset($option['woo_status']) ){ 384 | if( ( $old_status !== $new_status ) && in_array( 'wc-'.$new_status, $option['woo_status'] ) ){ 385 | $token[] = $option['token']; 386 | } 387 | } 388 | } 389 | 390 | if( !empty( $token ) ){ 391 | /* translators: %1$s is order id, %2$s is order state. */ 392 | $message = sprintf( __('There is an order id %1$d, and the state is changed to %2$s.', 'wp-line-notify'), $order_id, wc_get_order_status_name($new_status) ); 393 | $message .= admin_url( 'post.php?post=' . absint( $order_id ) . '&action=edit' ); 394 | $this->send_msg( $token, $message ); 395 | } 396 | 397 | } 398 | 399 | public function new_wpcf7_message( $contact_form ) { 400 | 401 | $token = []; 402 | $wpcf7_id = $contact_form->id(); 403 | 404 | foreach( self::sig_get_all_options() as $option ){ 405 | if( !empty($option['token']) && isset($option['wpcf7_form']) && !empty($option['wpcf7_form']) ){ 406 | if( in_array( $wpcf7_id, $option['wpcf7_form']) ) { 407 | $token[] = $option['token']; 408 | } 409 | } 410 | } 411 | 412 | if( !empty( $token ) ){ 413 | 414 | $mail_body = $contact_form->prop('mail')['body']; 415 | $message = __( "You have a new contact message.\n" , 'wp-line-notify' ); 416 | $message .= wpcf7_mail_replace_tags( $mail_body ); 417 | 418 | $this->send_msg( $token, $message ); 419 | } 420 | 421 | } 422 | 423 | public function register_new_form_actions( $form_actions_registrar ){ 424 | 425 | $token = []; 426 | 427 | foreach( self::sig_get_all_options() as $option ){ 428 | if( !empty($option['token']) && isset($option['elementor_form']) && $option['elementor_form'] === 'yes' ){ 429 | $token[] = $option['token']; 430 | } 431 | } 432 | 433 | require_once( SIG_LINE_NOTIFY_DIR . '/includes/class-elementor.php' ); 434 | $form_actions_registrar->register( new \Line_Notify_After_Submit_Action( $token ) ); 435 | 436 | } 437 | 438 | /** 439 | * 440 | */ 441 | public function send_msg( $tokens=[], $message=''){ 442 | 443 | if( empty( $tokens ) || empty( $message ) ) return; 444 | 445 | foreach( $tokens as $token ){ 446 | $line = new sig_line_notify( $token ); 447 | $line->send( $message ); 448 | } 449 | 450 | } 451 | 452 | /** 453 | * return string 454 | */ 455 | public function current_user_option_name(){ 456 | $user_id = $this->sig_get_option_uid(); 457 | $option_name = SIG_LINE_NOTIFY_OPTIONS; 458 | if ( !empty($user_id) ) { 459 | $option_name .= '_'.$user_id; 460 | } 461 | return $option_name; 462 | } 463 | 464 | /** 465 | * return array 466 | */ 467 | public static function sig_get_all_options(){ 468 | 469 | $options = []; 470 | $options[0] = get_option( SIG_LINE_NOTIFY_OPTIONS); 471 | 472 | $users = self::sig_get_all_users(); 473 | foreach( $users as $user ){ 474 | if( !empty(get_option( SIG_LINE_NOTIFY_OPTIONS."_{$user->ID}" )) ){ 475 | $options[$user->ID] = get_option( SIG_LINE_NOTIFY_OPTIONS."_{$user->ID}" ); 476 | } 477 | } 478 | 479 | return $options; 480 | } 481 | 482 | /** 483 | * return array 484 | */ 485 | public static function sig_get_all_users(){ 486 | return get_users( array( 'role__in' => array( 'administrator', 'editor', 'author', 'contributor', 'shop_manager' ) ) ); 487 | } 488 | 489 | /** 490 | * Test token 491 | */ 492 | public function sig_line_notify_test(){ 493 | 494 | $rs_msg = ""; 495 | 496 | check_admin_referer('sig_line_notify_test_nonce'); 497 | 498 | $message = sanitize_textarea_field( $_POST['line_notify_content_test'] ); 499 | if( empty($message) ) $message = __( 'This is a Line notify plugin test.' , 'wp-line-notify' ); 500 | 501 | $option_name = SIG_LINE_NOTIFY_OPTIONS; 502 | $user_id = ! empty( $_POST['line_notify_uid_test'] ) ? absint( wp_unslash( $_POST['line_notify_uid_test'] ) ) : null; 503 | if( !empty($user_id) ) $option_name .= '_'.$user_id; 504 | 505 | $option = get_option( $option_name ); 506 | 507 | if( empty($option['token']) ){ 508 | $rs_msg = __( 'Please fill in the top Line Notify Token field.' , 'wp-line-notify' ); 509 | }else{ 510 | 511 | $line = new sig_line_notify( $option['token'] ); 512 | $rs = $line->send( $message ); 513 | 514 | if ( $rs === 'ok' ) { 515 | $rs_msg = __( 'Send test ok!' , 'wp-line-notify' ); 516 | } else { 517 | $rs_msg = sprintf('%1s, message: %2s', __( 'Error on send LINE Notify.' , 'wp-line-notify' ), sanitize_text_field($rs) ); 518 | } 519 | 520 | } 521 | 522 | wp_die( $rs_msg ); 523 | } 524 | 525 | /** 526 | * return int or null 527 | */ 528 | public function sig_get_option_uid(){ 529 | $user_id = ! empty( $_GET['uid'] ) ? absint( wp_unslash( $_GET['uid'] ) ) : null; 530 | if ( ! empty($user_id) ) { 531 | $userdata = get_user_by( 'id',$user_id ); 532 | if ( ! $userdata ) { 533 | wp_redirect( admin_url( 'options-general.php?page=sig-wp-line-notify' ) ); 534 | die(); 535 | } 536 | } 537 | return $user_id; 538 | } 539 | } 540 | 541 | add_action( 'plugins_loaded', 'wp_line_notify', 10, 0 ); 542 | 543 | function wp_line_notify(){ 544 | new WpLineNotify(); 545 | } 546 | --------------------------------------------------------------------------------