public static function push($id = null, $message = '', $class = 'updated', $flash = true, $hidden = false) { $notifications = get_option(self::$option_name, array()); $notification = new RWP_Notification($id, $message, $class, $flash, $hidden); $id = $notification->get_id(); $notifications[$id] = $notification; update_option(self::$option_name, $notifications); }
public static function activate() { global $wp_version; if (version_compare($wp_version, '4.2', '>=') && version_compare(PHP_VERSION, '5.3', '>=')) { // Check ok! // Set default preferences $pref = RWP_Reviewer::get_option('rwp_preferences'); if (empty($pref)) { $default = array('preferences_authorization' => 'all', 'preferences_rating_mode' => 'five_stars', 'preferences_post_types' => array('post', 'page'), 'preferences_step' => 0.5); add_option('rwp_preferences', $default); } // Init templates $temps = RWP_Reviewer::get_option('rwp_templates'); if (empty($temps)) { add_option('rwp_templates', array()); } // Check if there are some previous version references $old = RWP_Reviewer::get_option('rwp_reviewer_templates'); if (empty($old)) { update_option('rwp_restore', 1); } // Init support info $sup = RWP_Reviewer::get_option('rwp_support'); if (empty($sup)) { add_option('rwp_support', array()); } // Init support info $pend = get_option('rwp_pending_ratings'); if (!$pend) { add_option('rwp_pending_ratings', 0); } } else { RWP_Notification::push('activation', __('The Reviewer Plugin needs WordPress >= 4.2 and PHP >= 5.3 to work. If data are correct you can ignore the notice', 'reviewer'), 'error'); } $support = RWP_Reviewer::get_option('rwp_support'); if (!isset($support['support_copy_id'])) { RWP_Notification::push('support', __('Thank you for purchasing the Reviewer Plugin. Activate your copy in order to get support.', 'reviewer') . ' <a href="' . admin_url('admin.php?page=reviewer-support-page') . '">' . __('Activate Now', 'reviewer') . '</a>', 'update-nag', false); } return 0; }
public function validate_fields($fields) { $valids = array(); $errors = array(); foreach ($this->support_fields as $field_id => $field) { if (!isset($fields[$field_id])) { // The field is not set $errors[] = __('Invalid form submission', $this->plugin_slug); break; } $value = trim($fields[$field_id]); if (empty($value)) { if (empty($field['default'])) { $errors[] = sprintf(__('%s is required', $this->plugin_slug), $field['title']); } else { $valids[$field_id] = $field['default']; } } else { $valids[$field_id] = esc_sql(esc_html($value)); } } if (!empty($errors)) { // Some errors add_settings_error($this->option_name, 'rwp-support-warning', implode('<br/>', $errors), 'update-nag'); return array(); } else { // Validation ok, register plugin copy $res = $this->register_plugin($valids); if ($res['status'] === false) { // Request failed add_settings_error($this->option_name, 'rwp-support-warning', $res['body'], 'update-nag'); return array(); } else { // Request ok if ($res['body']['status']) { // Registered RWP_Notification::delete('support'); $valids['support_copy_id'] = $res['body']['resp']; add_settings_error($this->option_name, 'rwp-support-ok', __('Thank you for activating your plugin copy.', $this->plugin_slug), 'updated'); } else { // Registration failed add_settings_error($this->option_name, 'rwp-support-warning', __('Unable to register the plugin copy. Please check your Envato Username and Purchase Code fields.', $this->plugin_slug), 'update-nag'); return array(); } } } return $valids; }