| 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.11 |
| 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.11'); |
| 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 |
} |
| 37 |
|
| 38 |
|
| 39 |
function push_notification_add_action_links($actions, $plugin_file, $plugin_data, $context){ |
| 40 |
$mylinks = array('<a href="' . esc_url_raw(admin_url( 'admin.php?page=push-notification' )) . '">'.esc_html__( 'Settings', 'push-notification' ).'</a>', |
| 41 |
'<a href="https://pushnotifications.io/documentation/" target="_blank">'.esc_html__( 'Documentation', 'push-notification' ).'</a>', |
| 42 |
); |
| 43 |
return array_merge( $actions, $mylinks ); |
| 44 |
} |
| 45 |
|
| 46 |
register_activation_hook( PUSH_NOTIFICATION_PLUGIN_FILE, 'push_notification_on_activate' ); |
| 47 |
function push_notification_on_activate(){ |
| 48 |
/** Setup notification feature in PWA-for-wp*/ |
| 49 |
$pwaforwp_settings = get_option( 'pwaforwp_settings'); |
| 50 |
if(isset($pwaforwp_settings['notification_feature']) && $pwaforwp_settings['notification_feature']==0){ |
| 51 |
$pwaforwp_settings['notification_feature'] = 1; |
| 52 |
update_option( 'pwaforwp_settings', $pwaforwp_settings); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* on activation of plugin compatibile with PWA for wp |
| 57 |
* if PWA activated and now activating PushNotification, Need to regenerate service worker files |
| 58 |
*/ |
| 59 |
$auth_settings = get_option( 'push_notification_auth_settings', array() ); |
| 60 |
//Push notification Check |
| 61 |
if(isset($auth_settings['user_token']) && isset($auth_settings['token_details']['validated']) && $auth_settings['token_details']['validated'] == 1){ |
| 62 |
//pwaforamp check |
| 63 |
if( function_exists('pwaforwp_required_file_creation') ){ |
| 64 |
$pwaSettings = pwaforwp_defaultSettings(); |
| 65 |
if( $pwaSettings['notification_feature']==1 && isset($pwaSettings['notification_options']) && $pwaSettings['notification_options']=='pushnotifications_io'){ |
| 66 |
pwaforwp_required_file_creation(); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
} |
| 71 |
} |
| 72 |
/** |
| 73 |
* After activate plugin path to redirect |
| 74 |
* @plugin name of current activation plugin |
| 75 |
*/ |
| 76 |
function push_notification_after_activation_redirect( $plugin ) { |
| 77 |
if( $plugin == plugin_basename( PUSH_NOTIFICATION_PLUGIN_FILE ) ) { |
| 78 |
exit( wp_redirect( admin_url( 'admin.php?page=push-notification' ) ) ); |
| 79 |
} |
| 80 |
} |
| 81 |
add_action( 'activated_plugin', 'push_notification_after_activation_redirect' ); |
| 82 |
|
| 83 |
|
| 84 |
/** |
| 85 |
* TO compatible with older < 1.3 of pushnotification |
| 86 |
*/ |
| 87 |
add_action("plugins_loaded", 'push_notification_older_version_compatibility'); |
| 88 |
function push_notification_older_version_compatibility(){ |
| 89 |
$configCompatible = get_transient( 'push_notification_older_version' ); |
| 90 |
|
| 91 |
if(!$configCompatible){ |
| 92 |
$auth_settings = push_notification_auth_settings(); |
| 93 |
if( isset($auth_settings['user_token']) && isset($auth_settings['token_details']['validated']) && $auth_settings['token_details']['validated'] == 1 && !isset($auth_settings['messageManager']) ){ |
| 94 |
$response = PN_Server_Request::varifyUser($auth_settings['user_token']); |
| 95 |
set_transient( 'push_notification_older_version', 1 ); |
| 96 |
} |
| 97 |
} |
| 98 |
} |