PageRenderTime 41ms CodeModel.GetById 19ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 1ms

/wp-content/themes/directory/functions/accounts.php

https://gitlab.com/eita/encontre-consumo-responsavel
PHP | 524 lines | 381 code | 64 blank | 79 comment | 108 complexity | a2462107839cabb054a082222b6240d8 MD5 | raw file
  1<?php
  2
  3// init
  4add_action( 'admin_init', 'aitDirCreateRoles');
  5
  6// admin customization
  7add_filter( 'pre_get_posts', 'aitDirShowOnlyMyItems');
  8add_filter( 'views_edit-ait-dir-item', 'aitDirItemsTableViews');
  9add_filter( 'admin_notices', 'aitDirShowNotices' );
 10add_action( 'add_meta_boxes', 'aitDirItemDetailedCapabilities');
 11add_action( 'init', 'aitDirItemRemoveFeatures');
 12add_action( 'pre_get_posts', 'aitDirShowOnlyOwnAttachments');
 13add_filter( 'add_menu_classes', 'aitDirRemoveMediaAdminButton');
 14add_filter( 'manage_users_columns', 'aitDirUsersShowDetails');
 15add_filter( 'manage_users_custom_column', 'aitDirShowDetailsData', 10, 3);
 16
 17// registrations functionality
 18require_once dirname(__FILE__) . '/class-paypal.php';
 19require_once dirname(__FILE__) . '/accounts-reg.php';
 20
 21function aitDirCreateRoles() {
 22
 23	global $pagenow, $typenow, $current_user, $aitThemeOptions;
 24
 25	// directory items capability
 26	$capabilityType = 'ait-dir-item';
 27	$capabilitiesAdmin = array(
 28		"edit_{$capabilityType}" => true,
 29		"read_{$capabilityType}" => true,
 30		"delete_{$capabilityType}" => true,
 31		"edit_{$capabilityType}s" => true,
 32		"edit_others_{$capabilityType}s" => true,
 33		"publish_{$capabilityType}s" => true,
 34		"read_private_{$capabilityType}s" => true,
 35		"delete_{$capabilityType}s" => true,
 36		"delete_private_{$capabilityType}s" => true,
 37		"delete_published_{$capabilityType}s" => true,
 38		"delete_others_{$capabilityType}s" => true,
 39		"edit_private_{$capabilityType}s" => true,
 40		"edit_published_{$capabilityType}s" => true,
 41		"assign_dir_category" => true,
 42		"assign_dir_location" => true
 43	);
 44
 45	// set admin capability
 46	$adminRole = get_role( 'administrator' );
 47	foreach ($capabilitiesAdmin as $key => $value) {
 48		$adminRole->add_cap( $key );
 49	}
 50
 51	$subscriberRole = get_role( 'subscriber' );
 52	$subscriberRole->add_cap( 'directory_account_update' );
 53
 54	// update user roles from admin
 55	if(isset($_POST['action']) && $_POST['action'] == 'update' && strpos($_SERVER['PHP_SELF'],'options.php') !== false){
 56		$optionName = $_POST['option_page'];
 57		if(isset($_POST[$optionName]) && isset($_POST[$optionName]['members'])){
 58
 59			$prefixName = '';
 60			$options = $_POST[$optionName]['members'];
 61			$roles = $GLOBALS['wp_roles']->role_names;
 62
 63			$capabilitiesDirectory = array(
 64				"edit_{$capabilityType}s" => true,
 65				"read_private_{$capabilityType}s" => false,
 66				"edit_published_{$capabilityType}s" => true,
 67				"delete_{$capabilityType}s" => true,
 68				"delete_published_{$capabilityType}s" => true,
 69				"assign_dir_category" => true,
 70				"assign_dir_location" => true,
 71				"read" => true,
 72				"upload_files" => true,
 73				"directory_account_update" => true
 74			);
 75
 76			if(isset($options['role1Enable'])){
 77				remove_role( 'directory_1' );
 78				$caps = $capabilitiesDirectory;
 79				if(!isset($options['role1Approve'])){
 80					$caps["publish_{$capabilityType}s"] = true;
 81				}
 82				add_role( 'directory_1', $prefixName . $options['role1Name'], $caps);
 83			} else {
 84				remove_role( 'directory_1' );
 85			}
 86
 87			if(isset($options['role2Enable'])){
 88				remove_role( 'directory_2' );
 89				$caps = $capabilitiesDirectory;
 90				if(!isset($options['role2Approve'])){
 91					$caps["publish_{$capabilityType}s"] = true;
 92				}
 93				add_role( 'directory_2', $prefixName . $options['role2Name'], $caps);
 94			} else {
 95				remove_role( 'directory_2' );
 96			}
 97
 98			if(isset($options['role3Enable'])){
 99				remove_role( 'directory_3' );
100				$caps = $capabilitiesDirectory;
101				if(!isset($options['role3Approve'])){
102					$caps["publish_{$capabilityType}s"] = true;
103				}
104				add_role( 'directory_3', $prefixName . $options['role3Name'], $caps);
105			} else {
106				remove_role( 'directory_3' );
107			}
108
109			if(isset($options['role4Enable'])){
110				remove_role( 'directory_4' );
111				$caps = $capabilitiesDirectory;
112				if(!isset($options['role4Approve'])){
113					$caps["publish_{$capabilityType}s"] = true;
114				}
115				add_role( 'directory_4', $prefixName . $options['role4Name'], $caps);
116			} else {
117				remove_role( 'directory_4' );
118			}
119
120			if(isset($options['role5Enable'])){
121				remove_role( 'directory_5' );
122				$caps = $capabilitiesDirectory;
123				if(!isset($options['role5Approve'])){
124					$caps["publish_{$capabilityType}s"] = true;
125				}
126				add_role( 'directory_5', $prefixName . $options['role5Name'], $caps);
127			} else {
128				remove_role( 'directory_5' );
129			}
130
131		}
132	}
133
134	// check number of posts for directory users
135	$usrRoles = $current_user->roles;
136	if (isDirectoryUser()) {
137		// Untrash
138		if($pagenow == 'post.php' && !empty($_REQUEST['post']) && !empty($_REQUEST['action']) && $_REQUEST['action'] == 'untrash') {
139			$post = get_post($_REQUEST['post']);
140			$typenow = (isset($post)) ? $post->post_type : '';
141		}
142		// Add new item or untrash
143		if($typenow == 'ait-dir-item' && ($pagenow == 'post-new.php' || ($pagenow == 'post.php' && isset($post)))) {
144
145			$params = array(
146				'post_type'			=> 'ait-dir-item',
147				'nopaging'			=> true,
148				'author'			=> $current_user->ID
149			);
150			$itemsQuery = new WP_Query();
151			$items = $itemsQuery->query($params);
152
153			$backUrl = admin_url('edit.php?post_type=ait-dir-item&dir_notification=1');
154
155			if(in_array('directory_1', $usrRoles)){
156				if(count($items) >= intval($aitThemeOptions->members->role1Items)){
157					header('Location: ' . $backUrl);
158					exit();
159				}
160			} elseif (in_array('directory_2', $usrRoles)) {
161				if(count($items) >= intval($aitThemeOptions->members->role2Items)){
162					header('Location: ' . $backUrl);
163					exit();
164				}
165			} elseif (in_array('directory_3', $usrRoles)) {
166				if(count($items) >= intval($aitThemeOptions->members->role3Items)){
167					header('Location: ' . $backUrl);
168					exit();
169				}
170			} elseif (in_array('directory_4', $usrRoles)) {
171				if(count($items) >= intval($aitThemeOptions->members->role4Items)){
172					header('Location: ' . $backUrl);
173					exit();
174				}
175			} elseif (in_array('directory_5', $usrRoles)) {
176				if(count($items) >= intval($aitThemeOptions->members->role5Items)){
177					header('Location: ' . $backUrl);
178					exit();
179				}
180			}
181		}
182	}
183}
184
185/**
186 * Don't show others items for directory roles
187 */
188function aitDirShowOnlyMyItems($query) {
189	if (isDirectoryUser()) {
190		if((strpos($_SERVER['PHP_SELF'],'edit.php') !== false) && isset($_GET['post_type']) && ($_GET['post_type'] == 'ait-dir-item')){
191			$query->set('author',$GLOBALS['current_user']->ID);
192		}
193	}
194	return $query;
195}
196
197/**
198 * Correct number of items for directory users
199 */
200function aitDirItemsTableViews($views) {
201	if (isDirectoryUser()) {
202		global $wpdb;
203
204		$user = wp_get_current_user();
205		$type = 'ait-dir-item';
206
207		//$cache_key = $type;
208
209		$query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s AND post_author = %d";
210		$query .= ' GROUP BY post_status';
211
212		//$count = wp_cache_get($cache_key, 'counts');
213		//if ( false !== $count )
214		//	return $count;
215
216		$count = $wpdb->get_results( $wpdb->prepare( $query, $type, $user->ID ), ARRAY_A );
217
218		$stats = array();
219		foreach ( get_post_stati() as $state )
220			$stats[$state] = 0;
221
222		foreach ( (array) $count as $row )
223			$stats[$row['post_status']] = $row['num_posts'];
224
225		$stats = (object) $stats;
226		//wp_cache_set($cache_key, $stats, 'counts');
227
228		global $locked_post_status, $avail_post_stati;
229
230		$post_type = $type;
231
232		if ( !empty($locked_post_status) )
233			return array();
234
235		$status_links = array();
236		$num_posts = $stats;
237		$class = '';
238		$allposts = '';
239
240		$current_user_id = get_current_user_id();
241
242		$total_posts = array_sum( (array) $num_posts );
243
244		// Subtract post types that are not included in the admin all list.
245		foreach ( get_post_stati( array('show_in_admin_all_list' => false) ) as $state )
246			$total_posts -= $num_posts->$state;
247
248		$class = empty( $class ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : '';
249		$status_links['all'] = "<a href='edit.php?post_type=$post_type{$allposts}'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts' , 'ait'), number_format_i18n( $total_posts ) ) . '</a>';
250
251		foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) {
252			$class = '';
253
254			$status_name = $status->name;
255
256			if ( !in_array( $status_name, $avail_post_stati ) )
257				continue;
258
259			if ( empty( $num_posts->$status_name ) )
260				continue;
261
262			if ( isset($_REQUEST['post_status']) && $status_name == $_REQUEST['post_status'] )
263				$class = ' class="current"';
264
265			$status_links[$status_name] = "<a href='edit.php?post_status=$status_name&amp;post_type=$post_type'$class>" . sprintf( translate_nooped_plural( $status->label_count, $num_posts->$status_name ), number_format_i18n( $num_posts->$status_name ) ) . '</a>';
266		}
267		return $status_links;
268	} else {
269		return $views;
270	}
271}
272
273/**
274 * Show error notice if max items was exceeded or registration messages
275 */
276function aitDirShowNotices() {
277	global $registerMessages;
278
279	if(isset($_GET['dir_notification']) && $_GET['dir_notification'] == '1'){
280		echo '<div class="error"><p>'.__('Sorry but you have maximum items for your account type. Upgrade your account to insert new items!','ait').'</p></div>';
281	}
282	if(isset($registerMessages)){
283		echo '<div class="updated"><p>'.$registerMessages.'</p></div>';
284	}
285}
286
287function aitDirItemDetailedCapabilities($data) {
288
289	global $aitThemeOptions, $wp_meta_boxes, $current_user;
290	$usrRoles = $current_user->roles;
291
292	// remove featured options for non administrators
293	if (isset($wp_meta_boxes['ait-dir-item']) && (!in_array('administrator', $usrRoles))) {
294		foreach ($wp_meta_boxes['ait-dir-item'] as $contextName => $context) {
295			foreach ($context as $boxesName => $boxes) {
296				foreach ($boxes as $boxName => $box) {
297					if (isset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['featured'])) {
298						unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['featured']);
299					}
300				}
301			}
302		}
303	}
304
305	if (isDirectoryUser()) {
306		$usrRoles = $current_user->roles;
307		$roleNumber = substr(reset($usrRoles), 10);
308
309		$nameAddress = 'role'.$roleNumber.'Address';
310		$nameStreetview = 'role'.$roleNumber.'Streetview';
311		$nameTelephone = 'role'.$roleNumber.'Telephone';
312		$nameEmail = 'role'.$roleNumber.'Email';
313		$nameWeb = 'role'.$roleNumber.'Web';
314		$nameHours = 'role'.$roleNumber.'Hours';
315		$nameAlternativeContent = 'role'.$roleNumber.'AlternativeContent';
316		$nameSocial = 'role'.$roleNumber.'Social';
317		$nameSpecial = 'role'.$roleNumber.'Special';
318		$nameGallery = 'role'.$roleNumber.'Gallery';
319
320		if(isset($wp_meta_boxes['ait-dir-item'])){
321			foreach ($wp_meta_boxes['ait-dir-item'] as $contextName => $context) {
322				foreach ($context as $boxesName => $boxes) {
323					foreach ($boxes as $boxName => $box) {
324						// item options
325						if($boxName == '_ait-dir-item_metabox'){
326							//unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['address']);
327							if(!isset($aitThemeOptions->members->$nameAddress)){
328								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['address']);
329							}
330							if(!isset($aitThemeOptions->members->$nameStreetview)){
331								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['showStreetview']);
332								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['streetViewHeading']);
333								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['streetViewLatitude']);
334								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['streetViewLongitude']);
335								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['streetViewPitch']);
336								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['streetViewZoom']);
337							}
338							if(!isset($aitThemeOptions->members->$nameTelephone)){
339								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['telephone']);
340							}
341							if(!isset($aitThemeOptions->members->$nameEmail)){
342								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['email']);
343								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['emailContactOwner']);
344							}
345							if(!isset($aitThemeOptions->members->$nameWeb)){
346								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['web']);
347							}
348							if(!isset($aitThemeOptions->members->$nameHours)){
349								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['Opening Hours']);
350								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['hoursMonday']);
351								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['hoursTuesday']);
352								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['hoursWednesday']);
353								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['hoursThursday']);
354								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['hoursFriday']);
355								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['hoursSaturday']);
356								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['hoursSunday']);
357							}
358							if(!isset($aitThemeOptions->members->$nameAlternativeContent)){
359								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['Alternative Content']);
360								unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['alternativeContent']);
361							}
362							// if(!isset($aitThemeOptions->members->$nameSocial)){
363							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['Social Icons']);
364							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['socialImg1']);
365							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['socialLink1']);
366							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['socialImg2']);
367							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['socialLink2']);
368							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['socialImg3']);
369							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['socialLink3']);
370							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['socialImg4']);
371							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['socialLink4']);
372							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['socialImg5']);
373							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['socialLink5']);
374							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['socialImg6']);
375							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['socialLink6']);
376							// }
377							// if(!isset($aitThemeOptions->members->$nameSpecial)){
378							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['Special Offer']);
379							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['specialActive']);
380							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['specialTitle']);
381							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['specialContent']);
382							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['specialImage']);
383							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['specialPrice']);
384							// }
385							// if(!isset($aitThemeOptions->members->$nameGallery)){
386							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['Gallery']);
387							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['galleryEnable']);
388							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery1']);
389							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery2']);
390							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery3']);
391							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery4']);
392							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery5']);
393							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery6']);
394							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery7']);
395							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery8']);
396							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery9']);
397							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery10']);
398							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery11']);
399							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery12']);
400							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery13']);
401							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery14']);
402							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery15']);
403							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery16']);
404							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery17']);
405							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery18']);
406							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery19']);
407							// 	unset($wp_meta_boxes['ait-dir-item'][$contextName][$boxesName][$boxName]['callback'][0]->configData['gallery20']);
408							// }
409						}
410					}
411				}
412			}
413		}
414	}
415}
416
417function aitDirItemRemoveFeatures() {
418	global $aitThemeOptions, $current_user;
419
420	if (isDirectoryUser()) {
421		$usrRoles = $current_user->roles;
422		$roleNumber = substr(reset($usrRoles), 10);
423
424		$nameEditor = 'role'.$roleNumber.'Content';
425		$nameImage = 'role'.$roleNumber.'Image';
426		$nameExcerpt = 'role'.$roleNumber.'Excerpt';
427		$nameReviews = 'role'.$roleNumber.'Reviews';
428
429		// attributes
430		remove_post_type_support( 'ait-dir-item', 'page-attributes' );
431		// editor - content
432		if(!isset($aitThemeOptions->members->$nameEditor)){
433			remove_post_type_support( 'ait-dir-item', 'editor' );
434		}
435		// image - thumbnail
436		if(!isset($aitThemeOptions->members->$nameImage)){
437			remove_post_type_support( 'ait-dir-item', 'thumbnail' );
438		}
439		// excerpt
440		if(!isset($aitThemeOptions->members->$nameExcerpt)){
441			remove_post_type_support( 'ait-dir-item', 'excerpt' );
442		}
443		// reviews - comments
444		if(!isset($aitThemeOptions->members->$nameReviews)){
445			remove_post_type_support( 'ait-dir-item', 'comments' );
446		}
447
448	}
449}
450
451function aitDirShowOnlyOwnAttachments( $query ) {
452	global $current_user, $pagenow;
453	if (isDirectoryUser()) {
454		if( 'upload.php' == $pagenow || 'admin-ajax.php' == $pagenow || 'media-upload.php' == $pagenow) {
455			$query->set('author', $current_user->ID );
456		}
457	}
458	return $query;
459}
460
461function aitDirRemoveMediaAdminButton($menu) {
462	global $current_user;
463	if (isDirectoryUser()) {
464		foreach ($menu as $key => $item) {
465			if($item[1] == 'upload_files'){
466				unset($menu[$key]);
467			}
468		}
469	}
470	return $menu;
471}
472
473function aitDirUsersShowDetails($columns) {
474	global $aitThemeOptions;
475	$columns['items'] = __('Items','ait');
476	if (isset($aitThemeOptions->members->paypalPaymentType) && ($aitThemeOptions->members->paypalPaymentType == 'recurring')) {
477		$columns['recurring_profile_id'] = __('PayPal recurring payments profile ID','ait');
478	} else {
479		$columns['activation_time'] = __('Activation time','ait');
480		$columns['days_before_expiration'] = __('Days left before expiration','ait');
481		$columns['transaction_id'] = __('Last PayPal transaction ID','ait');
482	}
483	return $columns;
484}
485
486function aitDirShowDetailsData($empty='', $column_name, $id) {
487	if( $column_name == 'items' ) {
488		return getAuthorItemsCount($id);
489	}
490	if( $column_name == 'activation_time' ) {
491		$data = get_user_meta( $id, 'dir_activation_time', true );
492		if ($data) {
493			$dateFormat = get_option( 'date_format', 'm/d/Y' );
494			return date($dateFormat,$data['time']);
495		}
496	}
497	if( $column_name == 'days_before_expiration' ) {
498		$user = new WP_User($id);
499		if (isDirectoryUser($user)) {
500			return aitDirGetDaysLeft($user->ID);
501		} else {
502			return '';
503		}
504	}
505	if( $column_name == 'transaction_id' ) {
506		$data = get_user_meta( $id, 'dir_paypal_transaction_id', true );
507		if ($data) {
508			return $data;
509		}
510	}
511	if( $column_name == 'recurring_profile_id' ) {
512		$data = get_user_meta( $id, 'dir_paypal_recurring_profile_id', true );
513		if ($data) {
514			return $data;
515		}
516	}
517}
518
519function getAuthorItemsCount($id) {
520	global $wpdb;
521
522	$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'ait-dir-item' AND post_status = 'publish' AND post_author = ".$id );
523	return $count;
524}