src/WordPress/Models/ProfileSection.php
static function factory(Plugin $plugin, $type)
	{
		$plugin->validator->extend('can_edit', function($attribute, $value, $parameters, $validator) {
			if (empty($value)) {
				return false;
			}

			$current_user = wp_get_current_user();
			if (empty($current_user)) {
				return false;
			}

			if ($attribute === 'user_id') {
				$target_user = get_user_by('ID', $value);
			} else {
				$target_user = get_user_by($attribute, $value);
			}

			if ($current_user->ID === $target_user->ID) {
				return true;
			} else if ($current_user->can('administrator')) {
				return true;
			} else {
				return false;
			}
		});

		if (empty($type)) {
			throw new \Exception("Missing required argument: type");
		}

		$type = urldecode($type);

		if (class_exists($type)) {
			$implements = class_implements($type);
			if (!isset($implements['FatPanda\Illuminate\WordPress\Concerns\ProfileSectionContract'])) {
				throw new \Exception("Profile Section type {$type} does not implement ProfileSectionContract");
			}
			$section = new $type();
			$section->setPlugin($plugin);
			return $section;
		
		} else {
			return new SimpleProfileSection($type);

		}
	}
static function factory(Plugin $plugin, $type)
	{
		$plugin->validator->extend('can_edit', function($attribute, $value, $parameters, $validator) {
			if (empty($value)) {
				return false;
			}

			$current_user = wp_get_current_user();
			if (empty($current_user)) {
				return false;
			}

			if ($attribute === 'user_id') {
				$target_user = get_user_by('ID', $value);
			} else {
				$target_user = get_user_by($attribute, $value);
			}

			if ($current_user->ID === $target_user->ID) {
				return true;
			} else if ($current_user->can('administrator')) {
				return true;
			} else {
				return false;
			}
		});

		if (empty($type)) {
			throw new \Exception("Missing required argument: type");
		}

		$type = urldecode($type);

		if (class_exists($type)) {
			$implements = class_implements($type);
			if (!isset($implements['FatPanda\Illuminate\WordPress\Concerns\ProfileSectionContract'])) {
				throw new \Exception("Profile Section type {$type} does not implement ProfileSectionContract");
			}
			$section = new $type();
			$section->setPlugin($plugin);
			return $section;
		
		} else {
			return new SimpleProfileSection($type);

		}
	}
static function factory ( Plugin $ plugin , $ type ) { $ plugin -> validator -> extend ( 'can_edit' , function ( $ attribute , $ value , $ parameters , $ validator ) { if ( empty ( $ value ) ) { return false ; } $ current_user = wp_get_current_user ( ) ; if ( empty ( $ current_user ) ) { return false ; } if ( $ attribute === 'user_id' ) { $ target_user = get_user_by ( 'ID' , $ value ) ; } else { $ target_user = get_user_by ( $ attribute , $ value ) ; } if ( $ current_user -> ID === $ target_user -> ID ) { return true ; } else if ( $ current_user -> can ( 'administrator' ) ) { return true ; } else { return false ; } } ) ; if ( empty ( $ type ) ) { throw new \ Exception ( "Missing required argument: type" ) ; } $ type = urldecode ( $ type ) ; if ( class_exists ( $ type ) ) { $ implements = class_implements ( $ type ) ; if ( ! isset ( $ implements [ 'FatPanda\Illuminate\WordPress\Concerns\ProfileSectionContract' ] ) ) { throw new \ Exception ( "Profile Section type {$type} does not implement ProfileSectionContract" ) ; } $ section = new $ type ( ) ; $ section -> setPlugin ( $ plugin ) ; return $ section ; } else { return new SimpleProfileSection ( $ type ) ; } }
Create a profile section of the given type, and associate it with the
given Plugin
@param Plugin
@param String A classname of some class that implements ProfileSectionContract
@return PluginSectionContract implementation
@throws Exception If given class does not implement ProfileSectionContract
Create a profile section of the given type and associate it with the given Plugin