Sindbad~EG File Manager

Current Path : /home/xiedrke/entrepot/wp-content/plugins/realpress/app/Controllers/
Upload File :
Current File : /home/xiedrke/entrepot/wp-content/plugins/realpress/app/Controllers/AgentAdminController.php

<?php

namespace RealPress\Controllers;

class AgentAdminController {
	public function __construct() {
		//Agent can only see own properties
		add_filter( 'pre_get_posts', array( $this, 'limit_properties_list' ) );
		add_action( 'admin_init', array( $this, 'remove_dashboard' ) );
	}

	/**
	 * @return void
	 */
	public function remove_dashboard() {
		$user_id = get_current_user_id();
		if ( empty( $user_id ) ) {
			return;
		}
		$user_meta  = get_userdata( $user_id );
		$user_roles = $user_meta->roles;

		if ( empty( $user_roles ) ) {
			$user_roles = array();
		}

		if ( ! in_array( REALPRESS_AGENT_ROLE, $user_roles ) ) {
			return;
		}

		foreach ( $GLOBALS['menu'] as $menu ) {
			if ( isset( $menu[2] ) && $menu[2] === 'index.php' ) {
				remove_menu_page( $menu[2] );
			}
		}
	}

	/**
	 * @param $query
	 *
	 * @return mixed
	 */
	public function limit_properties_list( $query ) {
		global $pagenow;

		if ( 'edit.php' != $pagenow || ! $query->is_admin ) {
			return $query;
		}

		if ( ! isset( $_GET['post_type'] ) ||  $_GET['post_type'] !== REALPRESS_PROPERTY_CPT ) {
			return $query;
		}

		$user_id = get_current_user_id();
		if ( empty( $user_id ) ) {
			return $query;
		}
		$user_meta  = get_userdata( $user_id );
		$user_roles = $user_meta->roles;

		if ( empty( $user_roles ) ) {
			$user_roles = array();
		}

		if ( in_array( REALPRESS_AGENT_ROLE, $user_roles ) ) {
			$query->set( 'author', $user_id );
		}

		return $query;
	}
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists