Completed
Push — master ( 5987fc...959a28 )
by
unknown
13:59
created

wpshop_email_options::declare_options()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 22
Code Lines 14

Duplication

Lines 6
Ratio 27.27 %

Importance

Changes 0
Metric Value
cc 4
eloc 14
nc 3
nop 0
dl 6
loc 22
rs 8.9197
c 0
b 0
f 0
1
<?php if ( ! defined( 'ABSPATH' ) ) { exit;
2
}
3
4
// End if().
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
5
if ( ! defined( 'WPSHOP_VERSION' ) ) {
6
	die( __( 'Access is not allowed by this way', 'wpshop' ) );
7
}
8
9
/**
10
 * Emails options management
11
 *
12
 * Define the different method to manage the different emails options
13
 *
14
 * @author Eoxia <[email protected]>
15
 * @version 1.0
16
 * @package wpshop
17
 * @subpackage librairies
18
 */
19
20
/**
21
 * Define the different method to manage the different emails options
22
 *
23
 * @package wpshop
24
 * @subpackage librairies
25
 */
26
class wpshop_email_options {
27
28
29
30
	/**
31
	 *
32
	 */
33
	public static function declare_options() {
34
35
		add_settings_section( 'wpshop_emails', '<span class="dashicons dashicons-email"></span>' . __( 'Email addresses', 'wpshop' ), array( 'wpshop_email_options', 'plugin_section_text' ), 'wpshop_emails' );
36
		register_setting( 'wpshop_options', 'wpshop_emails', array( 'wpshop_email_options', 'wpshop_options_validate_emails' ) );
37
		add_settings_field( 'wpshop_noreply_email', __( 'Mails answers address email', 'wpshop' ), array( 'wpshop_email_options', 'wpshop_noreply_email_field' ), 'wpshop_emails', 'wpshop_emails' );
38
		add_settings_field( 'wpshop_contact_email', __( 'Contact email', 'wpshop' ), array( 'wpshop_email_options', 'wpshop_contact_email_field' ), 'wpshop_emails', 'wpshop_emails' );
39
		add_settings_field( 'wpshop_send_confirmation_order_email', '', array( 'wpshop_email_options', 'wpshop_send_confirmation_order_message_field' ), 'wpshop_emails', 'wpshop_emails' );
40
		/** Define the settings section for message	*/
41
		add_settings_section( 'wpshop_messages', '<span class="dashicons dashicons-email-alt"></span>' . __( 'Messages', 'wpshop' ), array( 'wpshop_email_options', 'plugin_section_text' ), 'wpshop_messages' );
42
		/**	Get default messages defined into xml files 	*/
43
		$xml_default_emails = file_get_contents( WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_emails.xml' );
44
		$default_emails = new SimpleXMLElement( $xml_default_emails );
45
		/**	Read default emails for options creation	*/
46 View Code Duplication
		foreach ( $default_emails->xpath( '//emails/email' ) as $email ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
			if ( ( WPSHOP_DEFINED_SHOP_TYPE == (string) $email->attributes()->shop_type ) || ( 'sale' == WPSHOP_DEFINED_SHOP_TYPE ) ) {
48
				register_setting( 'wpshop_options', (string) $email->attributes()->code, array( 'wpshop_email_options', 'wps_options_validate_emails' ) );
49
				add_settings_field( (string) $email->attributes()->code, __( (string) $email->description, 'wpshop' ), array( 'wpshop_email_options', 'wps_options_emails_field' ), 'wpshop_messages', 'wpshop_messages', array(
50
					'code' => (string) $email->attributes()->code,
51
				) );
52
			}
53
		}
54
	}
55
56
	/**
57
	 * Common section description
58
	 */
59
	public static function plugin_section_text() {
60
61
		// End if().
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
62
	}
63
64
	/* ------------------------ */
65
	/* --------- EMAILS ------- */
66
	/* ------------------------ */
67 View Code Duplication
	public static function wpshop_noreply_email_field() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
69
		$admin_email = get_bloginfo( 'admin_email' );
70
		$emails = get_option( 'wpshop_emails', null );
71
		$email = empty( $emails['noreply_email'] ) ? $admin_email : $emails['noreply_email'];
72
		echo '<input name="wpshop_emails[noreply_email]" type="text" value="' . $email . '" />
73
		<a href="#" title="' . __( 'This is the no reply email','wpshop' ) . '" class="wpshop_infobulle_marker">?</a>';
74
	}
75 View Code Duplication
	public static function wpshop_contact_email_field() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
77
		$admin_email = get_bloginfo( 'admin_email' );
78
		$emails = get_option( 'wpshop_emails', null );
79
		$email = empty( $emails['contact_email'] ) ? $admin_email : $emails['contact_email'];
80
		echo '<input name="wpshop_emails[contact_email]" type="text" value="' . $email . '" />
81
		<a href="#" title="' . __( 'This is the email on which customers can contact you','wpshop' ) . '" class="wpshop_infobulle_marker">?</a>';
82
	}
83
	public static function wpshop_options_validate_emails( $input ) {
84
		return $input;
85
	}
86
87 View Code Duplication
	public static function wpshop_send_confirmation_order_message_field() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88
89
		$email_option = get_option( 'wpshop_emails' );
90
		$output = '<input type="checkbox" name="wpshop_emails[send_confirmation_order_message]" id="wpshop_emails_send_confirmation_order_message" ' . ( ( ! empty( $email_option ) && ! empty( $email_option['send_confirmation_order_message'] ) ) ? 'checked="checked"' : '') . '/> ';
91
		$output .= '<label for="wpshop_emails_send_confirmation_order_message">' . __( 'Send confirmation order message when order is totally paid', 'wpshop' ) . '</label>';
92
		echo $output;
93
	}
94
95
	function wpshop_send_confirmation_order_message_validate( $input ) {
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...
96
97
		return $input;
98
	}
99
100
	/* -------------------------- */
101
	/* --------- MESSAGES ------- */
102
	/* -------------------------- */
103
	/**
104
	 *
105
	 * @param unknown_type $input
106
	 * @return unknown
107
	 */
108
	public static function wps_options_validate_emails( $input ) {
109
110
		return $input;
111
	}
112
113
	/**
114
	 *
115
	 * @param unknown_type $args
116
	 */
117
	public static function wps_options_emails_field( $args ) {
118
119
		$content = '';
120
		$current_message_id = get_option( $args['code'], '' );
121
		/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
41% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
122
		$wps_message = new wps_message_ctr();
123
		$options = $wps_message->getMessageListOption( $current_message_id );
124
125
		if ( !empty( $options ) ) {
126
			$content .= '<select name="' . $args['code'] . '" class="chosen_select" >';
127
			$content .= $options;
128
			$content .= '</select> <a id="wps-email-' . $current_message_id . '" title="' . __( 'Edit current selected message', 'wpshop' ) . '" href="' . admin_url( 'post.php?post=' . $current_message_id . '&action=edit' ) . '" target="_wps_content_customisation" class="shop-content-customisation shop-content-customisation-email dashicons dashicons-edit"></a>';
129
		}*/
130
131
		echo $content . '<a id="wps-email-' . $current_message_id . '" title="' . __( 'Edit current selected message', 'wpshop' ) . '" href="' . admin_url( 'post.php?post=' . $current_message_id . '&action=edit' ) . '" target="_wps_content_customisation" class="shop-content-customisation shop-content-customisation-email dashicons dashicons-edit"></a>';
132
	}
133
134
}
135