Plugin Directory

Changeset 2388783


Ignore:
Timestamp:
09/26/2020 09:30:31 AM (6 years ago)
Author:
arbn
Message:

upgraded to version 1.0.1

Location:
arrowdan-notifier/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • arrowdan-notifier/trunk/arrowdan-notifier.php

    r2296449 r2388783  
    33Plugin Name: ARROWDAN Notifier
    44Description: Notify users using Firebase Cloud Messaging (FCM) when post is published.
    5 Version: 1.0
     5Version: 1.0.1
    66Author: ArBn
    7 Author URI: https://www.arbn.com.np
     7Author URI: https://www.ar-bn.com
    88License: GPL2
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1010 */
    1111if (!defined('ABSPATH')) {exit;}
    12 if (!defined("AFCMPN_VERSION_CURRENT")) define("AFCMPN_VERSION_CURRENT", '1');
     12if (!defined("AFCMPN_VERSION_CURRENT")) define("AFCMPN_VERSION_CURRENT", '1.0.1');
    1313if (!defined("AFCMPN_URL")) define("AFCMPN_URL", plugin_dir_url( __FILE__ ) );
    1414if (!defined("AFCMPN_PLUGIN_DIR")) define("AFCMPN_PLUGIN_DIR", plugin_dir_path(__FILE__));
     
    2424        add_action('admin_menu', array($this, 'afcmpn_admin_menu'));
    2525        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);
    2728        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        }
    2853    }
    2954
     
    6085    {
    6186        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');
    6389    }
    6490
     
    7298        $test = new ARROWDANTestNotifier;
    7399        $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.";
    76102        $test->post_excerpt = $test->post_content;
    77103        $result = $this->arrowdan_notifier($test);
     
    94120        $post_title = wp_strip_all_tags($post->post_title);       
    95121        $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        }
    96129        $notification = array(
    97130            'title'                 => $post_title,
    98131            'body'                  => $post_content,
    99             'sound'                 => 'default',     
     132            'sound'                 => 'default',
     133            'click_action'          => 'FLUTTER_NOTIFICATION_CLICK',
     134            'image'                 => $image,   
    100135        );
    101136        $data = array(
    102137            'message'               => $post_content,
    103138            'title'                 => $post_title,
     139            'image'                 => $image,
     140            'id'                    => $post_id,
    104141        );   
    105142        $post = array(
     
    127164    }
    128165
    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);
    138195                    }
    139196                }
     197               
    140198            }
    141199        }
    142200    }
     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
    143220    public function afcmpn_activate()
    144221    {
     
    154231    public  $post_title;
    155232    public  $post_content;
    156     public  $post_excerpt;   
     233    public  $post_excerpt;
    157234}
    158235$ARROWDAN_FCM_PN_OBJ = new ARROWDAN_FCM_PN();
  • arrowdan-notifier/trunk/dashboard.php

    r2296449 r2388783  
    1414        </tr>
    1515        <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>
    1822        </tr>
    1923        <tr>
  • arrowdan-notifier/trunk/readme.txt

    r2296449 r2388783  
    11=== ARROWDAN Notifier ===
    22Contributors: arbn
    3 Donate link: https://ko-fi.com/arabindra
    43Tags: notifier, notification, android, ios, flutter, firebase, fcm,
    54Requires at least: 4.6
    6 Tested up to: 5.4.1
    7 Stable tag: 1.0
     5Tested up to: 5.5.1
     6Stable tag: 1.0.1
    87Requires PHP: 5.6.20
    98License: GPLv2 or later
     
    1615
    1716**Features**
    18 * Notify on post publish
    19 * Notify on post updated
     17* Notify on post publish/update with image
     18* Control directly from post sidebar
    2019
    2120== Installation ==
     
    2726
    2827== Frequently Asked Questions ==
    29 = Can I disable notification on post update ? =
    30 Yes. You can disbale by checking in Disable Notification on Post Update.
    3128= Can I send notification to other topic ? =
    3229No. You can send notification only to topic post.
     
    3532
    3633== 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
    3738= 1.0.0 =
    3839* First version.
Note: See TracChangeset for help on using the changeset viewer.