wpshop_init::admin_print_js()   C
last analyzed

Complexity

Conditions 8
Paths 4

Size

Total Lines 100
Code Lines 84

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 84
nc 4
nop 0
dl 0
loc 100
rs 5.2676
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php if ( !defined( 'ABSPATH' ) ) exit;
2
3
/*	Check if file is include. No direct access possible with file url	*/
4
if ( !defined( 'WPSHOP_VERSION' ) ) {
5
	die( __('Access is not allowed by this way', 'wpshop') );
6
}
7
8
/**
9
* Plugin initialisation definition file.
10
*
11
* This file contains the different methods needed by the plugin on initialisation
12
* @author Eoxia <[email protected]>
13
* @version 1.1
14
* @package wpshop
15
* @subpackage librairies
16
*/
17
18
/**
19
 *	Define the different plugin initialisation's methods
20
 * @author Eoxia <[email protected]>
21
 * @version 1.1
22
 * @package wpshop
23
 * @subpackage librairies
24
 */
25
class wpshop_init{
26
27
	/**
28
	 *	This is the function loaded when wordpress load the different plugin
29
	 */
30
	public static function load() {
31
		global $wpdb;
32
33
		/**	Load the different template element	*/
34
		$wpshop_display = new wpshop_display();
35
		$wpshop_display->load_template();
36
37
		/*	Declare the different options for the plugin	*/
38
		add_action('admin_init', array('wpshop_options', 'add_options'));
39
40
		/*	Include head js	*/
41
		add_action('admin_print_scripts', array('wpshop_init', 'admin_print_js'));
42
43
		$page = !empty( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
44
		$post_type = !empty( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : '';
45
		$action = !empty( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : '';
46
		$post = !empty( $_GET['post'] ) ? (array) $_GET['post'] : '';
47
		$taxonomy = !empty( $_GET['taxonomy'] ) ? sanitize_text_field( $_GET['taxonomy'] ) : '';
48
		if((isset($page) && substr($page, 0, 7) == 'wpshop_') || (isset($page) && $page == 'wps-installer' ) || (isset($post_type) && substr($post_type, 0, 7) == 'wpshop_') || !empty($post) || (isset($page) && $page==WPSHOP_NEWTYPE_IDENTIFIER_GROUP) || (isset($taxonomy) && ($taxonomy == WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES))){
49
			/*	Include the different javascript	*/
50
// 			add_action('admin_init', array('wpshop_init', 'admin_js'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% 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...
51
			add_action( 'admin_enqueue_scripts', array('wpshop_init', 'admin_js') );
52
			add_action('admin_footer', array('wpshop_init', 'admin_js_footer'));
53
54
			/*	Include the different css	*/
55
			//add_action('admin_init', array('wpshop_init', 'admin_css'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% 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...
56
		}
57
		add_action('admin_init', array('wpshop_init', 'admin_css'));
58
59
		/*	Include the different css	*/
60
		if ( !is_admin() ) {
61
			add_action('wp_print_styles', array('wpshop_init', 'frontend_css'));
62
			add_action('wp_print_scripts', array('wpshop_init', 'frontend_js_instruction'));
63
		}
64
65
		if (isset($page,$action) && $page=='wpshop_doc' && $action=='edit') {
66
			add_action('admin_init', array('wpshop_doc', 'init_wysiwyg'));
67
		}
68
69
		// RICH TEXT EDIT INIT
70
		add_action('init', array('wpshop_display','wpshop_rich_text_tags'), 9999);
71
		add_action('init', array('wpshop_display','wps_hide_admin_bar_for_customers'), 9999 );
72
73
		/**	Adda custom class to the admin body	*/
74
		add_filter( 'admin_body_class', array( 'wpshop_init', 'admin_body_class' ) );
75
		add_filter( 'site_transient_update_plugins', array( 'wpshop_init', 'site_transient_update_plugins' ) );
76
	}
77
78
	/**
79
	 *	Admin menu creation
80
	 */
81
	public static function admin_menu(){
82
		global $menu;
83
84
		/*	Get current plugin version	*/
85
		$wpshop_shop_type = get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE);
0 ignored issues
show
Unused Code introduced by
$wpshop_shop_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...
86
87
		$wpshop_catalog_menu_order = 34;
88
89
		$menu[ $wpshop_catalog_menu_order-1 ] = array( '', 'read', 'separator-wpshop_dashboard', '', 'wp-menu-separator wpshop_dashboard' );
90
91
		/*	Main menu creation	*/
92
		global $wps_dashboard_ctr;
93
		add_menu_page(__( 'Dashboard', 'wpshop' ), __( 'Shop', 'wpshop' ), 'wpshop_view_dashboard', WPSHOP_URL_SLUG_DASHBOARD, array( $wps_dashboard_ctr, 'display_dashboard' ), 'dashicons-admin-home', $wpshop_catalog_menu_order);
94
		add_submenu_page(WPSHOP_URL_SLUG_DASHBOARD, __('Dashboard', 'wpshop' ), __('Dashboard', 'wpshop'), 'wpshop_view_dashboard', WPSHOP_URL_SLUG_DASHBOARD, array( $wps_dashboard_ctr, 'display_dashboard' ));
95
96
		/*	Add eav model menus	*/
97
		add_menu_page(__( 'Entities', 'wpshop' ), __( 'Entities', 'wpshop' ), 'wpshop_view_dashboard', WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, array('wpshop_display', 'display_page'), 'dashicons-universal-access-alt', $wpshop_catalog_menu_order + 1);
98
		add_submenu_page(WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, __( 'Attributes', 'wpshop' ), __('Attributes', 'wpshop'), 'wpshop_view_attributes', WPSHOP_URL_SLUG_ATTRIBUTE_LISTING, array('wpshop_display','display_page'));
99
		add_submenu_page(WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, __( 'Attributes groups', 'wpshop' ), __('Attributes groups', 'wpshop'), 'wpshop_view_attribute_set', WPSHOP_URL_SLUG_ATTRIBUTE_SET_LISTING, array('wpshop_display','display_page'));
100
101
		/*	Add messages menus	*/
102
		//add_submenu_page(WPSHOP_URL_SLUG_DASHBOARD, __( 'Messages', 'wpshop' ), __( 'Messages', 'wpshop'), 'wpshop_view_messages', 'edit.php?post_type='.WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
103
		/*	Add group menu	*/
104
// 		if( in_array ( long2ip ( ip2long ( $_SERVER["REMOTE_ADDR"] ) ), unserialize( WPSHOP_DEBUG_MODE_ALLOWED_IP ) ) )add_submenu_page(WPSHOP_URL_SLUG_DASHBOARD, __('Groups', 'wpshop'), __('Groups', 'wpshop'), 'wpshop_view_groups', WPSHOP_NEWTYPE_IDENTIFIER_GROUP, array('wps_customer_group','display_page'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% 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...
105
106
		/*	Add a menu for plugin tools	*/
107
// 		if (WPSHOP_DISPLAY_TOOLS_MENU) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
108
			add_management_page( __('Wpshop - Tools', 'wpshop' ), __('Wpshop - Tools', 'wpshop' ), 'wpshop_view_tools_menu', WPSHOP_URL_SLUG_TOOLS , array('wpshop_tools', 'main_page'));
109
// 		}
110
111
		/*	Add the options menu	*/
112
		add_options_page(__('WPShop options', 'wpshop'), __('Shop', 'wpshop'), 'wpshop_view_options', WPSHOP_URL_SLUG_OPTION, array('wpshop_options', 'option_main_page'));
113
114
		//echo '<pre>'; print_r($menu); echo '</pre>';
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
115
	}
116
117
	public static function admin_menu_order($menu_order) {
118
		// Initialize our custom order array
119
		$wpshop_menu_order = array();
120
121
		// Get the index of our custom separator
122
		$separator = array_search( 'separator-wpshop_dashboard', $menu_order );
123
		$product = array_search( 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $menu_order );
124
		$order = array_search( 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER, $menu_order );
125
		$customers = array_search( 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $menu_order );
126
		//$entities = array_search( 'admin.php?page=' . WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, $menu_order );
0 ignored issues
show
Unused Code Comprehensibility introduced by
39% 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...
127
		$entities = array_search( WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, $menu_order );
128
129
		unset( $menu_order[$separator] );
130
		unset( $menu_order[$product] );
131
		unset( $menu_order[$order] );
132
		unset( $menu_order[$customers] );
133
		unset( $menu_order[$entities] );
134
135
		// Loop through menu order and do some rearranging
136
		foreach ( $menu_order as $index => $item ) :
137
			if ( 'wpshop_dashboard' == $item ) :
138
				$wpshop_menu_order[] = 'separator-wpshop_dashboard';
139
				$wpshop_menu_order[] = $item;
140
				$wpshop_menu_order[] = 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
141
				$wpshop_menu_order[] = 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER;
142
				$wpshop_menu_order[] = 'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS;
143
				$wpshop_menu_order[] = WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES;
144
			elseif ( !in_array( $item, array( 'separator-wpshop_dashboard' ) ) ) :
145
				$wpshop_menu_order[] = $item;
146
			endif;
147
		endforeach;
148
149
		// Return order
150
		return $wpshop_menu_order;
151
	}
152
153
	public static function admin_custom_menu_order() {
154
		return current_user_can( 'manage_options' );
155
	}
156
157
	/**
158
	 *	Admin javascript "header script" part definition
159
	 */
160
	public static function admin_print_js() {
161
162
		/*	Désactivation de l'enregistrement automatique pour certains type de post	*/
163
		global $post;
164
		if ( $post && ( (get_post_type($post->ID) === WPSHOP_NEWTYPE_IDENTIFIER_ORDER) ||  (get_post_type($post->ID) === WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE)
165
				|| (get_post_type($post->ID) === WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES) || (get_post_type($post->ID) === WPSHOP_NEWTYPE_IDENTIFIER_COUPON) ) ) {
166
			wp_dequeue_script('autosave');
167
		}
168
169
		$entity_to_search = !empty( $_GET['entity_to_search'] ) ? sanitize_text_field( $_GET['entity_to_search'] ) : '';
170
//	var WPSHOP_AJAX_FILE_URL = "'.WPSHOP_AJAX_FILE_URL.'";
171
		echo '
172
<script type="text/javascript">
173
174
	var WPSHOP_MEDIAS_ICON_URL = "'.WPSHOP_MEDIAS_ICON_URL.'";
175
	var WPSHOP_PRODUCT_PRICE_PILOT = "'.WPSHOP_PRODUCT_PRICE_PILOT.'";
176
	var WPSHOP_PRODUCT_PRICE_HT = "' . WPSHOP_PRODUCT_PRICE_HT . '";
177
	var WPSHOP_PRODUCT_PRICE_TAX = "' . WPSHOP_PRODUCT_PRICE_TAX . '";
178
	var WPSHOP_PRODUCT_PRICE_TTC = "' . WPSHOP_PRODUCT_PRICE_TTC . '";
179
	var WPSHOP_PRODUCT_SPECIAL_PRICE = "' . WPSHOP_PRODUCT_SPECIAL_PRICE . '";
180
	var WPSHOP_PRODUCT_PRICE_TAX_AMOUNT = "' . WPSHOP_PRODUCT_PRICE_TAX_AMOUNT . '";
181
	var WPSHOP_ADMIN_URL = "' . admin_url() . '";
182
	var WPSHOP_NEWTYPE_IDENTIFIER_ORDER = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '";
183
	var WPSHOP_NEWTYPE_IDENTIFIER_COUPON = "' . WPSHOP_NEWTYPE_IDENTIFIER_COUPON . '";
184
	var WPSHOP_NEWTYPE_IDENTIFIER_GROUP = "' . WPSHOP_NEWTYPE_IDENTIFIER_GROUP . '";
185
	var WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE = "' . WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE . '";
186
	var WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT = "' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '";
187
	var WPSHOP_JS_VAR_ADD_PICTURE = "' . __('Add a picture to category', 'wpshop') . '";
188
	var WPSHOP_JS_VAR_ADD_LOGO = "' . __('Upload your logo', 'wpshop') . '";
189
	var WPSHOP_NEWOPTION_CREATION_NONCE = "' . wp_create_nonce("wpshop_new_option_for_attribute_creation") . '";
190
191
	var WPSHOP_ADD_TEXT = "'.__('Add', 'wpshop').'";
192
	var WPSHOP_CREATE_TEXT = "'.__('Create', 'wpshop').'";
193
	var WPSHOP_SAVE_PRODUCT_OPTIONS_PARAMS = "'.__('Save parameters', 'wpshop').'";
194
195
	var WPSHOP_NEW_OPTION_IN_LIST_EMPTY = "'.__('You don\'t specify all needed file', 'wpshop').'";
196
	var WPSHOP_IS_NOT_ALLOWED_SHIPPING_COUNTRY = "'.__('Sorry ! You can\'t order on this shop, because we don\'t ship in your country.', 'wpshop').'";
197
	var WPSHOP_CONFIRM_BEFORE_GENERATE_INVOICE = "'.__('If you generate the invoice, you will cannot modify this order later. Are you sure to do this action ?', 'wpshop').'";
198
	var WPSHOP_NEW_OPTION_ALREADY_EXIST_IN_LIST = "'.__('The value you entered already exist in list', 'wpshop').'";
199
	var WPSHOP_SURE_TO_DELETE_ATTR_OPTION_FROM_LIST = "'.__('Are you sure you want to delete this option from list?', 'wpshop').'";
200
	var WPSHOP_DEFAULT_VALUE = "'.__('Set as default value', 'wpshop').'";
201
	var WPSHOP_MSG_INVOICE_QUOTATION = "' . __('Are you sure you want to charge this order? You\'ll be unable to modify the content after this operation', 'wpshop') . '";
202
	var WPSHOP_MSG_IGNORE_CONFIGURATION = "' . __('If you continue without install the plugin. Your products won\'t be purchasable', 'wpshop') . '";
203
	var WPSHOP_MSG_CONFIRM_THUMBNAIL_DELETION = "' . __('Are you sure you want to delete this thumbnail?', 'wpshop') . '";
204
	var WPSHOP_CHOSEN_NO_RESULT = "' . __('No result found for your search', 'wpshop') . '";
205
	var WPSHOP_CHOSEN_SELECT_FROM_MULTI_LIST = "' . __('Select values from list', 'wpshop') . '";
206
	var WPSHOP_CHOSEN_SELECT_FROM_LIST = "' . __('Select an Option', 'wpshop') . '";
207
	var WPSHOP_AJAX_CHOSEN_KEEP_TYPING = "' . __('Keep typing for search launching', 'wpshop') . '";
208
	var WPSHOP_AJAX_CHOSEN_SEARCHING = "' . __('Searching in progress for', 'wpshop') . '";
209
	var WPSHOP_MSG_CONFIRM_ADDON_DEACTIVATION = "'.__('Are you sure you want to deactivate this addon?', 'wpshop').'";
210
	var WPS_DELETE_SHOP_LOGO_MSG = "'.__('Are you sure you want to delete this logo?', 'wpshop').'";
211
	var WPS_DEFAULT_LOGO = "'.WPSHOP_MEDIAS_IMAGES_URL . 'no_picture.png";
212
213
	var WPSHOP_NO_ATTRIBUTES_SELECT_FOR_VARIATION = "'.__('You have to select at least one attribute for creating a new variation', 'wpshop').'";
214
215
	var WPSHOP_CHOSEN_ATTRS = {search_contains: true, disable_search_threshold: 5, no_results_text: WPSHOP_CHOSEN_NO_RESULT, placeholder_text_single : WPSHOP_CHOSEN_SELECT_FROM_LIST, placeholder_text_multiple : WPSHOP_CHOSEN_SELECT_FROM_MULTI_LIST};
216
217
	var WPSHOP_TEMPLATES_URL = "'.WPSHOP_TEMPLATES_URL.'";
218
	var WPSHOP_BUTTON_DESCRIPTION = "'.__('Insert shortcode into page content', 'wpshop').'";
219
	var WPSHOP_WYSIWYG_MENU_TITLE_PRODUCT_LISTING = "'.__('Product listing', 'wpshop').'";
220
	var WPSHOP_WYSIWYG_PRODUCT_LISTING_BY_PID_TITLE = "'.__('By product ID', 'wpshop').'";
221
	var WPSHOP_WYSIWYG_PRODUCT_LISTING_BY_ATTRIBUTE_TITLE = "'.__('By attribute value', 'wpshop').'";
222
	var WPSHOP_WYSIWYG_MENU_TITLE_CATEGORIES = "'.__('WPShop categories', 'wpshop').'";
223
	var WPSHOP_WYSIWYG_MENU_TITLE_ATTRIBUTE_VALUE = "'.__('Attribute value', 'wpshop').'";
224
	var WPSHOP_CUSTOM_MESSAGE_CONTENT_TITLE = "'.__('Custom message content', 'wpshop').'";
225
	var WPSHOP_CUSTOM_MESSAGE_CONTENT_CUSTOMER_FIRST_NAME = "'.__('Customer first name', 'wpshop').'";
226
	var WPSHOP_CUSTOM_MESSAGE_CONTENT_CUSTOMER_LAST_NAME = "'.__('Customer last name', 'wpshop').'";
227
	var WPSHOP_CUSTOM_MESSAGE_CONTENT_CUSTOMER_EMAIL = "'.__('Customer email', 'wpshop').'";
228
	var WPSHOP_CUSTOM_MESSAGE_CONTENT_ORDER_ID = "'.__('Order identifer', 'wpshop').'";
229
	var WPSHOP_CUSTOM_MESSAGE_CONTENT_PAYPAL_TRANSACTION_ID = "'.__('Paypal transaction ID', 'wpshop').'";
230
	var WPSHOP_CUSTOM_MESSAGE_CONTENT_ORDER_CONTENT = "'.__('Order content', 'wpshop').'";
231
	var WPSHOP_CUSTOM_MESSAGE_CONTENT_ORDER_CUSTOMER_PERSONNAL_INFORMATIONS = "'.__('Customer personnal informations', 'wpshop').'";
232
	var WPSHOP_CUSTOM_MESSAGE_CONTENT_ORDER_ADDRESSES = "'.__('Order addresses', 'wpshop').'";
233
	var WPSHOP_CUSTOM_MESSAGE_CONTENT_BILLING_ORDER_ADDRESS = "'.__('Billing order address', 'wpshop').'";
234
	var WPSHOP_CUSTOM_MESSAGE_CONTENT_SHIPPING_ORDER_ADDRESS = "'.__('Shipping order address', 'wpshop').'";
235
	var WPSHOP_CUSTOM_MESSAGE_CONTENT_SHIPPING_METHOD = "'.__('Shipping method', 'wpshop').'";
236
	var WPSHOP_CUSTOM_MESSAGE_CONTENT_ORDER_PAYMENT_METHOD = "'.__('order payment_method', 'wpshop').'";
237
	var WPSHOP_CUSTOM_MESSAGE_CONTENT_CUSTOMER_COMMENT = "'.__('Order customer comment', 'wpshop').'";
238
	var WPSHOP_CUSTOM_TAGS_TITLE = "'.__('Wpshop custom tags', 'wpshop').'";
239
	var WPSHOP_CUSTOM_TAGS_CART = "'.__('Cart', 'wpshop').'";
240
	var WPSHOP_CUSTOM_TAGS_CART_MINI = "'.__('Cart widget', 'wpshop').'";
241
	var WPSHOP_CUSTOM_TAGS_CHECKOUT = "'.__('Checkout', 'wpshop').'";
242
	var WPSHOP_CUSTOM_TAGS_ACCOUNT = "'.__('Customer account', 'wpshop').'";
243
	var WPSHOP_CUSTOM_TAGS_SHOP = "'.__('Shop', 'wpshop').'";
244
	var WPSHOP_CUSTOM_TAGS_ADVANCED_SEARCH = "'.__('Advanced search', 'wpshop').'";
245
	var WPSHOP_CANCEL_ORDER_CONFIRM_MESSAGE = "'.__('Do you want to cancel this order ?', 'wpshop').'";
246
	var WPSHOP_REFUND_ORDER_CONFIRM_MESSAGE = "'.__('Do you want to refund this order ?', 'wpshop').'";
247
	var WPSHOP_RESEND_ORDER_CONFIRM_MESSAGE = "'.__('Do you want to resend this order to customer ?', 'wpshop').'";
248
	var WPSHOP_SEARCH_IN_ORDER_EXPLAIN_MESSAGE = "'.__('You want to search in orders', 'wpshop').'";
249
	var WPSHOP_SEARCH_IN_ORDER_CHOICE_CUSTOMER = "'.__('a customer', 'wpshop').'";
250
	var WPSHOP_SEARCH_IN_ORDER_CHOICE_PRODUCT = "'.__('a product', 'wpshop').'";
251
	var WPSHOP_SEARCH_IN_ORDER_USER_CHOICE = "'.( (!empty($entity_to_search) ) ? $entity_to_search : 'customer' ).'";
252
	var WPSHOP_DELETE_ADDRESS_CONFIRMATION = "'.__( 'Do you really want to delete this address', 'wpshop' ).'";
253
254
	var wps_options_shipping_weight_for_custom_fees = "'.__( 'You must enter a weight', 'wpshop' ).'";
255
	var wps_options_country_choose_for_custom_fees = "'.__( 'You must a country for custom fees saving', 'wpshop' ).'";
256
	var wps_options_country_postcode_choose_for_custom_fees = "'.__( 'You must choose a country or write a postcode.', 'wpshop' ).'";
257
	var wps_an_error_occured = "'.__( 'An error occured', 'wpshop' ).'";
258
</script>';
259
	}
260
261
	/**
262
	 *	Admin javascript "footer script" part definition
263
	 */
264
	public static function admin_js_footer() {
265
		global $wp_version;
266
		ob_start();
267
		include(WPSHOP_JS_DIR . 'pages/wpshop_product.js');
268
		$wpshop_product_js = ob_get_contents();
269
		ob_end_clean();
270
271
		echo '<script type="text/javascript">
272
			var wp_version = "'.$wp_version.'";
273
			'.$wpshop_product_js.'
274
		</script>';
275
	}
276
277
	/**
278
	 *	Admin javascript "file" part definition
279
	 */
280
	static function admin_js() {
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...
281
		wp_enqueue_script('jquery');
282
		wp_enqueue_script('jquery-ui-core');
283
		wp_enqueue_script('jquery-ui-datepicker');
284
		wp_enqueue_script('jquery-ui-tabs');
285
		wp_enqueue_script('jquery-ui-sortable');
286
		wp_enqueue_script('jquery-ui-dialog');
287
		wp_enqueue_script('jquery-form');
288
		wp_enqueue_script('jquery-ui-slider');
289
		wp_enqueue_script( 'jquery-ui-autocomplete' );
290
		wp_enqueue_script('wpshop_main_function_js', WPSHOP_JS_URL . 'main_function.js', '', WPSHOP_VERSION);
291
		wp_enqueue_script('wpshop_main_js', WPSHOP_JS_URL . 'main.js', '', WPSHOP_VERSION);
292
		wp_enqueue_script('wpshop_jq_datatable', WPSHOP_JS_URL . 'jquery-libs/jquery.dataTables.min.js', '', WPSHOP_VERSION);
293
		wp_enqueue_script('wpshop_jquery_chosen',  WPSHOP_JS_URL . 'jquery-libs/chosen.jquery.min.js', '', WPSHOP_VERSION);
294
		wp_enqueue_script('jquery-effects-core');
295
		wp_enqueue_script('jquery-effects-highlight');
296
297
		$page = !empty( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
298
299
		/*	Include specific js file for the current page if existing	*/
300
		if(isset($page) && is_file(WPSHOP_JS_DIR . 'pages/' . $page . '.js')){
301
			wp_enqueue_script($page . '_js', WPSHOP_JS_URL . 'pages/' . $page . '.js', '', WPSHOP_VERSION);
302
		}
303
		if((isset($page) && ($page == 'wpshop_dashboard'))) {
304
			wp_enqueue_script($page . '_js', WPSHOP_JS_URL . 'pages/' . WPSHOP_URL_SLUG_OPTION . '.js', '', WPSHOP_VERSION);
305
			wp_register_style($page . '_css', WPSHOP_CSS_URL . 'pages/' . WPSHOP_URL_SLUG_OPTION . '.css', '', WPSHOP_VERSION);
306
			wp_enqueue_style($page . '_css');
307
		}
308
	}
309
310
	/**
311
	*	Admin javascript "header script" part definition
312
	*/
313
	function admin_css_head() {
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...
314
		ob_start();
315
		include(WPSHOP_CSS_DIR . 'pages/wpshop_product.css');
316
		$wpshop_product_css = ob_get_contents();
317
		ob_end_clean();
318
?>
319
<style type="text/css" >
320
<?php echo $wpshop_product_css; ?>
321
</style>
322
<?php
323
	}
324
325
	/**
326
	 *
327
	 * @param array $classes
328
	 * @return string
329
	 */
330
	public static function admin_body_class( $classes ) {
331
		global $post;
332
333
		if ( !empty($post->ID) ) {
334
			$post_type = get_post_type( $post->ID );
335
			if ( is_admin() && in_array( $post_type, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, WPSHOP_NEWTYPE_IDENTIFIER_ORDER, WPSHOP_NEWTYPE_IDENTIFIER_MESSAGE, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, WPSHOP_NEWTYPE_IDENTIFIER_COUPON, WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS) ) ) {
336
				$classes .= ' wpshop-admin-body wpshop-admin-post-type-' . $post_type;
337
			}
338
		}
339
340
		return $classes;
341
	}
342
343
	/**
344
	 *	Admin javascript "file" part definition
345
	 */
346
	public static function wpshop_css() {
347
// 		wp_register_style('wpshop_menu_css', WPSHOP_CSS_URL . 'wpshop.css', '', WPSHOP_VERSION);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
348
// 		wp_enqueue_style('wpshop_menu_css');
349
	}
350
351
	/**
352
	 *	Admin javascript "file" part definition
353
	 */
354
	static function admin_css() {
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...
355
		wp_register_style('wpshop_main_css', WPSHOP_CSS_URL . 'main.css', '', WPSHOP_VERSION);
356
		wp_enqueue_style('wpshop_main_css');
357
358
		// Chosen
359
		wp_register_style('wpshop_chosen_css', WPSHOP_CSS_URL . 'jquery-libs/chosen.css', '', WPSHOP_VERSION);
360
		wp_enqueue_style('wpshop_chosen_css');
361
362
		/*	Include specific css file for the current page if existing	*/
363
		$page = !empty( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
364
		if(isset($page) && is_file(WPSHOP_CSS_DIR . 'pages/' . $page . '.css')){
365
			wp_register_style($page . '_css', WPSHOP_CSS_URL . 'pages/' . $page . '.css', '', WPSHOP_VERSION);
366
			wp_enqueue_style($page . '_css');
367
		}
368
369
		wp_register_style('wpshop_default_admin_wps_style_css', WPSHOP_TEMPLATES_URL . 'wpshop/css/wps_style_old.css', '', WPSHOP_VERSION);
370
		wp_enqueue_style('wpshop_default_admin_wps_style_css');
371
	}
372
373
	/**
374
	 *	Admin css "file" part definition
375
	 */
376
	public static function frontend_css() {
377
378
		//wp_register_style('wpshop_default_frontend_main_css', WPSHOP_TEMPLATES_URL . 'wpshop/css/frontend_main.css', '', WPSHOP_VERSION);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
379
		//wp_enqueue_style('wpshop_default_frontend_main_css');
380
381
		wp_register_style('wpshop_frontend_main_css', wpshop_display::get_template_file('frontend_main.css', WPSHOP_TEMPLATES_URL, 'wpshop/css', 'output', true), '', WPSHOP_VERSION);
382
		wp_enqueue_style('wpshop_frontend_main_css');
383
384
// 		wp_register_style('wpshop_dialog_box_css', wpshop_display::get_template_file('wpshop_dialog_box.css', WPSHOP_TEMPLATES_URL, 'wpshop/css', 'output'), '', WPSHOP_VERSION);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
385
// 		wp_enqueue_style('wpshop_dialog_box_css');
386
		/*	Include Librairies directly from plugin for librairies not modified	*/
387
388
		wp_register_style('wpshop_jquery_fancybox', WPSHOP_CSS_URL . 'jquery-libs/jquery.fancybox-1.3.4.css', '', WPSHOP_VERSION);
389
		wp_enqueue_style('wpshop_jquery_fancybox');
390
391
// 		wp_register_style('wpshop_jquery_ui', WPSHOP_CSS_URL . 'jquery-ui.css', '', WPSHOP_VERSION);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
392
// 		wp_enqueue_style('wpshop_jquery_ui');
393
394
// 		wp_register_style('wpshop_jquery_ui_menu', WPSHOP_CSS_URL . 'jquery-libs/jquery-ui-1.10.1.custom.css', '', WPSHOP_VERSION);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
395
// 		wp_enqueue_style('wpshop_jquery_ui_menu');
396
397
// 		wp_register_style('wpshop_jquery_ui_menu_2', WPSHOP_CSS_URL . 'jquery-libs/jquery-ui-1.10.1.custom.min.css', '', WPSHOP_VERSION);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
398
// 		wp_enqueue_style('wpshop_jquery_ui_menu_2');
399
400
// 		wp_register_style('wpshop_jquery_jqzoom_css', wpshop_display::get_template_file('jquery.jqzoom.css', WPSHOP_TEMPLATES_URL, 'wpshop/css', 'output'), '', WPSHOP_VERSION);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
401
// 		wp_enqueue_style('wpshop_jquery_jqzoom_css');
402
403
		wp_register_style('wpshop_default_wps_style_css', WPSHOP_TEMPLATES_URL . 'wpshop/css/wps_style.css', '', WPSHOP_VERSION);
404
		wp_enqueue_style('wpshop_default_wps_style_css');
405
406
		if( file_exists( get_stylesheet_directory().'/wpshop/css/wps_style.css' ) ) {
407
			wp_deregister_style( 'wpshop_default_wps_style_css' );
408
			wp_register_style('wps_style_css', wpshop_display::get_template_file('wps_style.css', WPSHOP_TEMPLATES_URL, 'wpshop/css', 'output', true), '', WPSHOP_VERSION);
409
			wp_enqueue_style('wps_style_css', 11);
410
		}
411
412
		/** OWL CAROUSSEL **/
413
		wp_register_style('wps_owl_caroussel', wpshop_display::get_template_file('owl.carousel.css', WPSHOP_TEMPLATES_URL, 'wpshop/css', 'output'), '', WPSHOP_VERSION);
414
		wp_enqueue_style('wps_owl_caroussel');
415
416
		wp_register_style('wps_owl_caroussel_transitions', wpshop_display::get_template_file('owl.transitions.css', WPSHOP_TEMPLATES_URL, 'wpshop/css', 'output'), '', WPSHOP_VERSION);
417
		wp_enqueue_style('wps_owl_caroussel_transitions');
418
419
			wp_enqueue_style( 'dashicons' );
420
	}
421
422
	/**
423
	 *	Frontend javascript caller
424
	 */
425
	public static function frontend_js_instruction() {
426
		wp_enqueue_script('jquery');
427
		wp_enqueue_script('jquery-ui-tabs');
428
		wp_enqueue_script('jquery-form');
429
		wp_enqueue_script('jquery-ui-core');
430
		wp_enqueue_script('jquery-ui-dialog');
431
		wp_enqueue_script('jquery-ui-datepicker');
432
		wp_enqueue_script('jquery-effects-core');
433
		wp_enqueue_script('jquery-effects-highlight');
434
		wp_enqueue_script('jquery-ui-slider');
435
		wp_enqueue_script('wpshop_frontend_main_js', wpshop_display::get_template_file('frontend_main.js', WPSHOP_TEMPLATES_URL, 'wpshop/js', 'output'), '', WPSHOP_VERSION, true);
436
// 		wp_enqueue_script('wpshop_jquery_jqzoom_core_js', wpshop_display::get_template_file('jquery.jqzoom-core.js', WPSHOP_TEMPLATES_URL, 'wpshop/js', 'output'), '', WPSHOP_VERSION, true);
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
437
		wp_enqueue_script('fancyboxmousewheel',WPSHOP_JS_URL . 'fancybox/jquery.mousewheel-3.0.4.pack.js', '', WPSHOP_VERSION, true);
438
		wp_enqueue_script('fancybox', WPSHOP_JS_URL . 'fancybox/jquery.fancybox-1.3.4.pack.js', '', WPSHOP_VERSION, true);
439
		wp_enqueue_script('jquery_address', WPSHOP_JS_URL . 'jquery-libs/jquery.address-1.5.min.js', '', WPSHOP_VERSION);
440
		wp_enqueue_script('wps_api', wpshop_display::get_template_file('wps-api.js', WPSHOP_TEMPLATES_URL, 'wpshop/js', 'output'), '', WPSHOP_VERSION, true);
441
		wp_enqueue_script('jquery.nouislider.min', wpshop_display::get_template_file('jquery.nouislider.min.js', WPSHOP_TEMPLATES_URL, 'wpshop/js', 'output'), '', WPSHOP_VERSION, true);
442
		wp_enqueue_script('wps_owl_caroussel', wpshop_display::get_template_file('owl.carousel.min.js', WPSHOP_TEMPLATES_URL, 'wpshop/js', 'output'), '', WPSHOP_VERSION, true);
443
?>
444
<script type="text/javascript">
445
	var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
446
	var CURRENT_PAGE_URL = "<?php !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '' ?>";
447
	var WPSHOP_REQUIRED_FIELD_ERROR_MESSAGE = "<?php _e('Every fields marked as required must be filled', 'wpshop'); ?>";
448
	var WPSHOP_INVALID_EMAIL_ERROR_MESSAGE = "<?php _e('Email invalid', 'wpshop'); ?>";
449
	var WPSHOP_UNMATCHABLE_PASSWORD_ERROR_MESSAGE = "<?php _e('Both passwords must match', 'wpshop'); ?>";
450
	var WPSHOP_CHOSEN_NO_RESULT = "<?php _e('No result found for your search', 'wpshop'); ?>";
451
	var WPSHOP_CHOSEN_SELECT_FROM_MULTI_LIST = "<?php _e('Select values from list', 'wpshop'); ?>";
452
	var WPSHOP_CHOSEN_SELECT_FROM_LIST = "<?php _e('Select an Option', 'wpshop'); ?>";
453
	var WPSHOP_AJAX_CHOSEN_KEEP_TYPING = "<?php _e('Keep typing for search launching', 'wpshop'); ?>";
454
	var WPSHOP_AJAX_CHOSEN_SEARCHING = "<?php _e('Searching in progress for', 'wpshop'); ?>";
455
	var WPSHOP_PRODUCT_VARIATION_REQUIRED_MSG = "<div id='wpshop_product_add_to_cart_form_result' class='error_bloc' ><?php _e('Please select all required value', 'wpshop'); ?></div>";
456
	var WPSHOP_ACCEPT_TERMS_OF_SALE = "<?php _e('You must accept the terms of sale.', 'wpshop'); ?>";
457
	var WPSHOP_MUST_CHOOSE_SHIPPING_MODE = "<?php _e('You must to choose a shipping mode', 'wpshop'); ?>";
458
	var WPSHOP_NO_SHIPPING_MODE_AVAILABLE = "<?php _e('You can\'t order because no shipping mode is available.', 'wpshop'); ?>";
459
	var WPSHOP_LOADER_ICON_JQUERY_ADDRESS = "<img src=\"<?php echo WPSHOP_LOADING_ICON; ?>\" alt=\"Loading...\" />";
460
	var WPSHOP_CONFIRM_DELETE_ADDRESS = "<?php _e( 'Do you really want to delete this address ?', 'wpshop' ); ?>";
461
	var wps_speed_slideUpDown = 200;
462
	var MODAL_URL = '<?php echo WPSHOP_TEMPLATES_URL; ?>wpshop/modal.php';
463
</script>
464
<?php
465
	}
466
467
	/**
468
	 *	Function called on plugin initialisation allowing to declare the new types needed by our plugin
469
	 *	@see wpshop_products::create_wpshop_products_type();
470
	 *	@see wpshop_categories::create_product_categories();
471
	 */
472
	public static function add_new_wp_type() {
473
		$wpshop_shop_type = get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE);
474
475
		/*	Creation du type d'element Entité pour wpshop	*/
476
		wpshop_entities::create_wpshop_entities_type();
477
		add_action('add_meta_boxes', array('wpshop_entities', 'add_meta_boxes'));
478
		add_action('save_post', array('wpshop_entities', 'save_entity_type_custom_informations'));
479
		add_filter('manage_posts_columns', array('wpshop_entities', 'custom_columns_header'), 10, 2);
480
		add_filter('manage_posts_custom_column', array('wpshop_entities', 'custom_columns_content'), 10, 2);
481
// 			add_action('quick_edit_custom_box', array('wpshop_attributes', 'quick_edit'), 10, 2);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
482
			add_action('bulk_edit_custom_box', array('wpshop_attributes', 'bulk_edit'), 10, 2);
483
484
		/*	Creation des types personnalisé à partir des entités créées	*/
485
		wpshop_entities::create_wpshop_entities_custom_type();
486
487
		/*	Add wpshop product type and add a new meta_bow into product creation/edition interface for regrouping title and editor in order to sort interface	*/
488
		wpshop_products::create_wpshop_products_type();
489
		add_filter('hidden_meta_boxes', array('wpshop_products', 'hidden_meta_boxes'), 10, 3);
490
		add_action('add_meta_boxes', array('wpshop_products', 'add_meta_boxes'));
491
		//add_action('admin_menu', array('wpshop_products', 'admin_menu'), 10);
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% 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...
492
		add_filter('post_link', array('wpshop_products', 'set_product_permalink'), 10, 3);
493
		add_filter('post_type_link', array('wpshop_products', 'set_product_permalink'), 10, 3);
494
		add_action('pre_get_posts', array('wpshop_products', 'set_product_request_by_name'));
495
		$product_class = new wpshop_products();
496
		add_action('save_post', array($product_class, 'save_product_custom_informations'));
497
		/*	Modification des paramètres de variation quand ils ne sont pas configurés individuellement	*/
498
		add_filter('pre_update_option_' . 'wpshop_catalog_product_option', array('wpshop_products', 'update_wpshop_catalog_product_option'), 10, 2 );
499
500
		/*	Add wpshop product category term	*/
501
		wpshop_categories::create_product_categories();
502
503
		/*	Add wpshop message term	*/
504
505
506
		if ( $wpshop_shop_type == 'sale' ) {
507
			/*	Add wpshop orders term	*/
508
			wpshop_orders::create_orders_type();
509
			add_action('add_meta_boxes', array('wpshop_orders', 'add_meta_boxes'));
510
			add_action('manage_'.WPSHOP_NEWTYPE_IDENTIFIER_ORDER.'_posts_custom_column',  array('wpshop_orders', 'orders_custom_columns'), 10, 2);
511
			add_filter('manage_edit-'.WPSHOP_NEWTYPE_IDENTIFIER_ORDER.'_columns', array('wpshop_orders', 'orders_edit_columns'));
512
			add_action('restrict_manage_posts', array('wpshop_orders', 'list_table_filters') );
513
			add_filter('parse_query', array('wpshop_orders', 'list_table_filter_parse_query') );
514
		}
515
516
		$args = array(
517
			'public'   => true,
518
			'_builtin' => false
519
		);
520
		$output = 'objects'; // names or objects, note names is the default
521
		$operator = 'or'; // 'and' or 'or'
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
522
523
		$wp_types_original=get_post_types($args,$output,$operator);
524
		foreach ($wp_types_original as $type => $type_definition):
525
			$wp_types[$type] = $type_definition->labels->name;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$wp_types was never initialized. Although not strictly required by PHP, it is generally a good practice to add $wp_types = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
526
		endforeach;
527
		$to_exclude=unserialize(WPSHOP_INTERNAL_TYPES_TO_EXCLUDE);
528
		if(!empty($to_exclude)):
529
			foreach($to_exclude as $excluded_type):
530
				if(isset($wp_types[$excluded_type]))unset($wp_types[$excluded_type]);
531
			endforeach;
532
		endif;
533
		DEFINE('WPSHOP_INTERNAL_TYPES', serialize(array_merge($wp_types, array('users' => __('Users', 'wpshop')))));
0 ignored issues
show
Bug introduced by
The variable $wp_types does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
534
	}
535
536
	/**
537
	 * Send mail when new version is available
538
	 */
539
	public static function site_transient_update_plugins( $option ) {
540
		if ( isset( $option->response[ WPSHOP_PLUGIN_NAME ] ) ) {
541
			global $wpdb;
542
			$message_mdl = new wps_message_mdl();
543
			$admin_new_version_message = get_option( 'WPSHOP_NEW_VERSION_ADMIN_MESSAGE', null );
544
			$shop_admin_email_option = get_option( 'wpshop_emails' );
545
			$shop_admin_id = $wpdb->get_var( $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->users . ' WHERE user_email = %s', $shop_admin_email_option['contact_email'] ) );
546
			if ( ! is_null( $shop_admin_id ) && ! is_null( $admin_new_version_message ) ) {
547
				$messages_histo = $message_mdl->get_messages_histo( $admin_new_version_message, $shop_admin_id );
548
				if ( ! empty( $messages_histo ) ) {
549
					foreach ( $messages_histo as $messages_histo_group ) {
550
						foreach ( $messages_histo_group as $messages_histo ) {
551
							if ( strpos( $messages_histo['mess_title'], $option->response[ WPSHOP_PLUGIN_NAME ]->new_version ) !== false
552
							|| strpos( $messages_histo['mess_message'], $option->response[ WPSHOP_PLUGIN_NAME ]->new_version ) !== false ) {
553
								return $option;
554
							}
555
						}
556
					}
557
				}
558
				$wps_message = new wps_message_ctr();
559
				$wps_message->wpshop_prepared_email( $shop_admin_email_option['contact_email'], 'WPSHOP_NEW_VERSION_ADMIN_MESSAGE', array(
560
					'wpshop_version' => $option->response[ WPSHOP_PLUGIN_NAME ]->new_version,
561
				) );
562
			}
563
		}
564
		return $option;
565
	}
566
}
567