class-media-library-organizer-admin.php 28 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
<?php
/**
 * Admin class.
 *
 * @package Media_Library_Organizer
 * @author WP Media Library
 */

/**
 * Handles the settings screen.
 *
 * @since   1.0.0
 */
class Media_Library_Organizer_Admin {

	/**
	 * Holds the base class object.
	 *
	 * @since   1.0.0
	 *
	 * @var     object
	 */
	public $base;

	/**
	 * Constructor
	 *
	 * @since   1.0.0
	 *
	 * @param   object $base    Base Plugin Class.
	 */
	public function __construct( $base ) {

		// Store base class.
		$this->base = $base;

		// Maybe request review.
		add_action( 'wp_loaded', array( $this, 'maybe_request_review' ) );

		// Admin CSS, JS and Menu.
		add_filter( 'wpzinc_admin_body_class', array( $this, 'admin_body_class' ) ); // WordPress Admin.
		add_filter( 'body_class', array( $this, 'body_class' ) ); // Frontend Editors.

		// Actions.
		add_action( 'admin_enqueue_scripts', array( $this, 'scripts_css' ) ); // WordPress Admin.
		add_action( 'wp_enqueue_scripts', array( $this, 'scripts_css' ) ); // Frontend Editors.

		// Menu.
		add_action( 'admin_menu', array( $this, 'admin_menu' ) );

		// Settings Screen.
		add_action( 'media_library_organizer_admin_scripts_js_general', array( $this, 'enqueue_js_settings' ), 10, 4 );
		add_action( 'media_library_organizer_admin_scripts_css_general', array( $this, 'enqueue_css_settings' ) );

		// Addon Screens.
		add_action( 'media_library_organizer_admin_output_settings_panel_general', array( $this, 'output_addon_settings_panel_general' ) );
		add_action( 'media_library_organizer_admin_output_settings_panels', array( $this, 'output_addon_panels' ) );

	}

	/**
	 * Maybe request a review
	 *
	 * Won't do this if Pro with Whitelabelling is enabled
	 *
	 * The review notice will display 3 days after this request
	 *
	 * @since   1.2.4
	 */
	public function maybe_request_review() {

		if ( ! function_exists( 'Media_Library_Organizer_Pro' ) ) {
			Media_Library_Organizer()->dashboard->request_review();
		} elseif ( ! Media_Library_Organizer_Pro()->licensing->has_feature( 'whitelabelling' ) ) {
			Media_Library_Organizer()->dashboard->request_review();
		}

	}

	/**
	 * Registers screen names that should add the wpzinc class to the <body> tag
	 *
	 * @since   1.1.0
	 *
	 * @param   array $screens    Screen Names.
	 * @return  array               Screen Names
	 */
	public function admin_body_class( $screens ) {

		/**
		 * Registers screen names that should add the wpzinc class to the <body> tag
		 *
		 * @since   2.5.7
		 *
		 * @param   array   $screens    Screen Names.
		 * @return  array               Screen Names.
		 */
		$screens = apply_filters( 'media_library_organizer_admin_body_class', $screens );

		// Return.
		return $screens;

	}

	/**
	 * Defines CSS classes for the frontend output
	 *
	 * @since   1.1.0
	 *
	 * @param   array $classes    CSS Classes.
	 * @return  array               CSS Classes
	 */
	public function body_class( $classes ) {

		$classes[] = 'wpzinc';

		return $classes;

	}

	/**
	 * Enqueues JS and CSS depending on the screen that's being viewed
	 *
	 * @since   1.0.0
	 */
	public function scripts_css() {

		// Bail if we can't get the current admin screen, or we're not viewing a screen
		// belonging to this plugin.
		if ( ! function_exists( 'get_current_screen' ) ) {
			return;
		}

		// Determine whether to load minified JS.
		$ext = ( $this->base->dashboard->should_load_minified_js() ? 'min' : '' );

		// JS: Register Selectize.
		$this->base->get_class( 'media' )->register_selectize_js_css( $ext );

		// Get current screen, registered plugin screens and the media view (list or grid).
		$screen  = get_current_screen();
		$screens = $this->get_screens();
		$mode    = $this->base->get_class( 'common' )->get_media_view();

		// If we're on the Media screen, enqueue.
		if ( $screen->id === 'upload' || $screen->id === 'media' ) {
			// Add New.
			if ( $screen->action === 'add' ) {
				$this->enqueue_scripts_css( 'media_add_new', $screen, $screens, $mode, $ext );
				return;
			}

			// List or Grid View.
			$this->enqueue_scripts_css( 'media', $screen, $screens, $mode, $ext );
			return;
		}

		// If we're on the Edit Attachment screen, enqueue.
		if ( $screen->id === 'attachment' ) {
			$this->enqueue_scripts_css( 'attachment', $screen, $screens, $mode, $ext );
			return;
		}

		// If we're on the top level Plugin screen, enqueue.
		if ( $screen->base === 'toplevel_page_' . $this->base->plugin->name ) {
			$this->enqueue_scripts_css( 'general', $screen, $screens, $mode, $ext );
			return;
		}

		// Iterate through the registered screens, to see if we're viewing that screen.
		foreach ( $screens as $registered_screen ) {
			if ( $screen->id === 'media-library-organizer_page_media-library-organizer-' . $registered_screen['name'] ) {
				// We're on a plugin screen.
				$this->enqueue_scripts_css( $registered_screen['name'], $screen, $screens, $mode, $ext );
				return;
			}
		}

	}

	/**
	 * Enqueues scripts and CSS.
	 *
	 * @since   1.0.0
	 *
	 * @param   string    $plugin_screen_name     Plugin Screen Name (general|media).
	 * @param   WP_Screen $screen                 Current WordPress Screen object.
	 * @param   array     $screens                Registered Plugin Screens (optional).
	 * @param   string    $mode                   Media View Mode (list|grid).
	 * @param   string    $ext                    If defined, load minified JS.
	 */
	public function enqueue_scripts_css( $plugin_screen_name, $screen, $screens = '', $mode = 'list', $ext = '' ) {

		global $post;

		// Enqueue JS.
		// These scripts are registered in the Dashboard module.
		wp_enqueue_script( 'wpzinc-admin-conditional' );
		wp_enqueue_script( 'wpzinc-admin-tabs' );
		wp_enqueue_script( 'wpzinc-admin' );

		/**
		 * Enqueue Javascript for the given screen and Media View mode.
		 *
		 * @since   1.0.7
		 *
		 * @param   WP_Screen   $screen                 Current WordPress Screen object.
		 * @param   array       $screens                Registered Plugin Screens (optional).
		 * @param   string      $mode                   Media View Mode (list|grid).
		 * @param   string      $ext                    If defined, load minified JS.
		 */
		do_action( 'media_library_organizer_admin_scripts_js', $screen, $screens, $mode, $ext );

		/**
		 * Enqueue Javascript for the given screen and Media View mode by Plugin
		 * Screen Name.
		 *
		 * @since   1.0.7
		 *
		 * @param   WP_Screen   $screen                 Current WordPress Screen object.
		 * @param   array       $screens                Registered Plugin Screens (optional).
		 * @param   string      $mode                   Media View Mode (list|grid).
		 * @param   string      $ext                    If defined, load minified JS
		 */
		do_action( 'media_library_organizer_admin_scripts_js_' . $plugin_screen_name, $screen, $screens, $mode, $ext );

		/**
		 * Enqueue Stylesheets (CSS) for the given screen and Media View mode.
		 *
		 * @since   1.0.7
		 *
		 * @param   WP_Screen   $screen                 Current WordPress Screen object.
		 * @param   array       $screens                Registered Plugin Screens (optional).
		 * @param   string      $mode                   Media View Mode (list|grid).
		 */
		do_action( 'media_library_organizer_admin_scripts_css', $screen, $screens, $mode );

		/**
		 * Enqueue Stylesheets (CSS) for the given screen and Media View mode.
		 *
		 * @since   1.0.7
		 *
		 * @param   WP_Screen   $screen                 Current WordPress Screen object.
		 * @param   array       $screens                Registered Plugin Screens (optional).
		 * @param   string      $mode                   Media View Mode (list|grid).
		 */
		do_action( 'media_library_organizer_admin_scripts_css_' . $plugin_screen_name, $screen, $screens, $mode );

	}

	/**
	 * Enqueues JS for the Settings screen.
	 *
	 * @since   1.1.6
	 *
	 * @param   obj    $screen     get_current_screen().
	 * @param   array  $screens    Available Plugin Screens.
	 * @param   string $mode       Media View Mode (list|grid).
	 * @param   string $ext        If defined, loads minified JS.
	 */
	public function enqueue_js_settings( $screen, $screens, $mode, $ext ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter

		// JS.
		wp_enqueue_script( 'wpzinc-admin-modal' );

		// Plugin JS.
		wp_enqueue_script( $this->base->plugin->name . '-selectize' );
		wp_enqueue_script( $this->base->plugin->name . '-settings', $this->base->plugin->url . 'assets/js/' . ( $ext ? $ext . '/' : '' ) . 'settings' . ( $ext ? '-' . $ext : '' ) . '.js', array( 'jquery' ), $this->base->plugin->version, true );

		// Localize.
		wp_localize_script(
			$this->base->plugin->name . '-settings',
			'media_library_organizer_settings',
			array(
				'save_settings_action' => 'media_library_organizer_save_settings',
				'save_settings_nonce'  => wp_create_nonce( $this->base->plugin->name . '-save-settings' ),
				'save_settings_modal'  => array(
					'title'         => __( 'Saving', 'media-library-organizer' ),
					'title_success' => __( 'Saved!', 'media-library-organizer' ),
				),
			)
		);

		// CSS.
		wp_enqueue_style( 'wpzinc-admin-selectize' );

	}

	/**
	 * Enqueues CSS for the Settings screen.
	 *
	 * @since   1.0.3
	 */
	public function enqueue_css_settings() {

		// Enqueue CSS.
		wp_enqueue_style( $this->base->plugin->name . '-admin', $this->base->plugin->url . '/assets/css/admin.css', false, $this->base->plugin->version );

	}

	/**
	 * Adds menu and sub menu items to the WordPress Administration.
	 *
	 * @since 1.0.0
	 */
	public function admin_menu() {

		// Bail if we cannot access any menus.
		if ( function_exists( 'Media_Library_Organizer_Access' ) && ! Media_Library_Organizer_Access()->can_access( 'show_menu' ) ) {
			return;
		}

		// Get the registered screens.
		$screens = $this->get_screens();

		// Define the minimum capability required to access the Media Library Organizer Menu and Sub Menus.
		$minimum_capability = 'manage_options';

		/**
		 * Defines the minimum capability required to access the Media Library Organizer
		 * Menu and Sub Menus.
		 *
		 * @since   1.2.4
		 *
		 * @param   string  $capability     Minimum Required Capability.
		 * @return  string                  Minimum Required Capability
		 */
		$minimum_capability = apply_filters( 'media_library_organizer_admin_admin_menu_minimum_capability', $minimum_capability );

		// Create the top level screen.
		add_menu_page( $this->base->plugin->displayName, $this->base->plugin->displayName, $minimum_capability, $this->base->plugin->name, array( $this, 'admin_screen' ), 'dashicons-admin-media' );

		// Iterate through screens, adding as submenu items.
		foreach ( (array) $screens as $screen ) {
			// The settings screen doesn't need to append the page slug.
			$slug = ( ( $screen['name'] === 'settings' ) ? $this->base->plugin->name : $this->base->plugin->name . '-' . $screen['name'] );

			// Define ACL name.
			$access = str_replace( '-', '_', str_replace( $this->base->plugin->name, '', $slug ) );
			if ( empty( $access ) ) {
				$access = 'settings';
			}

			// Skip if access isn't permitted, but always allow licensing and settings.
			if ( $access !== 'settings' && function_exists( 'Media_Library_Organizer_Access' ) && $access !== '_pro' && ! Media_Library_Organizer_Access()->can_access( 'show_menu_' . $access ) ) {
				continue;
			}

			// Add submenu page.
			add_submenu_page( $this->base->plugin->name, $screen['label'], $screen['label'], $minimum_capability, $slug, array( $this, 'admin_screen' ) );
		}

		// Import and Export.
		if ( ! function_exists( 'Media_Library_Organizer_Access' ) || Media_Library_Organizer_Access()->can_access( 'show_menu_import_export' ) ) {
			do_action( 'media_library_organizer_admin_menu_import_export' );
		}

		// Support.
		if ( ! function_exists( 'Media_Library_Organizer_Access' ) || Media_Library_Organizer_Access()->can_access( 'show_menu_support' ) ) {
			do_action( 'media_library_organizer_admin_menu_support' );
		}

	}

	/**
	 * Returns an array of screens for the plugin's admin.
	 *
	 * @since   1.0.0
	 *
	 * @return  array Sections
	 */
	private function get_screens() {

		// Define the settings screen.
		$screens = array(
			'settings' => array(
				'name'          => 'settings',
				'label'         => __( 'Settings', 'media-library-organizer' ),
				'description'   => __( 'Defines Plugin-wide settings for Media Library Organizer.', 'media-library-organizer' ),
				'view'          => $this->base->plugin->folder . 'views/admin/settings-general.php',
				'columns'       => 2,
				'data'          => array(),
				'documentation' => 'https://wpmedialibrary.com/documentation/media-library-organizer/setup/',
			),
		);

		/**
		 * Define sections in the Plugin's Settings
		 *
		 * @since   1.0.7
		 *
		 * @param   array       $screens                Registered Plugin Screens.
		 */
		$screens = apply_filters( 'media_library_organizer_admin_get_screens', $screens );

		// Return.
		return $screens;

	}

	/**
	 * Gets the current admin screen the user is on.
	 *
	 * @since   1.0.0
	 *
	 * @return  array    Screen name and label
	 */
	public function get_current_screen() {

		// Bail if no page given.
		if ( ! isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
			return;
		}

		// Get current screen name.
		$screen = sanitize_text_field( $_GET['page'] ); // phpcs:ignore WordPress.Security.NonceVerification

		// Get registered screens.
		$screens = $this->get_screens();

		// Remove the plugin name from the screen.
		$screen = str_replace( $this->base->plugin->name . '-', '', $screen );

		// If the screen is the plugin name, it's the settings screen.
		if ( $screen === $this->base->plugin->name ) {
			$screen = 'settings';
		}

		// Check if the screen exists.
		if ( ! isset( $screens[ $screen ] ) ) {
			return new WP_Error( 'screen_missing', __( 'The requested administration screen does not exist', 'media-library-organizer' ) );
		}

		/**
		 * Adjust the screen data immediately before returning.
		 *
		 * @since   1.0.7
		 *
		 * @param   array   $screens[ $screen ] Screen Data.
		 * @param   string  $screen             Screen Name.
		 */
		$screens[ $screen ] = apply_filters( 'media_library_organizer_admin_get_current_screen_' . $screen, $screens[ $screen ], $screen );

		// Return the screen.
		return $screens[ $screen ];

	}

	/**
	 * Gets the current admin screen name the user is on
	 *
	 * @since   1.0.0
	 *
	 * @return  mixed  false | Screen Name
	 */
	private function get_current_screen_name() {

		// If no page name was given, we're not on a plugin screen.
		if ( ! isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
			return false;
		}

		// Get screen name.
		$screen = sanitize_text_field( $_GET['page'] ); // phpcs:ignore WordPress.Security.NonceVerification

		// Return.
		return $screen;

	}

	/**
	 * Gets the current admin screen tab the user is on.
	 *
	 * @since   1.0.0
	 *
	 * @param   array $tabs   Screen Tabs.
	 * @return  array           Tab name and label
	 */
	private function get_current_screen_tab( $tabs ) {

		// If the supplied tabs are an empty array, return false.
		if ( empty( $tabs ) ) {
			return false;
		}

		// If no tab defined, get the first tab name from the tabs array.
		if ( ! isset( $_REQUEST['tab'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
			foreach ( $tabs as $tab ) {
				return $tab;
			}
		}

		// Return the requested tab, if it exists.
		if ( isset( $tabs[ $_REQUEST['tab'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
			$tab = $tabs[ sanitize_text_field( $_REQUEST['tab'] ) ]; // phpcs:ignore WordPress.Security.NonceVerification
			return $tab;
		} else {
			foreach ( $tabs as $tab ) {
				return $tab;
			}
		}

	}

	/**
	 * Returns an array of tabs, depending on the Plugin Screen being viewed.
	 *
	 * @since   1.0.0
	 *
	 * @param   string $screen     Screen.
	 * @return  array               Tabs
	 */
	private function get_screen_tabs( $screen ) {

		// Define tabs array.
		$tabs = array();

		// Define the tabs depending on which screen is specified.
		switch ( $screen ) {

			/**
			 * Settings
			 */
			case 'settings':
				$tabs = array(
					'settings'     => array(
						'name'          => 'general',
						'label'         => __( 'Filters', 'media-library-organizer' ),
						'documentation' => $this->base->plugin->documentation_url . '/settings/#general',
						'menu_icon'     => 'general',
					),
					'user-options' => array(
						'name'          => 'user-options',
						'label'         => __( 'User Options', 'media-library-organizer' ),
						'documentation' => $this->base->plugin->documentation_url . '/settings/#user-options',
						'menu_icon'     => 'user',
					),
				);
				break;

		}

		/**
		 * Define tabs in the Plugin Settings section.
		 *
		 * @since   1.0.7
		 *
		 * @param   array   $tabs       Settings Tabs.
		 * @param   string  $screen     Current Screen Name to define Tabs for.
		 */
		$tabs = apply_filters( 'media_library_organizer_admin_get_screen_tabs', $tabs, $screen );

		// Return.
		return $tabs;

	}

	/**
	 * Returns an array of Addon tabs, depending on the Plugin Screen being viewed.
	 *
	 * @since   1.1.0
	 *
	 * @param   string $screen     Screen.
	 * @return  array               Tabs
	 */
	private function get_screen_addon_tabs( $screen ) {

		// Define additional tabs.
		$addon_tabs = array(
			'auto-categorization' => array(
				'name'          => 'auto-categorization',
				'label'         => __( 'Auto Categorization', 'media-library-organizer' ),
				'documentation' => $this->base->plugin->documentation_url . '/auto-categorization/setup',
				'menu_icon'     => 'tag',
				'is_pro'        => true,
			),
			'bulk-quick-edit'     => array(
				'name'          => 'bulk-quick-edit',
				'label'         => __( 'Bulk and Quick Edit', 'media-library-organizer' ),
				'documentation' => $this->base->plugin->documentation_url . '/bulk-quick-edit/setup',
				'menu_icon'     => 'edit',
				'is_pro'        => true,
			),
			'defaults'            => array(
				'name'          => 'defaults',
				'label'         => __( 'Defaults', 'media-library-organizer' ),
				'documentation' => $this->base->plugin->documentation_url . '/defaults/setup',
				'is_pro'        => true,
			),
			'exif'                => array(
				'name'          => 'exif',
				'label'         => __( 'EXIF', 'media-library-organizer' ),
				'documentation' => $this->base->plugin->documentation_url . '/exif/setup',
				'menu_icon'     => 'camera',
				'is_pro'        => true,
			),
			'iptc'                => array(
				'name'          => 'iptc',
				'label'         => __( 'IPTC', 'media-library-organizer' ),
				'documentation' => $this->base->plugin->documentation_url . '/iptc/setup',
				'menu_icon'     => 'camera',
				'is_pro'        => true,
			),
			'optimizer'           => array(
				'name'          => 'optimizer',
				'label'         => __( 'Optimizer', 'media-library-organizer' ),
				'documentation' => $this->base->plugin->documentation_url . '/optimizer/setup',
				'menu_icon'     => 'image',
				'is_pro'        => true,
			),
			'output'              => array(
				'name'          => 'output',
				'label'         => __( 'Output', 'media-library-organizer' ),
				'documentation' => $this->base->plugin->documentation_url . '/output/setup',
				'menu_icon'     => 'general',
				'is_pro'        => true,
			),
			'taxonomy-manager'    => array(
				'name'          => 'taxonomy-manager',
				'label'         => __( 'Taxonomies', 'media-library-organizer' ),
				'documentation' => $this->base->plugin->documentation_url . '/taxonomy-manager/setup',
				'is_pro'        => true,
			),
			'zip'                 => array(
				'name'          => 'zip',
				'label'         => __( 'ZIP and Unzip', 'media-library-organizer' ),
				'documentation' => $this->base->plugin->documentation_url . '/zip-unzip/setup',
				'is_pro'        => true,
			),
		);

		/**
		 * Define Addon tabs in the Plugin Settings section.
		 *
		 * @since   1.1.0
		 *
		 * @param   array   $tabs       Settings Tabs.
		 * @param   string  $screen     Current Screen Name to define Tabs for.
		 */
		$addon_tabs = apply_filters( 'media_library_organizer_admin_get_screen_addon_tabs', $addon_tabs, $screen );

		// Sort additional tabs alphabetically.
		ksort( $addon_tabs );

		// Return.
		return $addon_tabs;

	}

	/**
	 * Output the Settings screen.
	 * Save POSTed data from the Administration Panel into a WordPress option.
	 *
	 * @since 1.0.0
	 */
	public function admin_screen() {

		// Get the current screen.
		$screen = $this->get_current_screen();
		if ( ! $screen || is_wp_error( $screen ) ) {
			require_once $this->base->plugin->folder . '/views/admin/error.php';
			return;
		}

		// Maybe save settings.
		$this->save_settings( $screen['name'] );

		// Hacky; get the current screen again, so its data is refreshed post save and actions.
		$screen = $this->get_current_screen();
		if ( ! $screen || is_wp_error( $screen ) ) {
			require_once $this->base->plugin->folder . '/views/admin/error.php';
			return;
		}

		// Get the tabs for the given screen.
		$tabs       = $this->get_screen_tabs( $screen['name'] );
		$addon_tabs = $this->get_screen_addon_tabs( $screen['name'] );

		// Get the current tab.
		// If no tab specified, get the first tab.
		$tab = $this->get_current_screen_tab( $tabs );

		// Get Taxonomies.
		$taxonomies = $this->base->get_class( 'taxonomies' )->get_taxonomies();

		// Load View.
		require_once $this->base->plugin->folder . '/views/admin/settings.php';

		// Add footer action to output overlay modal markup.
		add_action( 'admin_footer', array( $this, 'output_modal' ) );

	}

	/**
	 * Outputs the hidden Javascript Modal and Overlay in the Footer.
	 *
	 * @since   1.1.6
	 */
	public function output_modal() {

		// Load view.
		require_once $this->base->plugin->folder . '_modules/dashboard/views/modal.php';

	}

	/**
	 * Outputs General Settings for Addons.
	 *
	 * @since   1.1.1
	 */
	public function output_addon_settings_panel_general() {

		// Load View.
		require_once $this->base->plugin->folder . '/views/admin/settings-general-upgrade.php';

	}

	/**
	 * Outputs Settings Panel(s) for Addons.
	 *
	 * @since   1.1.0
	 */
	public function output_addon_panels() {

		// Define Setting Panel(s) Titles and Descriptions.
		$panels = array(
			'auto-categorization' => array(
				'title'       => __( 'Auto Categorization Settings', 'media-library-organizer' ),
				'description' => sprintf(
					/* translators: Plugin Name */
					__( 'Automatically categorize images uploaded through WordPress using image recognition with %s Pro', 'media-library-organizer' ),
					$this->base->plugin->displayName
				),
			),

			'bulk-quick-edit'     => array(
				'title'       => __( 'Bulk and Quick Edit Settings', 'media-library-organizer' ),
				'description' => sprintf(
					/* translators: Plugin Name */
					__( 'Bulk and Quick Edit Titles, Alt Tags, Captions, Descriptions, Categories, EXIF and IPTC metadata from the List and Grid Media Library Views with %s Pro', 'media-library-organizer' ),
					$this->base->plugin->displayName
				),
			),

			'defaults'            => array(
				'title'       => __( 'Defaults Settings', 'media-library-organizer' ),
				'description' => sprintf(
					/* translators: Plugin Name */
					__( 'Define Default Titles, Alt Tags, Captions, Descriptions and Categories for newly uploaded files where no data is specified with %s Pro', 'media-library-organizer' ),
					$this->base->plugin->displayName
				),
			),

			'exif'                => array(
				'title'       => __( 'EXIF Settings', 'media-library-organizer' ),
				'description' => sprintf(
					/* translators: Plugin Name */
					__( 'Read, write and display EXIF image data with %s Pro', 'media-library-organizer' ),
					$this->base->plugin->displayName
				),
			),

			'iptc'                => array(
				'title'       => __( 'IPTC Settings', 'media-library-organizer' ),
				'description' => sprintf(
					/* translators: Plugin Name */
					__( 'Read, write and display IPTC image data, compatible with Google Image\'s Image Licenses, in %s Pro', 'media-library-organizer' ),
					$this->base->plugin->displayName
				),
			),

			'optimizer'           => array(
				'title'       => __( 'Optimizer Settings', 'media-library-organizer' ),
				'description' => sprintf(
					/* translators: Plugin Name */
					__( 'Convert image uploads to Google\'s webp format, and define the quality level to reduce file sizes and improve site loading times with %s Pro', 'media-library-organizer' ),
					$this->base->plugin->displayName
				),
			),

			'output'              => array(
				'title'       => __( 'Output', 'media-library-organizer' ),
				'description' => sprintf(
					/* translators: Plugin Name */
					__( 'Display image previews on hover and determine the thumbnail image size the Media Library with %s Pro', 'media-library-organizer' ),
					$this->base->plugin->displayName
				),
			),

			'taxonomy-manager'    => array(
				'title'       => __( 'Taxonomy Manager', 'media-library-organizer' ),
				'description' => sprintf(
					/* translators: Plugin Name */
					__( 'Define additional Taxonomies that can be used for Attachments in the Media Library with %s Pro', 'media-library-organizer' ),
					$this->base->plugin->displayName
				),
			),

			'zip'                 => array(
				'title'       => __( 'ZIP Settings', 'media-library-organizer' ),
				'description' => sprintf(
					/* translators: Plugin Name */
					__( 'Automatically unzip files when uploaded to the Media Library, and zip multiple Media Library files with %s Pro', 'media-library-organizer' ),
					$this->base->plugin->displayName
				),
			),
		);

		// Load View.
		require_once $this->base->plugin->folder . '/views/admin/settings-upgrade.php';

	}

	/**
	 * Save settings for the given screen
	 *
	 * @since 1.0
	 *
	 * @param string $screen     Screen Name.
	 */
	public function save_settings( $screen = 'settings' ) {

		// Check that some data was submitted in the request.
		if ( ! isset( $_REQUEST[ $this->base->plugin->name . '_nonce' ] ) ) {
			return;
		}

		// Invalid nonce.
		if ( ! wp_verify_nonce( $_REQUEST[ $this->base->plugin->name . '_nonce' ], 'media-library-organizer_' . $screen ) ) {
			$this->base->get_class( 'notices' )->add_error_notice( __( 'Invalid nonce specified. Settings NOT saved.', 'media-library-organizer' ) );
			return false;
		}

		// Depending on the screen we're on, save the data and perform some actions.
		switch ( $screen ) {

			/**
			 * Settings
			 */
			case 'settings':
				// General.
				$result = $this->base->get_class( 'settings' )->update_settings( 'general', $_POST['general'] );
				if ( is_wp_error( $result ) ) {
					$this->base->get_class( 'notices' )->add_error_notice( $result->get_error_message() );
					return;
				}

				// User Options.
				$result = $this->base->get_class( 'settings' )->update_settings( 'user-options', $_POST['user-options'] );
				if ( is_wp_error( $result ) ) {
					$this->base->get_class( 'notices' )->add_error_notice( $result->get_error_message() );
					return;
				}

				/**
				 * Save POSTed data on a Settings Screen
				 *
				 * @since   1.0.7
				 *
				 * @param   mixed   $result    Result of saving data (true or WP_Error)
				 * @param   array   $_POST     Unfiltered $_POST data
				 */
				$result = apply_filters( 'media_library_organizer_admin_save_settings', true, $_POST );
				break;

			/**
			 * Other Screens
			 */
			default:
				/**
				 * Saves Settings for a non-setting screen.
				 *
				 * @since   1.0.7
				 *
				 * @param   mixed   $result     Result of importing data (true or WP_Error).
				 * @param   array   $_POST      Unfiltered $_POST data to save.
				 */
				$result = apply_filters( 'media_library_organizer_admin_save_settings_' . $screen, '', $_POST );
				break;
		}

		// Check the result.
		if ( isset( $result ) && is_wp_error( $result ) ) {
			$this->base->get_class( 'notices' )->add_error_notice( $result->get_error_message() );
			return;
		}

		// OK.
		$this->base->get_class( 'notices' )->add_success_notice( __( 'Settings saved.', 'media-library-organizer' ) );
		return true;

	}

	/**
	 * Helper method to get the setting value from the Plugin settings
	 *
	 * @since 1.0.0
	 *
	 * @param   string $screen   Screen.
	 * @param   string $key      Setting Key.
	 * @return  mixed               Value
	 */
	public function get_setting( $screen = '', $key = '' ) {

		return $this->base->get_class( 'settings' )->get_setting( $screen, $key );

	}

}