PluginProbe
Push Notifications for WP – Self Hosted Web Push Notifications / 1.18
Push Notifications for WP – Self Hosted Web Push Notifications v1.18
1.52 1.51 trunk 1.0 1.1 1.10 1.11 1.12 1.12.1 1.13 1.14 1.15 1.16 1.17 1.18 1.19 1.2 1.20 1.21 1.22 1.23 1.24 1.25 1.25.1 1.26 All 58 releases
push-notification / push-notification.php

push-notification.php in Push Notifications for WP – Self Hosted Web Push Notifications 1.18, at push-notification.php

108 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 Plugin Name: Push Notification
4 Plugin URI: https://wordpress.org/plugins/push-notification/
5 Description: Push Notification allow admin to automatically notify your audience when you have published new content on your site or custom notices
6 Author: Magazine3
7 Version: 1.18
8 Author URI: http://pushnotifications.io/
9 Text Domain: push-notification
10 Domain Path: /languages
11 License: GPL2+
12 */
13
14 // Exit if accessed directly.
15 if ( ! defined( 'ABSPATH' ) ) exit;
16
17 define('PUSH_NOTIFICATION_PLUGIN_FILE', __FILE__ );
18 define('PUSH_NOTIFICATION_PLUGIN_DIR', plugin_dir_path( __FILE__ ));
19 define('PUSH_NOTIFICATION_PLUGIN_URL', plugin_dir_url( __FILE__ ));
20 define('PUSH_NOTIFICATION_PLUGIN_VERSION', '1.18');
21 define('PUSH_NOTIFICATION_PLUGIN_BASENAME', plugin_basename(__FILE__));
22
23 /**
24 * Initialize pwa functions
25 */
26 add_action('plugins_loaded', 'push_notification_initialize');
27 function push_notification_initialize(){
28 require_once PUSH_NOTIFICATION_PLUGIN_DIR."inc/admin/admin.php";
29 require_once PUSH_NOTIFICATION_PLUGIN_DIR."inc/admin/newsletter.php";
30 if(is_admin()){
31 add_filter( 'plugin_action_links_' . PUSH_NOTIFICATION_PLUGIN_BASENAME,'push_notification_add_action_links', 10, 4);
32 }
33 if( !is_admin() || wp_doing_ajax() ){
34 require_once PUSH_NOTIFICATION_PLUGIN_DIR."inc/frontend/pn-frontend.php";
35 }
36 if ( class_exists( 'OneSignal' ) ) {
37 add_action('admin_notices', 'push_notification_feature_notice');
38 }
39 }
40
41 function push_notification_feature_notice(){
42 $class = 'notice notice-warning';
43 $message = esc_html__( 'There is may some conflict issue with the other push notification plugin. To take benefit all features of the Push Notification plugin, Please deactivate the OneSignal plugin.', 'push-notification' );
44
45 printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
46 }
47
48
49 function push_notification_add_action_links($actions, $plugin_file, $plugin_data, $context){
50 $mylinks = array('<a href="' . esc_url_raw(admin_url( 'admin.php?page=push-notification' )) . '">'.esc_html__( 'Settings', 'push-notification' ).'</a>',
51 '<a href="https://pushnotifications.io/documentation/" target="_blank">'.esc_html__( 'Documentation', 'push-notification' ).'</a>',
52 );
53 return array_merge( $actions, $mylinks );
54 }
55
56 register_activation_hook( PUSH_NOTIFICATION_PLUGIN_FILE, 'push_notification_on_activate' );
57 function push_notification_on_activate(){
58 /** Setup notification feature in PWA-for-wp*/
59 $pwaforwp_settings = get_option( 'pwaforwp_settings');
60 if(isset($pwaforwp_settings['notification_feature']) && $pwaforwp_settings['notification_feature']==0){
61 $pwaforwp_settings['notification_feature'] = 1;
62 update_option( 'pwaforwp_settings', $pwaforwp_settings);
63 }
64
65 /**
66 * on activation of plugin compatibile with PWA for wp
67 * if PWA activated and now activating PushNotification, Need to regenerate service worker files
68 */
69 $auth_settings = get_option( 'push_notification_auth_settings', array() );
70 //Push notification Check
71 if(isset($auth_settings['user_token']) && isset($auth_settings['token_details']['validated']) && $auth_settings['token_details']['validated'] == 1){
72 //pwaforamp check
73 if( function_exists('pwaforwp_required_file_creation') ){
74 $pwaSettings = pwaforwp_defaultSettings();
75 if( $pwaSettings['notification_feature']==1 && isset($pwaSettings['notification_options']) && $pwaSettings['notification_options']=='pushnotifications_io'){
76 pwaforwp_required_file_creation();
77 }
78 }
79
80 }
81 }
82 /**
83 * After activate plugin path to redirect
84 * @plugin name of current activation plugin
85 */
86 function push_notification_after_activation_redirect( $plugin ) {
87 if( $plugin == plugin_basename( PUSH_NOTIFICATION_PLUGIN_FILE ) ) {
88 exit( wp_redirect( admin_url( 'admin.php?page=push-notification' ) ) );
89 }
90 }
91 add_action( 'activated_plugin', 'push_notification_after_activation_redirect' );
92
93
94 /**
95 * TO compatible with older < 1.3 of pushnotification
96 */
97 add_action("plugins_loaded", 'push_notification_older_version_compatibility');
98 function push_notification_older_version_compatibility(){
99 $configCompatible = get_transient( 'push_notification_older_version' );
100
101 if(!$configCompatible){
102 $auth_settings = push_notification_auth_settings();
103 if( isset($auth_settings['user_token']) && isset($auth_settings['token_details']['validated']) && $auth_settings['token_details']['validated'] == 1 && !isset($auth_settings['messageManager']) ){
104 $response = PN_Server_Request::varifyUser($auth_settings['user_token']);
105 set_transient( 'push_notification_older_version', 1 );
106 }
107 }
108 }