PluginProbe
Push Notifications for WP – Self Hosted Web Push Notifications / 1.21
Push Notifications for WP – Self Hosted Web Push Notifications v1.21
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.21, at push-notification.php

109 lines 4.7 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.21
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.21');
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 require_once PUSH_NOTIFICATION_PLUGIN_DIR."inc/compatibility/ultimate-member.php";
31 if(is_admin()){
32 add_filter( 'plugin_action_links_' . PUSH_NOTIFICATION_PLUGIN_BASENAME,'push_notification_add_action_links', 10, 4);
33 }
34 if( !is_admin() || wp_doing_ajax() ){
35 require_once PUSH_NOTIFICATION_PLUGIN_DIR."inc/frontend/pn-frontend.php";
36 }
37 if ( class_exists( 'OneSignal' ) ) {
38 add_action('admin_notices', 'push_notification_feature_notice');
39 }
40 }
41
42 function push_notification_feature_notice(){
43 $class = 'notice notice-warning';
44 $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' );
45
46 printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
47 }
48
49
50 function push_notification_add_action_links($actions, $plugin_file, $plugin_data, $context){
51 $mylinks = array('<a href="' . esc_url_raw(admin_url( 'admin.php?page=push-notification' )) . '">'.esc_html__( 'Settings', 'push-notification' ).'</a>',
52 '<a href="https://pushnotifications.io/documentation/" target="_blank">'.esc_html__( 'Documentation', 'push-notification' ).'</a>',
53 );
54 return array_merge( $actions, $mylinks );
55 }
56
57 register_activation_hook( PUSH_NOTIFICATION_PLUGIN_FILE, 'push_notification_on_activate' );
58 function push_notification_on_activate(){
59 /** Setup notification feature in PWA-for-wp*/
60 $pwaforwp_settings = get_option( 'pwaforwp_settings');
61 if(isset($pwaforwp_settings['notification_feature']) && $pwaforwp_settings['notification_feature']==0){
62 $pwaforwp_settings['notification_feature'] = 1;
63 update_option( 'pwaforwp_settings', $pwaforwp_settings);
64 }
65
66 /**
67 * on activation of plugin compatibile with PWA for wp
68 * if PWA activated and now activating PushNotification, Need to regenerate service worker files
69 */
70 $auth_settings = get_option( 'push_notification_auth_settings', array() );
71 //Push notification Check
72 if(isset($auth_settings['user_token']) && isset($auth_settings['token_details']['validated']) && $auth_settings['token_details']['validated'] == 1){
73 //pwaforamp check
74 if( function_exists('pwaforwp_required_file_creation') ){
75 $pwaSettings = pwaforwp_defaultSettings();
76 if( $pwaSettings['notification_feature']==1 && isset($pwaSettings['notification_options']) && $pwaSettings['notification_options']=='pushnotifications_io'){
77 pwaforwp_required_file_creation();
78 }
79 }
80
81 }
82 }
83 /**
84 * After activate plugin path to redirect
85 * @plugin name of current activation plugin
86 */
87 function push_notification_after_activation_redirect( $plugin ) {
88 if( $plugin == plugin_basename( PUSH_NOTIFICATION_PLUGIN_FILE ) ) {
89 exit( wp_redirect( admin_url( 'admin.php?page=push-notification' ) ) );
90 }
91 }
92 add_action( 'activated_plugin', 'push_notification_after_activation_redirect' );
93
94
95 /**
96 * TO compatible with older < 1.3 of pushnotification
97 */
98 add_action("plugins_loaded", 'push_notification_older_version_compatibility');
99 function push_notification_older_version_compatibility(){
100 $configCompatible = get_transient( 'push_notification_older_version' );
101
102 if(!$configCompatible){
103 $auth_settings = push_notification_auth_settings();
104 if( isset($auth_settings['user_token']) && isset($auth_settings['token_details']['validated']) && $auth_settings['token_details']['validated'] == 1 && !isset($auth_settings['messageManager']) ){
105 $response = PN_Server_Request::varifyUser($auth_settings['user_token']);
106 set_transient( 'push_notification_older_version', 1 );
107 }
108 }
109 }