alerts->RegisterGroup( array( SECTION1; $result .= self::build_events_code( $definitions['events'] ); $result .= <<<'SECTION2' ) ); add_filter( 'wsal_event_objects', 'mwpal_dynamic_objects_init', 10, 1 ); add_action( 'wsal_event_type_data', 'mwpal_dynamic_event_types_init', 10, 1 ); } function mwpal_dynamic_objects_init( $objects ) { return array_merge( $objects, array( SECTION2; $result .= self::build_assoc_array_code( $definitions['objects'] ); $result .= <<<'SECTION3' ) ); } function mwpal_dynamic_event_types_init( $types ) { return array_unique( array_merge( $types, array( SECTION3; $result .= self::build_assoc_array_code( $definitions['types'] ); $result .= <<<'SECTION4' ) ) ); } add_action( 'init', 'mwpal_dynamic_events_init', 20 ); SECTION4; file_put_contents( $filename, $result ); } /** * Builds PHP code to register given events. * * @param array $events Categorized events data. * * @return string */ private static function build_events_code( $events ) { $result = ''; foreach ( $events as $category => $subcategories ) { $result .= '\'' . wp_slash( $category ) . '\' => array(' . PHP_EOL; foreach ( $subcategories as $subcategory => $events ) { $result .= '\'' . wp_slash( $subcategory ) . '\' => array(' . PHP_EOL; foreach ( $events as $event ) { $code = intval( $event['code'] ); $severity_constant = mwpal_extension()->constants->GetConstantBy( 'value', $event['severity'], null ); if ( ! is_null( $severity_constant ) ) { $severity = $severity_constant->name; } $description = wp_slash( $event['desc'] ); $object = $event['object']; $event_type = $event['event_type']; $message = wp_slash( $event['mesg'] ); if ( ! empty( $event['metadata'] ) ) { foreach ( $event['metadata'] as $meta_key => $meta_value ) { $message .= ' %LineBreak% ' . $meta_key . ': ' . $meta_value; } } if ( ! empty( $event['links'] ) ) { foreach ( $event['links'] as $link_key => $link_value ) { if ( is_string( $link_key ) ) { $message .= ' %LineBreak% ' . $link_key . ': ' . $link_value; } else { $message .= ' %LineBreak% ' . $link_value; } } } $result .= << $value ) { $result .= '\'' . wp_slash( $key ) . '\' => \'' . wp_slash( $value ) . '\',' . PHP_EOL; } return $result; } }