Changeset 2388783
- Timestamp:
- 09/26/2020 09:30:31 AM (6 years ago)
- Location:
- arrowdan-notifier/trunk
- Files:
-
- 3 edited
-
arrowdan-notifier.php (modified) (7 diffs)
-
dashboard.php (modified) (1 diff)
-
readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
arrowdan-notifier/trunk/arrowdan-notifier.php
r2296449 r2388783 3 3 Plugin Name: ARROWDAN Notifier 4 4 Description: Notify users using Firebase Cloud Messaging (FCM) when post is published. 5 Version: 1.0 5 Version: 1.0.1 6 6 Author: ArBn 7 Author URI: https://www.ar bn.com.np7 Author URI: https://www.ar-bn.com 8 8 License: GPL2 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 */ 11 11 if (!defined('ABSPATH')) {exit;} 12 if (!defined("AFCMPN_VERSION_CURRENT")) define("AFCMPN_VERSION_CURRENT", '1 ');12 if (!defined("AFCMPN_VERSION_CURRENT")) define("AFCMPN_VERSION_CURRENT", '1.0.1'); 13 13 if (!defined("AFCMPN_URL")) define("AFCMPN_URL", plugin_dir_url( __FILE__ ) ); 14 14 if (!defined("AFCMPN_PLUGIN_DIR")) define("AFCMPN_PLUGIN_DIR", plugin_dir_path(__FILE__)); … … 24 24 add_action('admin_menu', array($this, 'afcmpn_admin_menu')); 25 25 add_action('admin_init', array($this, 'afcmpn_settings')); 26 add_action( 'save_post', array($this, 'afcmpn_post'), 10, 3); 26 add_action( 'save_post', array($this, 'afcmpn_meta_save'), 1); 27 add_action( 'add_meta_boxes', array($this, 'afcmpn_featured_meta'), 1); 27 28 add_filter( 'plugin_action_links_arrowdan-notifier/arrowdan-notifier.php', array($this, 'afcmpn_settings_link')); 29 } 30 31 function afcmpn_featured_meta() { 32 $args = array( 33 'public' => true, 34 ); 35 $post_types = get_post_types( $args, 'objects' ); 36 if ( $post_types ) { // If there are any custom public post types. 37 38 foreach ( $post_types as $post_type ) { 39 if ($post_type->name != 'attachment'){ 40 if ($this->get_options_posttype($post_type->name) && get_option('afcmpn_disable') != 1) { 41 add_meta_box( 'afcmpn_ckmeta_send_notification', esc_attr(__( 'ARROWDAN Notifier', AFCMPN_T )), array($this, 'afcmpn_meta_callback'), $post_type->name, 'side', 'high', null ); 42 } 43 } 44 } 45 46 } 47 } 48 49 function get_options_posttype($post_type) { 50 if ($post_type == "post") { 51 return true; 52 } 28 53 } 29 54 … … 60 85 { 61 86 register_setting('afcmpn_group', 'afcmpn_api'); 62 register_setting('afcmpn_group', 'afcmpn_disable_update'); 87 register_setting('afcmpn_group', 'afcmpn_disable_image'); 88 register_setting('afcmpn_group', 'afcmpn_disable'); 63 89 } 64 90 … … 72 98 $test = new ARROWDANTestNotifier; 73 99 $test->ID = 0; 74 $test->post_title = "Test Notification Title";75 $test->post_content = "Hi I am ArBn. This is test notification body";100 $test->post_title = "Test Notification"; 101 $test->post_content = "Hi I am ArBn. You are using ARROWDAN Notifier."; 76 102 $test->post_excerpt = $test->post_content; 77 103 $result = $this->arrowdan_notifier($test); … … 94 120 $post_title = wp_strip_all_tags($post->post_title); 95 121 $post_content = _mb_strlen($post->post_excerpt) == 0 ? _mb_substr(wp_strip_all_tags($post->post_content), 0, 55) : wp_strip_all_tags($post->post_excerpt); 122 $post_id = esc_attr($post->ID); 123 $thumb_id = get_post_thumbnail_id( $post_id ); 124 $thumb_url = wp_get_attachment_image_src( $thumb_id, 'full' ); 125 $image = $thumb_url ? esc_url($thumb_url[0]) : ''; 126 if (_mb_strlen($image) == 0 || get_option('afcmpn_disable_image') == 1) { 127 $image = null; 128 } 96 129 $notification = array( 97 130 'title' => $post_title, 98 131 'body' => $post_content, 99 'sound' => 'default', 132 'sound' => 'default', 133 'click_action' => 'FLUTTER_NOTIFICATION_CLICK', 134 'image' => $image, 100 135 ); 101 136 $data = array( 102 137 'message' => $post_content, 103 138 'title' => $post_title, 139 'image' => $image, 140 'id' => $post_id, 104 141 ); 105 142 $post = array( … … 127 164 } 128 165 129 function afcmpn_post($post_id, $post, $update) 130 { 131 if(get_option('afcmpn_api')) { 132 if (isset($post->post_status)) { 133 if($post->post_status == 'publish' && $post->post_type == 'post'){ 134 if($update && get_option('afcmpn_disable_update') == 1){ 135 return; 136 } else { 137 $this->arrowdan_notifier($post); 166 function afcmpn_meta_save( $post_id ) { 167 $is_autosave = wp_is_post_autosave( $post_id ); 168 $is_revision = wp_is_post_revision( $post_id ); 169 $is_valid_nonce = ( isset( $_POST[ 'afcmpn_nonce' ] ) && wp_verify_nonce( $_POST[ 'afcmpn_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false'; 170 if ( $is_autosave || $is_revision || !$is_valid_nonce ) { 171 return; 172 } 173 remove_action('wp_insert_post', array($this, 'afcmpn_post_save'),10); 174 175 // Checks for input and saves - save checked as yes and unchecked at no 176 if( isset( $_POST[ 'send-fcm-checkbox' ] ) ) { 177 update_post_meta( $post_id, 'send-fcm-checkbox', '1' ); 178 } else { 179 update_post_meta( $post_id, 'send-fcm-checkbox', '0' ); 180 } 181 182 add_action('wp_insert_post', array($this, 'afcmpn_post_save'),10, 3); 183 184 } 185 186 function afcmpn_post_save($post_id, $post, $update) 187 { 188 if(get_option('afcmpn_api') && isset($post->post_status) && $post->post_status == 'publish') { 189 if ($update) { 190 if (get_post_meta( $post_id, 'send-fcm-checkbox', true )) { 191 if ($this->get_options_posttype($post->post_type)) { 192 $result = $this->arrowdan_notifier($post); 193 } elseif ($this->get_options_posttype($post->post_type)) { 194 $result = $this->arrowdan_notifier($post); 138 195 } 139 196 } 197 140 198 } 141 199 } 142 200 } 201 202 function afcmpn_meta_callback( $post ) { 203 wp_nonce_field( basename( __FILE__ ), 'afcmpn_nonce' ); 204 $afcmpn_stored_meta = get_post_meta( $post->ID ); 205 ?> 206 207 <p> 208 <span class="fcm-row-title"><?php echo esc_html(__( 'Check to send push notification: ', AFCMPN_T ));?></span> 209 <div class="fcm-row-content"> 210 <label for="send-fcm-checkbox"> 211 <input type="checkbox" name="send-fcm-checkbox" id="send-fcm-checkbox" value="1" checked/> 212 <?php echo esc_attr(__( 'Send Push Notification', AFCMPN_T ));?> 213 </label> 214 </div> 215 </p> 216 217 <?php 218 } 219 143 220 public function afcmpn_activate() 144 221 { … … 154 231 public $post_title; 155 232 public $post_content; 156 public $post_excerpt; 233 public $post_excerpt; 157 234 } 158 235 $ARROWDAN_FCM_PN_OBJ = new ARROWDAN_FCM_PN(); -
arrowdan-notifier/trunk/dashboard.php
r2296449 r2388783 14 14 </tr> 15 15 <tr height="50"> 16 <td style="width: 30%;"><b><label for="afcmpn_disable_update"><?php echo __("Disable Notification on Post Update", AFCMPN_T);?></label></b></td> 17 <td><input id="afcmpn_disable_update" name="afcmpn_disable_update" type="checkbox" value="1" <?php checked( '1', get_option( 'afcmpn_disable_update' ) ); ?>></td> 16 <td style="width: 30%;"><b><label for="afcmpn_disable_image"><?php echo __("Disable Image Notification", AFCMPN_T);?></label></b></td> 17 <td><input id="afcmpn_disable_image" name="afcmpn_disable_image" type="checkbox" value="1" <?php checked( '1', get_option( 'afcmpn_disable_image' ) ); ?>></td> 18 </tr> 19 <tr height="50"> 20 <td style="width: 30%;"><b><label for="afcmpn_disable"><?php echo __("Disable Push Notification", AFCMPN_T);?></label></b></td> 21 <td><input id="afcmpn_disable" name="afcmpn_disable" type="checkbox" value="1" <?php checked( '1', get_option( 'afcmpn_disable' ) ); ?>></td> 18 22 </tr> 19 23 <tr> -
arrowdan-notifier/trunk/readme.txt
r2296449 r2388783 1 1 === ARROWDAN Notifier === 2 2 Contributors: arbn 3 Donate link: https://ko-fi.com/arabindra4 3 Tags: notifier, notification, android, ios, flutter, firebase, fcm, 5 4 Requires at least: 4.6 6 Tested up to: 5. 4.17 Stable tag: 1.0 5 Tested up to: 5.5.1 6 Stable tag: 1.0.1 8 7 Requires PHP: 5.6.20 9 8 License: GPLv2 or later … … 16 15 17 16 **Features** 18 * Notify on post publish 19 * Notify on post updated17 * Notify on post publish/update with image 18 * Control directly from post sidebar 20 19 21 20 == Installation == … … 27 26 28 27 == Frequently Asked Questions == 29 = Can I disable notification on post update ? =30 Yes. You can disbale by checking in Disable Notification on Post Update.31 28 = Can I send notification to other topic ? = 32 29 No. You can send notification only to topic post. … … 35 32 36 33 == Changelog == 34 = 1.0.1 = 35 * Notification with image and post ID added 36 * Option to disable Notification and Image Notification 37 * Notification can be directly controlled from post 37 38 = 1.0.0 = 38 39 * First version.
Note: See TracChangeset
for help on using the changeset viewer.