Skip to content
Snippets Groups Projects
Select Git revision
  • 49b651f53fa0a64295bdeaa2e427e8add7114a62
  • master default protected
  • bugfix/wordpress-review
  • fix/duplicate
  • bugfix/get_current_screen_fail
  • feature/dismiss-nonce
  • replace-dodgy-path
  • bugfix/notice-not-show
  • devel
  • 3.3.0
  • 3.2.5
  • 3.2.4
  • 3.2.3
  • 3.2.2
  • 3.2.1
  • 3.2.0
  • 3.2.0-beta7
  • 3.2.0-beta6
  • 3.2.0-beta5
  • 3.2.0-beta4
  • 3.2.0-beta3
  • 3.2.0-beta2
  • 3.2.0-beta1
  • 3.1.4
  • 3.1.4-beta1
  • 3.1.3
  • 3.1.1
  • 3.1
  • 3.0
29 results

notice-functions.php

Blame
  • Settings.php 2.84 KiB
    <?php
    
    namespace WPDesk\ActivationReminder\Composer;
    
    class Settings {
    
    	const PLUGIN_TITLE = 'plugin-title';
    	const PLUGIN_DIR = 'plugin-dir';
    	const LOGO_URL = 'logo-url';
    	const BUY_PLUGIN_URL = 'buy-plugin-url';
    	const ACTIVATION_REMINDER = 'activation-reminder';
    	const HOW_TO_ACTIVATE_LINK = 'how-to-activate-link';
    
    	/**
    	 * @var string
    	 */
    	private $plugin_title;
    
    	/**
    	 * @var string
    	 */
    	private $plugin_dir;
    
    	/**
    	 * @var string
    	 */
    	private $logo_url;
    
    	/**
    	 * @var string
    	 */
    	private $buy_plugin_url;
    
    	/**
    	 * @var string
    	 */
    	private $how_to_activate_link;
    
    	/**
    	 * @param string $plugin_title
    	 * @param string $plugin_dir
    	 * @param string $logo_url
    	 * @param string $buy_plugin_url
    	 * @param string $how_to_activate_link
    	 */
    	public function __construct( string $plugin_title, string $plugin_dir, string $logo_url, string $buy_plugin_url, string $how_to_activate_link ) {
    		$this->plugin_title         = $plugin_title;
    		$this->plugin_dir           = $plugin_dir;
    		$this->logo_url             = $logo_url;
    		$this->buy_plugin_url       = $buy_plugin_url;
    		$this->how_to_activate_link = $how_to_activate_link;
    	}
    
    	/**
    	 * @return string
    	 */
    	public function get_plugin_title(): string {
    		return $this->plugin_title;
    	}
    
    	/**
    	 * @return string
    	 */
    	public function get_plugin_dir(): string {
    		return $this->plugin_dir;
    	}
    
    	/**
    	 * @return string
    	 */
    	public function get_logo_url(): string {
    		return $this->logo_url;
    	}
    
    	/**
    	 * @return string
    	 */
    	public function get_buy_plugin_url(): string {
    		return $this->buy_plugin_url;
    	}
    
    	/**
    	 * @return string
    	 */
    	public function get_how_to_activate_link(): string {
    		return $this->how_to_activate_link;
    	}
    
    	/**
    	 *
    	 */
    	public static function validate_settings( $settings ) {
    		if ( ! isset( $settings[ self::ACTIVATION_REMINDER ] ) ) {
    			throw new InvalidSettingValue( self::ACTIVATION_REMINDER, null );
    		}
    		if ( ! is_array( $settings[ self::ACTIVATION_REMINDER ] ) ) {
    			throw new InvalidSettingValue( self::ACTIVATION_REMINDER, 'should be array' );
    		}
    		$settings_fields = [
    			self::PLUGIN_TITLE,
    			self::PLUGIN_DIR,
    			self::LOGO_URL,
    			self::BUY_PLUGIN_URL,
    			self::HOW_TO_ACTIVATE_LINK,
    		];
    		foreach ( $settings_fields as $field ) {
    			if ( ! isset( $settings[ self::ACTIVATION_REMINDER ][ $field ] ) ) {
    				throw new InvalidSettingValue( $field, null );
    			}
    		}
    	}
    
    
    	/**
    	 * @param array $settings
    	 *
    	 * @return self
    	 */
    	public static function create_from_composer_settings( array $settings ) {
    		self::validate_settings( $settings );
    		return new self(
    			$settings[ self::ACTIVATION_REMINDER ][ self::PLUGIN_TITLE ],
    			$settings[ self::ACTIVATION_REMINDER ][ self::PLUGIN_DIR ],
    			$settings[ self::ACTIVATION_REMINDER ][ self::LOGO_URL ],
    			$settings[ self::ACTIVATION_REMINDER ][ self::BUY_PLUGIN_URL ],
    			$settings[ self::ACTIVATION_REMINDER ][ self::HOW_TO_ACTIVATE_LINK ]
    		);
    	}
    
    }