/** * @param string $text * @param array $userIds * @param array $options * @param array $payload * @return WP_Error */ public function send_push_notification($text, array $userIds, array $options, array $payload = array()) { if (empty($text)) { return new WP_Error('broke', __("Missing text to send push notification!", "menu")); } if (count($userIds) === 0 || empty($userIds[0]) === true) { return new WP_Error('broke', __("Missing users ids to send push notification!", "menu")); } if (empty($options['appId']) || empty($options['privateApiKey'])) { return new WP_Error('broke', __("Please check basic settings and enter valid data!", "menu")); } $data = array('user_ids' => $userIds, 'notification' => array('alert' => $text, 'ios' => array('payload' => $payload), 'android' => array('payload' => $payload))); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://push.ionic.io/api/v1/push'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_USERPWD, $options['privateApiKey'] . ":"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'X-Ionic-Application-Id: ' . $options['appId'])); $result = json_decode(curl_exec($ch)); curl_close($ch); $historyManager = new Ionic_User_History_Manager(); $historyManager->store_history($text, count($userIds), $result); if ($result->result === 'error') { return new WP_Error('broke', __($result->message, "menu")); } return $result; }
public function plugin_activation() { $userIdManager = new Ionic_User_UserId_Manager(); $userIdManager->create_user_id_table(); $historyManager = new Ionic_User_History_Manager(); $historyManager->create_push_history_table(); $scheduledManager = new Ionic_User_Scheduled_Manager(); $scheduledManager->create_scheduled_table(); }
public function admin_menu_options() { if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.')); } // Store / load data from / to options $storeData = self::store_option(self::OPTION_NAME, $_POST); $options = self::load_options(self::OPTION_NAME); $totalUserIds = Ionic_User_UserId_Manager::get_total_userIds(); if (filter_input(INPUT_POST, 'store-scheduled-push')) { if (filter_input(INPUT_POST, 'scheduled-send-to-all')) { $userIds = 'all'; } else { $userIds = filter_input(INPUT_POST, 'scheduled-user-ids'); } $scheduledStoreReturn = Ionic_User_Scheduled_Manager::store_scheduled(filter_input(INPUT_POST, 'scheduled-date'), filter_input(INPUT_POST, 'scheduled-time'), filter_input(INPUT_POST, 'scheduled-text'), $userIds); if (is_wp_error($scheduledStoreReturn)) { $error = $scheduledStoreReturn->get_error_message(); } } if (filter_input(INPUT_GET, 'deleteScheduledId')) { Ionic_User_Scheduled_Manager::delete_scheduled(filter_input(INPUT_GET, 'deleteScheduledId')); } if (filter_input(INPUT_POST, 'send-push')) { // Send push notification if (filter_input(INPUT_POST, 'send-to-all') !== null) { $userIds = Ionic_User_UserId_Manager::get_all_userIds(); } else { $userIds = explode(';', filter_input(INPUT_POST, 'send-user-ids')); } $sendPushReturn = Ionic_User_Send_Push::send_push_notification(filter_input(INPUT_POST, 'send-text'), $userIds, $options); if (is_wp_error($sendPushReturn)) { $error = $sendPushReturn->get_error_message(); } } $tab = $_REQUEST['tab'] ? $_REQUEST['tab'] : 'settings'; if ($tab === 'userIds') { $pagenum = filter_input(INPUT_GET, 'pagenum') ? absint(filter_input(INPUT_GET, 'pagenum')) : 1; $userIdsPages = Ionic_User_UserId_Manager::get_userIds_page_links($pagenum); } if ($tab === 'scheduled') { $pagenum = filter_input(INPUT_GET, 'pagenum') ? absint(filter_input(INPUT_GET, 'pagenum')) : 1; $scheduledPages = Ionic_User_Scheduled_Manager::get_scheduled_page_links($pagenum); } if ($tab === 'history') { $pagenum = filter_input(INPUT_GET, 'pagenum') ? absint(filter_input(INPUT_GET, 'pagenum')) : 1; $historyPages = Ionic_User_History_Manager::get_history_page_links($pagenum); } $template = IUP_PLUGIN_DIR_PATH . 'assets/html/iup-admin-' . $tab . '.html'; if (is_file($template) === true) { require $template; } }