private static function _import($contents) { $items = json_decode($contents, true); $added = 0; if (empty($items)) { return array('error', __('Error importing rules, invalid syntax or empty file.', 'stream-notifications')); } foreach ($items as $item) { $rule = new WP_Stream_Notification_Rule(); $rule->load_from_array($item); $rule->save(); ++$added; } return array('updated', sprintf(__('Imported %d notification rules.', 'stream-notifications'), $added)); }
/** * Add a sample rule, used upon activation * */ public function add_sample_rule() { $rule = new WP_Stream_Notification_Rule(); $details = array('author' => 0, 'summary' => __('Sample Rule', 'stream-notifications'), 'visibility' => 'inactive', 'type' => 'notification_rule', 'triggers' => array(array('group' => 0, 'relation' => 'and', 'type' => 'author_role', 'operator' => '!=', 'value' => 'administrator'), array('group' => 0, 'relation' => 'and', 'type' => 'action', 'operator' => '=', 'value' => 'updated'), array('group' => 1, 'relation' => 'and', 'type' => 'author_role', 'operator' => '=', 'value' => 'administrator'), array('group' => 1, 'relation' => 'and', 'type' => 'connector', 'operator' => '=', 'value' => 'widgets'), array('group' => 1, 'relation' => 'and', 'type' => 'action', 'operator' => '=', 'value' => 'sorted')), 'groups' => array(1 => array('group' => 0, 'relation' => 'or')), 'alerts' => array(array('type' => 'email', 'users' => '1', 'emails' => '', 'subject' => sprintf(__('[Site Activity Alert] %s', 'stream-notifications'), get_bloginfo('name')), 'message' => __("The following just happened on your site:\r\n\r\n{summary} by {author.display_name}\r\n\r\nDate of action: {created}", 'stream-notifications')))); $rule->load_from_array($details); $rule->save(); }