Skip to content

Commit 01640d6

Browse files
committed
Merge branch 'release/1.0'
2 parents cc82a88 + 9860a76 commit 01640d6

11 files changed

Lines changed: 1553 additions & 0 deletions

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
indent_style = tab
9+
10+
[{*.txt,wp-config-sample.php}]
11+
end_of_line = crlf

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

inc/trigger.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Trigger class
4+
* This class registers all the triggers automatically
5+
*/
6+
7+
namespace Notification\bbPress;
8+
9+
abstract class Trigger {
10+
11+
public function __construct() {
12+
13+
// register triggers from child class
14+
$this->register_triggers();
15+
16+
// add notification actions
17+
$this->notifications();
18+
19+
}
20+
21+
/**
22+
* Used to register a notification action
23+
* Must be defined in a child class
24+
*/
25+
abstract protected function notifications();
26+
27+
/**
28+
* Register triggers
29+
* Each method which starts with trigger_ is automatically called
30+
* @return void
31+
*/
32+
public function register_triggers() {
33+
34+
$methods = get_class_methods( $this );
35+
36+
foreach ( $methods as $method ) {
37+
38+
// not a method we are looking for
39+
if ( strpos( $method, 'trigger_' ) === false ) {
40+
continue;
41+
}
42+
43+
$trigger = str_replace( 'trigger_', '', $method );
44+
45+
if ( apply_filters( 'notification/triggers/bbpress/' . $trigger, true ) ) {
46+
call_user_func( array( $this, $method ) );
47+
}
48+
49+
}
50+
51+
}
52+
53+
}

inc/triggers.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Triggers class
4+
*/
5+
6+
namespace Notification\bbPress;
7+
8+
use Notification\Singleton;
9+
use Notification\bbPress\Triggers;
10+
11+
class Triggers extends Singleton {
12+
13+
public function __construct() {
14+
15+
$this->load_triggers();
16+
17+
add_filter( 'notification/disable/post_types_allowed', array( $this, 'disable_metabox_post_types' ), 10, 1 );
18+
19+
}
20+
21+
/**
22+
* Load triggers from their directories
23+
* @return void
24+
*/
25+
public function load_triggers() {
26+
27+
// Forums
28+
new Triggers\Forums();
29+
30+
// Topics
31+
new Triggers\Topics();
32+
33+
// Replies
34+
new Triggers\Replies();
35+
36+
}
37+
38+
/**
39+
* Allow bbPress post types to disable certain triggers
40+
* @param array $post_types default post types
41+
* @return array post types with bbPress types
42+
*/
43+
public function disable_metabox_post_types( $post_types ) {
44+
45+
$post_types[] = bbp_get_forum_post_type();
46+
$post_types[] = bbp_get_topic_post_type();
47+
$post_types[] = bbp_get_reply_post_type();
48+
49+
return $post_types;
50+
51+
}
52+
53+
}

0 commit comments

Comments
 (0)