__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 5
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 17 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
5
if ( ! class_exists( 'WooThemes_Sensei_Email_Teacher_New_Message' ) ) :
6
7
/**
8
 * Teacher New Message
9
 *
10
 * An email sent to the teacher when one of their students sends them a private message.
11
 *
12
 * @package Users
13
 * @author Automattic
14
 *
15
 * @since		1.6.0
16
 */
17
class WooThemes_Sensei_Email_Teacher_New_Message {
18
19
	var $template;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $template.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
20
	var $subject;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $subject.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
21
	var $heading;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $heading.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
22
	var $recipient;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $recipient.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
23
	var $learner;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $learner.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
24
	var $teacher;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $teacher.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
25
	var $message;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $message.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
26
27
	/**
28
	 * Constructor
29
	 */
30
	function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
31
		$this->template = 'teacher-new-message';
32
		$this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have received a new private message', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template );
33
		$this->heading = apply_filters( 'sensei_email_heading', __( 'Your student has sent you a private message', 'woothemes-sensei' ), $this->template );
34
	}
35
36
	/**
37
	 * trigger function.
38
	 *
39
	 * @access public
40
     * @param integer $message_id
41
	 * @return void
42
	 */
43
	function trigger( $message_id = 0 ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
44
		global  $sensei_email_data;
45
46
		$this->message = get_post( $message_id );
47
48
		$learner_username = get_post_meta( $message_id, '_sender', true );
49
		$this->learner = get_user_by( 'login', $learner_username );
50
51
		$teacher_username = get_post_meta( $message_id, '_receiver', true );
52
		$this->teacher = get_user_by( 'login', $teacher_username );
53
54
		$content_type = get_post_meta( $message_id, '_posttype', true );
0 ignored issues
show
Unused Code introduced by
$content_type is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
55
		$content_id = get_post_meta( $message_id, '_post', true );
56
		$content_title = get_the_title( $content_id );
57
58
        // setup the post type parameter
59
        $content_type = get_post_type( $content_id );
60
        if( !$content_type ){
61
            $content_type ='';
62
        }
63
64
		// Construct data array
65
		$sensei_email_data = apply_filters( 'sensei_email_data', array(
66
			'template'			=> $this->template,
67
            $content_type.'_id' => $content_id,
68
			'heading'			=> $this->heading,
69
			'teacher_id'		=> $this->teacher->ID,
70
			'learner_id'		=> $this->learner->ID,
71
			'learner_name'		=> $this->learner->display_name,
72
			'message_id'		=> $message_id,
73
			'message'			=> $this->message->post_content,
74
			'content_title'		=> $content_title,
75
			'content_type'		=> $content_type,
76
		), $this->template );
77
78
		// Set recipient (teacher)
79
		$this->recipient = stripslashes( $this->teacher->user_email );
80
81
		// Send mail
82
		Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) );
83
84
		wp_safe_redirect( esc_url_raw( add_query_arg( array( 'send' => 'complete' ) ) ) );
85
		exit;
86
	}
87
}
88
89
endif;
90
91
return new WooThemes_Sensei_Email_Teacher_New_Message();