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

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