<?php 
// version 1.0
require_once(dirname(__FILE__)."/functions.php");
require_once(dirname(__FILE__)."/actions.php");
require_once(dirname(__FILE__)."/do-action.php");

class password_api {

	public static $plugin_name = "password_api";
	public static $plugin_root = 'plugins\password_api';
	public static $plugin_ref = "Password Api";

	public function __construct () {
		
	}

	public static function install() {
		$common_access = ['change_password'];
		add_common_access($common_access);
		$super_admin = ['change_password']; //content owner
		$super_admin_tech = ['change_password', 'change_user_password']; //technical owner
		$admin = ['change_password']; //content owner
		$admin_tech = ['change_password']; //technical owner
		$member = ['change_password'];
		$pending = ['change_password'];
		$unverified = ['change_password'];
		$se = [];
		
		update_role('software_engineer', array_unique(array_merge($super_admin, $admin, $super_admin_tech, $admin_tech, $member, $se)));
		update_role('super_admin', $super_admin);
		update_role('admin', $admin);
		update_role('super_admin_tech', $super_admin_tech);
		update_role('admin_tech', $admin_tech);
		update_role('member', $member);
		update_role('pending', $pending);
		update_role('unverified', $unverified);

		$post = new post;
		register_admin_page(array(
			'title' => 'Change Password',
			'callback' => 'change_password_cb',
			'access' => 'change_password',
			'permalink' => 'change-password'
		));

		register_admin_page(array(
			'title' => 'Change Password',
			'callback' => 'change_password2_cb',
			'access' => 'change_password',
			'permalink' => 'change-password2'
		));

		register_admin_page(array(
			'title' => 'Change Password',
			'callback' => 'change_user_password_cb',
			'access' => 'change_user_password',
			'permalink' => 'change-user-password'
		));

		register_admin_submenu(array(
			'mm_id' => 'settings',
			'id' => 'change_password',
			'title' => 'Change Password',
			'icon' => '',
			'page' => 'change-password',
			'access' => 'change_password'
		));

		add_action("more_edit_profile_field", "pswd_more_edit_profile_field");
	}

	public static function uninstall() {
		unregister_admin_page([
			'change-password', 'change_user_password'
		]);

		unregister_admin_submenu([
			'change_password'
		]);

		remove_action("more_edit_profile_field", "pswd_more_edit_profile_field");
	}
}