<?php
namespace SabaiApps\Directories\Component\Membership\Helper;

use SabaiApps\Directories\Application;

class WordPressShortcodeHelper {

	public function restrict( Application $application, $atts, $content, $tag ) {
		if ( $application->getUser()->isAdministrator() ) {
			return $content;
		}

		if ( ! $application->getUser()->id
			|| ! $application->getComponent( 'User' )->userDirectoryExists()
			|| ( ! $entity = $application->Entity_Entity( 'user', $application->getUser()->id ) )
			|| ( ! $plan = $application->Payment_Plan( $entity ) )
		) {
			return '';
		}

		if ( ! empty( $atts['plans'] )
			&& ( $plans = explode( ',', trim( $atts['plans'] ) ) )
			&& ! in_array( $plan->paymentPlanId(), $plans )
			&& ! in_array( $plan->paymentPlanName(), $plans )
		) {
			return '';
		}

		return $content;
	}
}
