settings.php 37.1 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 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951
<?php

/**
 * CPAC_Settings Class
 *
 * @since 2.0
 */
class CPAC_Settings {

	/**
	 * CPAC class
	 *
	 * @since 2.0
	 */
	private $cpac;

	/**
	 * Settings Page
	 *
	 * @since 2.0
	 */
	private $settings_page;

	/**
	 * @since 2.0
	 * @param object CPAC
	 */
	function __construct( $cpac ) {

		$this->cpac = $cpac;

		// register settings
		add_action( 'admin_menu', array( $this, 'settings_menu' ) );

		// handle requests gets a low priority so it will trigger when all other plugins have loaded their columns
		add_action( 'admin_init', array( $this, 'handle_column_request' ), 1000 );

		add_action( 'wp_ajax_cpac_column_refresh', array( $this, 'ajax_column_refresh' ) );

		add_action( 'cpac_messages', array( $this, 'maybe_display_addon_statuschange_message' ) );
	}

	/**
	 * @since 3.1.1
	 */
	public function get_settings_page() {
		return $this->settings_page;
	}

	/**
	 * Get available Admin Columns admin page URLs
	 *
	 * @since 2.2
	 * @return array Available settings URLs ([settings_page] => [url])
	 */
	public function get_settings_urls() {

		/**
		 * Filter the URLs for the different settings screens available in admin columns
		 *
		 * @since 2.2
		 *
		 * @param array $settings_urls Available settings URLs ([settings_page] => [url])
		 * @param CPAC_Settings $settings_instance Settings class instance
		 */
		$settings_urls = apply_filters( 'cac/settings/settings_urls', array(
			'admin'				=> admin_url( 'options-general.php?page=codepress-admin-columns' ),
			'settings'			=> admin_url( 'options-general.php?page=codepress-admin-columns&tab=settings' ),
			'network_settings'	=> network_admin_url( 'settings.php?page=codepress-admin-columns' ),
			'info'				=> admin_url( 'options-general.php?page=codepress-admin-columns&info=' ),
			'upgrade'			=> admin_url( 'options-general.php?page=cpac-upgrade' )
		), $this );

		return $settings_urls;
	}

	/**
	 * Get the settings URL for a page
	 *
	 * @since 2.2
	 * @param string $page Optional. Admin page to get the URL from. Defaults to the basic Admin Columns page
	 * @return string Settings page URL
	 */
	public function get_settings_url( $page = '' ) {

		$settings_urls = $this->get_settings_urls();

		if ( isset( $settings_urls[ $page ] ) ) {
			return $settings_urls[ $page ];
		}

		if ( ! $page ) {
			return $settings_urls['admin'];
		}

		return add_query_arg( 'tab', $page, $this->get_settings_url() );
	}

	/**
	 * Display an activation/deactivation message on the addons page if applicable
	 *
	 * @since 2.2
	 */
	public function maybe_display_addon_statuschange_message() {

		if ( empty( $_REQUEST['tab'] ) || $_REQUEST['tab'] != 'addons' ) {
			return;
		}

		$message = '';

		if ( ! empty( $_REQUEST['activate'] ) ) {
			$message = __( 'Add-on successfully activated.', 'codepress-admin-columns' );
		}
		else if ( ! empty( $_REQUEST['deactivate'] ) ) {
			$message = __( 'Add-on successfully deactivated.', 'codepress-admin-columns' );
		}

		if ( ! $message ) {
			return;
		}
		?>
		<div class="updated cac-notification below-h2">
			<p><?php echo $message; ?></p>
		</div>
		<?php
	}

	/**
	 * @since 2.2
	 */
	public function ajax_column_refresh() {
		if ( ! empty( $_POST['formdata'] ) && ! empty( $_POST['column'] ) ) {
			parse_str( $_POST['formdata'], $formdata );
			$storagemodel_key = ! empty( $formdata['cpac_key'] ) ? $formdata['cpac_key'] : '';

			if ( $storagemodel_key && ! empty( $formdata[ $storagemodel_key ][ $_POST['column'] ] ) ) {
				$columndata = $formdata[ $formdata['cpac_key'] ][ $_POST['column'] ];
				$storage_model = $this->cpac->get_storage_model( $formdata['cpac_key'] );
				$registered_columns = $storage_model->get_registered_columns();

				if ( in_array( $columndata['type'], array_keys( $registered_columns ) ) ) {
					$column = clone $registered_columns[ $columndata['type'] ];
					$column->set_clone( $columndata['clone'] );

					foreach ( $columndata as $optionname => $optionvalue ) {
						$column->set_options( $optionname, $optionvalue );
					}

					$column->sanitize_label();

					$columns = array( $column->properties->name => $column );

					do_action( 'cac/columns', $columns );
					do_action( "cac/columns/storage_key={$storagemodel_key}", $columns );

					$column->display();
				}
			}
		}

		exit;
	}

	/**
	 * @since 1.0
	 */
	public function settings_menu() {
		// add settings page
		$this->settings_page = add_submenu_page( 'options-general.php', __( 'Admin Columns Settings', 'codepress-admin-columns' ), __( 'Admin Columns', 'codepress-admin-columns' ), 'manage_admin_columns', 'codepress-admin-columns', array( $this, 'display' ), false, 98 );

		// add help tabs
		add_action( "load-{$this->settings_page}", array( $this, 'help_tabs' ) );

		// register setting
		register_setting( 'cpac-general-settings', 'cpac_general_options' );

		// add cap to options.php
   		add_filter( 'option_page_capability_cpac-general-settings', array( $this, 'add_capability' ) );

		$this->enqueue_admin_scripts();
	}

	/**
	 * Print scripts and styles
	 *
	 * @since 2.4.7
	 */
	public function enqueue_admin_scripts() {
		add_action( 'admin_print_styles-' . $this->settings_page, array( $this, 'admin_styles' ) );
		add_action( 'admin_print_scripts-' . $this->settings_page, array( $this, 'admin_scripts' ) );
	}

	/**
	 * Allows the capaiblity 'manage_admin_columns' to store data through /wp-admin/options.php
	 *
	 * @since 2.0
	 */
	public function add_capability() {
		return 'manage_admin_columns';
	}

	/**
	 * @since 1.0
	 */
	public function admin_styles() {
		$minified = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';

		wp_enqueue_style( 'wp-pointer' );
		wp_enqueue_style( 'jquery-ui-lightness', CPAC_URL . 'assets/ui-theme/jquery-ui-1.8.18.custom.css', array(), CPAC_VERSION, 'all' );
		wp_enqueue_style( 'cpac-admin', CPAC_URL . "assets/css/admin-column{$minified}.css", array(), CPAC_VERSION, 'all' );
	}

	/**
	 * @since 1.0
	 */
	public function admin_scripts() {

		wp_enqueue_script( 'wp-pointer' );
		wp_enqueue_script( 'jquery-ui-slider' );

		$minified = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';

		wp_enqueue_script( 'cpac-admin-settings', CPAC_URL . "assets/js/admin-settings{$minified}.js", array( 'jquery', 'dashboard', 'jquery-ui-slider', 'jquery-ui-sortable' ), CPAC_VERSION );

		// javascript translations
		wp_localize_script( 'cpac-admin-settings', 'cpac_i18n', array(
			'clone'	=> __( '%s column is already present and can not be duplicated.', 'codepress-admin-columns' ),
		));
	}

	/**
	 * @since 1.0
	 */
	public function handle_column_request() {

		// only handle updates from the admin columns page
		if ( ! ( isset($_GET['page'] ) && in_array( $_GET['page'], array( 'codepress-admin-columns' ) ) && isset( $_REQUEST['cpac_action'] ) ) ) {
			return false;
		}

		// use $_REQUEST because the values are send both over $_GET and $_POST
		$action = isset( $_REQUEST['cpac_action'] ) ? $_REQUEST['cpac_action'] 	: '';
		$nonce  = isset( $_REQUEST['_cpac_nonce'] ) ? $_REQUEST['_cpac_nonce'] 	: '';
		$key 	= isset( $_REQUEST['cpac_key'] ) 	? $_REQUEST['cpac_key'] 	: '';

		switch ( $action ) :

			case 'update_by_type' :
				if ( wp_verify_nonce( $nonce, 'update-type' ) && $key ) {
					if ( $storage_model = $this->cpac->get_storage_model( $key ) ) {
						$storage_model->store();
					}
				}
				break;

			case 'restore_by_type' :
				if ( wp_verify_nonce( $nonce, 'restore-type' ) && $key ) {
					if ( $storage_model = $this->cpac->get_storage_model( $key ) ) {
						$storage_model->restore();
					}
				}
				break;

			case 'restore_all' :
				if ( wp_verify_nonce( $nonce, 'restore-all' ) ) {
					$this->restore_all();
				}
				break;

		endswitch;
	}

	/**
	 * Restore all column defaults
	 *
	 * @since 1.0
	 */
	private function restore_all() {
		global $wpdb;

		$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'cpac_options_%'" );

		cpac_admin_message( __( 'Default settings succesfully restored.',  'codepress-admin-columns' ), 'updated' );
	}

	/**
	 * Add help tabs to top menu
	 *
	 * @since 1.3.0
	 */
	public function help_tabs() {

		$screen = get_current_screen();

		if ( ! method_exists( $screen,'add_help_tab' ) )
			return;

		$tabs = array(
			array(
				'title'		=> __( "Overview", 'codepress-admin-columns' ),
				'content'	=>
					"<h5>Admin Columns</h5>
					<p>". __( "This plugin is for adding and removing additional columns to the administration screens for post(types), pages, media library, comments, links and users. Change the column's label and reorder them.", 'codepress-admin-columns' ) . "</p>"
			),
			array(
				'title'		=> __( "Basics", 'codepress-admin-columns' ),
				'content'	=> "
					<h5>" 	. __( "Change order", 'codepress-admin-columns' ) . "</h5>
					<p>" 	. __( "By dragging the columns you can change the order which they will appear in.", 'codepress-admin-columns' ) . "</p>
					<h5>" 	. __( "Change label", 'codepress-admin-columns' ) . "</h5>
					<p>" 	. __( "By clicking on the triangle you will see the column options. Here you can change each label of the columns heading.", 'codepress-admin-columns' ) . "</p>
					<h5>" 	. __( "Change column width", 'codepress-admin-columns' ) . "</h5>
					<p>" 	. __( "By clicking on the triangle you will see the column options. By using the draggable slider you can set the width of the columns in percentages.", 'codepress-admin-columns' ) . "</p>
				"
			),
			array(
				'title'		=> __( "Custom Field", 'codepress-admin-columns' ),
				'content'	=>
					"<h5>". __( "'Custom Field' column", 'codepress-admin-columns' ) . "</h5>
					<p>". __( "The custom field colum uses the custom fields from posts and users. There are 10 types which you can set.", 'codepress-admin-columns' ) . "</p>
					<ul>
						<li><strong>". __( "Default", 'codepress-admin-columns' ) . "</strong><br/>". __( "Value: Can be either a string or array. Arrays will be flattened and values are seperated by a ',' comma.", 'codepress-admin-columns' ) . "</li>
						<li><strong>". __( "Image", 'codepress-admin-columns' ) . "</strong><br/>". __( "Value: should contain an image URL or Attachment IDs ( seperated by a ',' comma ).", 'codepress-admin-columns' ) . "</li>
						<li><strong>". __( "Excerpt", 'codepress-admin-columns' ) . "</strong><br/>". __( "Value: This will show the first 20 words of the Post content.", 'codepress-admin-columns' ) . "</li>
						<li><strong>". __( "Multiple Values", 'codepress-admin-columns' ) . "</strong><br/>". __( "Value: should be an array. This will flatten any ( multi dimensional ) array.", 'codepress-admin-columns' ) . "</li>
						<li><strong>". __( "Numeric", 'codepress-admin-columns' ) . "</strong><br/>". __( "Value: Integers only.<br/>If you have the 'sorting addon' this will be used for sorting, so you can sort your posts on numeric (custom field) values.", 'codepress-admin-columns' ) . "</li>
						<li><strong>". __( "Date", 'codepress-admin-columns' ) . "</strong><br/>". sprintf( __( "Value: Can be unix time stamp or a date format as described in the <a href='%s'>Codex</a>. You can change the outputted date format at the <a href='%s'>general settings</a> page.", 'codepress-admin-columns' ), 'http://codex.wordpress.org/Formatting_Date_and_Time', get_admin_url() . 'options-general.php' ) . "</li>
						<li><strong>". __( "Post Titles", 'codepress-admin-columns' ) . "</strong><br/>". __( "Value: can be one or more Post ID's (seperated by ',').", 'codepress-admin-columns' ) . "</li>
						<li><strong>". __( "Usernames", 'codepress-admin-columns' ) . "</strong><br/>". __( "Value: can be one or more User ID's (seperated by ',').", 'codepress-admin-columns' ) . "</li>
						<li><strong>". __( "Checkmark", 'codepress-admin-columns' ) . "</strong><br/>". __( "Value: should be a 1 (one) or 0 (zero).", 'codepress-admin-columns' ) . "</li>
						<li><strong>". __( "Color", 'codepress-admin-columns' ) . "</strong><br/>". __( "Value: hex value color, such as #808080.", 'codepress-admin-columns' ) . "</li>
						<li><strong>". __( "Counter", 'codepress-admin-columns' ) . "</strong><br/>". __( "Value: Can be either a string or array. This will display a count of the number of times the meta key is used by the item.", 'codepress-admin-columns' ) . "</li>
					</ul>
				"
			)
		);

		foreach ( $tabs as $k => $tab ) {
			$screen->add_help_tab( array(
				'id'		=> 'cpac-tab-'.$k,
				'title'		=> $tab['title'],
				'content'	=> $tab['content'],
			));
		}
	}

	/**
	 * @since 1.0
	 * @param string $storage_model URL type.
	 * @return string Url.
	 */
	public function get_url( $type ) {

		$site_url = 'http://www.admincolumns.com';

		$urls = array(
			'main'				=> $site_url,
			'pricing'			=> $site_url . '/pricing-purchase/',
			'codepress'			=> 'http://www.codepresshq.com',
			'admincolumns'		=> $site_url,
			'admincolumnspro'	=> $site_url,
			'documentation'		=> $site_url . '/documentation/',
			'feedback'			=> 'http://www.codepresshq.com/contact',
			'plugins'			=> 'http://wordpress.org/extend/plugins/codepress-admin-columns/',
			'support'			=> 'http://wordpress.org/tags/codepress-admin-columns/',
		);

		if ( ! isset( $urls[ $type ] ) )
			return false;

		return $urls[ $type ];
	}

	/**
	 * @since 2.0
	 */
	public function uses_custom_fields() {

		$old_columns = get_option('cpac_options');

		if ( empty( $old_columns['columns'] ) ) return false;

		foreach ( $old_columns['columns'] as $columns ) {
			foreach ( $columns as $id => $values ) {
				if ( strpos( $id, 'column-meta-' ) !== false )
					return true;
			}
		}

		return false;
	}

	/**
	 * Welcome screen
	 *
	 * @since 2.0
	 */
	public function welcome_screen() {

		// Should only be set after upgrade
		$show_welcome = false !== get_transient('cpac_show_welcome');

		// Should only be set manual
		if ( isset( $_GET['info'] ) ) {
			$show_welcome = true;
		}

		if ( ! $show_welcome ) {
			return false;
		}

		// Set check that welcome should not be displayed.
		delete_transient('cpac_show_welcome');

		$tab = !empty( $_GET['info'] ) ? $_GET['info'] : 'whats-new';

		?>

		<div id="cpac-welcome" class="wrap about-wrap">

			<h1><?php _e( "Welcome to Admin Columns", 'codepress-admin-columns' ); ?> <?php echo CPAC_VERSION; ?></h1>

			<div class="about-text">
				<?php _e( "Thank you for updating to the latest version!", 'codepress-admin-columns' ); ?>
				<?php _e( "Admin Columns is more polished and enjoyable than ever before. We hope you like it.", 'codepress-admin-columns' ); ?>
			</div>

			<div class="cpac-content-body">
				<h2 class="nav-tab-wrapper">
					<a class="cpac-tab-toggle nav-tab <?php if( $tab == 'whats-new' ){ echo 'nav-tab-active'; } ?>" href="<?php echo $this->get_settings_url( 'info' ); ?>whats-new"><?php _e( "What’s New", 'codepress-admin-columns' ); ?></a>
					<a class="cpac-tab-toggle nav-tab <?php if( $tab == 'changelog' ){ echo 'nav-tab-active'; } ?>" href="<?php echo $this->get_settings_url( 'info' ); ?>changelog"><?php _e( "Changelog", 'codepress-admin-columns' ); ?></a>
				</h2>

			<?php if ( 'whats-new' === $tab ) : ?>

				<h3><?php _e( "Important", 'codepress-admin-columns' ); ?></h3>

				<h4><?php _e( "Database Changes", 'codepress-admin-columns' ); ?></h4>
				<p><?php _e("The database has been changed between versions 1 and 2. But we made sure you can still roll back to version 1x without any issues.", 'codepress-admin-columns' ); ?></p>

			<?php if ( get_option( 'cpac_version', false ) < CPAC_UPGRADE_VERSION ) : ?>
				<p><?php _e("Make sure you backup your database and then click", 'codepress-admin-columns' ); ?> <a href="<?php echo $this->get_settings_url( 'upgrade' ); ?>" class="button-primary"><?php _e( "Upgrade Database", 'codepress-admin-columns' );?></a></p>
			<?php endif; ?>

				<h4><?php _e( "Potential Issues", 'codepress-admin-columns' ); ?></h4>
				<p><?php _e( "Do to the sizable refactoring the code, surounding Addons and action/filters, your website may not operate correctly. It is important that you read the full", 'codepress-admin-columns' ); ?> <a href="<?php echo $this->get_url('admincolumns'); ?>migrating-from-v1-to-v2" target="_blank"><?php _e( "Migrating from v1 to v2", 'codepress-admin-columns' ); ?></a> <?php _e( "guide to view the full list of changes.", 'codepress-admin-columns' ); ?> <?php printf( __( "When you have found a bug please <a href='%s'>report them to us</a> so we can fix it in the next release.", 'codepress-admin-columns'), 'mailto:info@codepress.nl' ); ?></p>

				<div class="cpac-alert cpac-alert-error">
					<p><strong><?php _e( "Important!", 'codepress-admin-columns' ); ?></strong> <?php _e( "If you updated the Admin Columns plugin without prior knowledge of such changes, Please roll back to the latest", 'codepress-admin-columns' ); ?> <a href="http://downloads.wordpress.org/plugin/codepress-admin-columns.1.4.9.zip"> <?php _e( "version 1", 'codepress-admin-columns' ); ?></a> <?php _e( "of this plugin.", 'codepress-admin-columns' ); ?></p>
				</div>

			<?php endif; ?>
			<?php if ( 'changelog' === $tab ) : ?>

				<h3><?php _e("Changelog for", 'codepress-admin-columns'); ?> <?php echo CPAC_VERSION; ?></h3>
				<?php

				$items = file_get_contents( CPAC_DIR . 'readme.txt' );
				$items = explode('= ' . CPAC_VERSION . ' =', $items);
				$items = end( $items );
				$items = current( explode("\n\n", $items) );
				$items = current( explode("= ", $items) );
				$items = array_filter( array_map('trim', explode("*", $items)) );

				?>
				<ul class="cpac-changelog">
				<?php foreach( $items as $item ) :
					$item = explode('http', $item);
				?>
					<li><?php echo $item[0]; ?><?php if( isset($item[1]) ): ?><a href="http<?php echo $item[1]; ?>" target="_blank"><?php _e("Learn more", 'codepress-admin-columns'); ?></a><?php endif; ?></li>
				<?php endforeach; ?>
				</ul>

			<?php endif; ?>
				<hr/>

			</div><!--.cpac-content-body-->

			<div class="cpac-content-footer">
				<a class="button-primary button-large" href="<?php echo $this->get_settings_url( 'general' ); ?>"><?php _e("Start using Admin Columns", 'codepress-admin-columns' ); ?></a>
			</div><!--.cpac-content-footer-->

		</div>
		<?php

		return true;
	}

	/**
	 * @since 1.0
	 */
	public function display_settings() {
	?>
		<table class="form-table cpac-form-table settings">
			<tbody>

				<tr class="general">
					<th scope="row">
						<h3><?php _e( 'General Settings', 'codepress-admin-columns' ); ?></h3>
						<p><?php _e( 'Customize your Admin Columns settings.', 'codepress-admin-columns' ); ?></p>
					</th>
					<td class="padding-22">
						<div class="cpac_general">
							<form method="post" action="options.php">
								<?php settings_fields( 'cpac-general-settings' ); ?>
								<?php $options = get_option( 'cpac_general_options' ); ?>
								<p>
									<label for="show_edit_button">
										<input name="cpac_general_options[show_edit_button]" type="hidden" value="0" >
										<input name="cpac_general_options[show_edit_button]" id="show_edit_button" type="checkbox" value="1" <?php checked( ! isset( $options['show_edit_button'] ) || ( '1' == $options['show_edit_button'] ) ); ?>>
										<?php _e( "Show \"Edit Columns\" button on admin screens. Default is <code>on</code>.", 'codepress-admin-columns' ); ?>
									</label>
								</p>

								<?php do_action( 'cac/settings/general', $options ); ?>

								<p>
									<input type="submit" class="button" value="<?php _e( 'Save' ); ?>" />
								</p>
							</form>
						</div>
					</td>
				</tr><!--.general-->

				<?php

				/** Allow plugins to add their own custom settings to the settings page. */
				if ( $groups = apply_filters( 'cac/settings/groups', array() ) ) {

					foreach ( $groups as $id => $group ) {

						$title 			= isset( $group['title'] ) ? $group['title'] : '';
						$description 	= isset( $group['description'] ) ? $group['description'] : '';

						?>
				<tr>
					<th scope="row">
						<h3><?php echo $title; ?></h3>
						<p><?php echo $description; ?></p>
					</th>
					<td class="padding-22">
						<?php

						/** Use this Hook to add additonal fields to the group */
						do_action( "cac/settings/groups/row={$id}" );

						?>
					</td>
				</tr>
						<?php
					}
				}

				?>

				<tr class="restore">
					<th scope="row">
						<h3><?php _e( 'Restore Settings', 'codepress-admin-columns' ); ?></h3>
						<p><?php _e( 'This will delete all column settings and restore the default settings.', 'codepress-admin-columns' ); ?></p>
					</th>
					<td class="padding-22">
						<form method="post" action="">
							<?php wp_nonce_field( 'restore-all','_cpac_nonce'); ?>
							<input type="hidden" name="cpac_action" value="restore_all" />
							<input type="submit" class="button" name="cpac-restore-defaults" value="<?php _e( 'Restore default settings', 'codepress-admin-columns' ) ?>" onclick="return confirm('<?php _e("Warning! ALL saved admin columns data will be deleted. This cannot be undone. \'OK\' to delete, \'Cancel\' to stop", 'codepress-admin-columns' ); ?>');" />
						</form>
					</td>
				</tr><!--.restore-->

			</tbody>
		</table>

	<?php
	}

	/**
	 * @since 2.4.1
	 */
	private function get_menu_types() {
		$menu_types = array(
			'post' => __( 'Posttypes', 'codepress-admin-columns' ),
			'other' => __( 'Others', 'codepress-admin-columns' ),
			'taxonomy' => __( 'Taxonomies', 'codepress-admin-columns' ),
		);
		return apply_filters( 'cac/menu_types', $menu_types );
	}

	/**
	 * @since 1.0
	 */
	public function display() {

		if ( $this->welcome_screen() ) {
			return;
		}

		$tabs = array(
			'general'	=> __( 'Admin Columns', 'codepress-admin-columns' ),
			'settings'	=> __( 'Settings', 'codepress-admin-columns' ),
			'addons'	=> __( 'Add-ons', 'codepress-admin-columns' )
		);

		/**
		 * Filter the tabs on the settings screen
		 *
		 * @param array $tabs Available tabs
		 */
		$tabs = apply_filters( 'cac/settings/tabs', $tabs );

		$current_tab = ( empty( $_GET['tab'] ) ) ? 'general' : sanitize_text_field( urldecode( $_GET['tab'] ) );
		?>
		<div id="cpac" class="wrap">
			<?php screen_icon( 'codepress-admin-columns' ); ?>
			<h2 class="nav-tab-wrapper cpac-nav-tab-wrapper">
				<?php foreach( $tabs as $name => $label ) : ?>
					<a href="<?php echo $this->get_settings_url( 'admin' ) . "&amp;tab={$name}"; ?>" class="nav-tab<?php if( $current_tab == $name ) echo ' nav-tab-active'; ?>"><?php echo $label; ?></a>
				<?php endforeach; ?>
			</h2>

			<?php do_action( 'cpac_messages' ); ?>

			<?php
			switch ( $current_tab ) :
				case 'general':

					$post_types = array_values( $this->cpac->get_post_types() );
					$first = array_shift( $post_types );

					$storage_models_by_type = array();
					foreach ( $this->cpac->storage_models as $k => $storage_model ) {
						$storage_models_by_type[ $storage_model->menu_type ][ $k ] = $storage_model;
					}

					?>
					<div class="cpac-menu">
					<?php
					foreach ( $this->get_menu_types() as $menu_type => $label ) {
						if ( ! empty( $storage_models_by_type[ $menu_type ] ) ) {
							$count = 0; ?>
							<ul class="subsubsub">
								<li class="first"><?php echo $label; ?>: </li>
							<?php foreach ( $storage_models_by_type[ $menu_type ] as $storage_model ) : ?>
								<li><?php echo $count++ != 0 ? ' | ' : ''; ?><a href="#cpac-box-<?php echo $storage_model->key; ?>" <?php echo $storage_model->is_menu_type_current( $first ) ? ' class="current"' : '';?> ><?php echo $storage_model->label; ?></a></li>
							<?php endforeach; ?>
							</ul>
						<?php
						}
					}
					?>
					</div>

					<?php do_action( 'cac/settings/after_menu' ); ?>

					<?php $count = 0; ?>
					<?php foreach ( $this->cpac->storage_models as $storage_model ) : ?>
						<div class="columns-container" data-type="<?php echo $storage_model->key ?>"<?php echo $storage_model->is_menu_type_current( $first ) ? '' : ' style="display:none"'; ?>>

							<div class="columns-left">
								<div id="titlediv">
									<h2>
										<?php echo $storage_model->label; ?>
										<?php $storage_model->screen_link(); ?>
									</h2>
								</div>

								<?php if ( $storage_model->is_using_php_export() ) : ?>
									<div class="error below-h2">
										<p><?php printf( __( 'The columns for %s are set up via PHP and can therefore not be edited in the admin panel.', 'codepress-admin-columns' ), '<strong>' . $storage_model->label . '</strong>' ); ?></p>
									</div>
								<?php endif; ?>
							</div>

							<div class="columns-right">
								<div class="columns-right-inside">
									<?php if ( ! $storage_model->is_using_php_export() ) : ?>
										<div class="sidebox" id="form-actions">
											<h3>
												<?php _e( 'Store settings', 'codepress-admin-columns' ) ?>
											</h3>
											<?php $has_been_stored = $storage_model->get_stored_columns() ? true : false; ?>
											<div class="form-update">
												<a href="javascript:;" class="button-primary submit-update"><?php echo $has_been_stored ? __( 'Update' ) : __('Save'); ?> <?php echo $storage_model->label; ?></a>
											</div>
											<?php if ( $has_been_stored ) : ?>
											<div class="form-reset">
												<a href="<?php echo add_query_arg( array( '_cpac_nonce' => wp_create_nonce('restore-type'), 'cpac_key' => $storage_model->key, 'cpac_action' => 'restore_by_type' ), $this->get_settings_url( 'admin' ) ); ?>" class="reset-column-type" onclick="return confirm('<?php printf( __( "Warning! The %s columns data will be deleted. This cannot be undone. \'OK\' to delete, \'Cancel\' to stop", 'codepress-admin-columns' ), $storage_model->label ); ?>');">
													<?php _e( 'Restore', 'codepress-admin-columns' ); ?> <?php echo $storage_model->label; ?> <?php _e( 'columns', 'codepress-admin-columns' ); ?>
												</a>
											</div>
											<?php endif; ?>

											<?php do_action( 'cac/settings/form_actions', $storage_model ); ?>

										</div><!--form-actions-->
									<?php endif; ?>

									<?php if ( ! cpac_is_pro_active() ) : ?>
									<?php $url_args = array(
										'utm_source' => 'plugin-installation',
										'utm_medium' => 'banner',
										'utm_campaign' => 'plugin-installation'
									); ?>
									<div class="sidebox" id="pro-version">
										<div class="padding-box cta">
											<h3>
												<a href="<?php echo add_query_arg( array_merge( $url_args, array( 'utm_content' => 'title' ) ), $this->get_url( 'admincolumnspro' ) ); ?>"><?php _e( 'Get Admin Columns Pro', 'codepress-admin-columns' ) ?></a>
											</h3>
											<div class="inside">
												<ul>
													<li><a href="<?php echo add_query_arg( array_merge( $url_args, array( 'utm_content' => 'usp-sorting' ) ), $this->get_url( 'admincolumnspro' ) ) ?>"><?php _e( 'Add Sorting', 'codepress-admin-columns' ); ?></a></li>
													<li><a href="<?php echo add_query_arg( array_merge( $url_args, array( 'utm_content' => 'usp-filtering' ) ), $this->get_url( 'admincolumnspro' ) ) ?>"><?php _e( 'Add Filtering', 'codepress-admin-columns' ); ?></a></li>
													<li><a href="<?php echo add_query_arg( array_merge( $url_args, array( 'utm_content' => 'usp-import-export' ) ), $this->get_url( 'admincolumnspro' ) ) ?>"><?php _e( 'Add Import/Export', 'codepress-admin-columns' ); ?></a></li>
													<li><a href="<?php echo add_query_arg( array_merge( $url_args, array( 'utm_content' => 'usp-editing' ) ), $this->get_url( 'admincolumnspro' ) ) ?>"><?php _e( 'Add Direct Editing', 'codepress-admin-columns' ); ?></a></li>
												</ul>
												<p>
													<?php printf( __( "Check out <a href='%s'>Admin Columns Pro</a> for more details!", 'codepress-admin-columns' ), add_query_arg( array_merge( $url_args, array( 'utm_content' => 'cta' ) ), $this->get_url( 'admincolumnspro' ) ) ); ?>
												</p>
											</div>
										</div>
									</div>

									<div class="sidebox" id="direct-feedback">
										<div id="feedback-choice">
											<h3><?php _e( 'Are you happy with Admin Columns?', 'codepress-admin-columns' ); ?></h3>
											<div class="inside">
												<a href="#" class="yes">Yes</a>
												<a href="#" class="no">No</a>
											</div>
										</div>
										<div id="feedback-support">
											<div class="inside">
												<p><?php _e( "What's wrong? Need help? Let us know!", 'codepress-admin-columns' ); ?></p>
												<p><?php _e( 'Check out our extensive documentation, or you can open a support topic on WordPress.org!', 'codepress-admin-columns' ); ?></p>
												<ul class="share">
													<li>
														<a href="<?php echo add_query_arg( array(
															'utm_source' => 'plugin-installation',
															'utm_medium' => 'feedback-docs-button',
															'utm_campaign' => 'plugin-installation'
														), $this->get_url( 'documentation' ) ); ?>" target="_blank">
															<div class="dashicons dashicons-editor-help"></div> <?php _e( 'Docs', 'codepress-admin-columns' ); ?>
														</a>
													</li>
													<li>
														<a href="https://wordpress.org/support/plugin/codepress-admin-columns" target="_blank">
															<div class="dashicons dashicons-wordpress"></div> <?php _e( 'Forums', 'codepress-admin-columns' ); ?>
														</a>
													</li>
												</ul>
												<div class="clear"></div>
											</div>
										</div>
										<div id="feedback-rate">
											<div class="inside">
												<p><?php _e( "Woohoo! We're glad to hear that!", 'codepress-admin-columns' ); ?></p>
												<p><?php _e( 'We would really love it if you could show your appreciation by giving us a rating on WordPress.org or tweet about Admin Columns!', 'codepress-admin-columns' ); ?></p>
												<ul class="share">
													<li>
														<a href="http://wordpress.org/support/view/plugin-reviews/codepress-admin-columns#postform" target="_blank">
															<div class="dashicons dashicons-star-empty"></div> <?php _e( 'Rate', 'codepress-admin-columns' ); ?>
														</a>
													</li>

													<li>
														<a href="<?php echo add_query_arg( array(
															'hashtags' => 'admincolumns',
															'text' => urlencode( "I'm using Admin Columns for WordPress!" ),
															'url' => urlencode( 'http://wordpress.org/plugins/codepress-admin-columns/' ),
															//'via' => 'wpcolumns'
														), 'https://twitter.com/intent/tweet' ); ?>" target="_blank">
															<div class="dashicons dashicons-twitter"></div> <?php _e( 'Tweet', 'codepress-admin-columns' ); ?>
														</a>
													</li>

													<li>
														<a href="<?php echo add_query_arg( array(
															'utm_source' => 'plugin-installation',
															'utm_medium' => 'feedback-purchase-button',
															'utm_campaign' => 'plugin-installation'
														), $this->get_url( 'admincolumnspro' ) ); ?>" target="_blank">
															<div class="dashicons dashicons-cart"></div> <?php _e( 'Buy Pro', 'codepress-admin-columns' ); ?>
														</a>
													</li>
												</ul>
												<div class="clear"></div>
											</div>
										</div>
									</div>

									<?php endif; ?>

									<div class="sidebox" id="plugin-support">
										<h3><?php _e( 'Support', 'codepress-admin-columns' ); ?></h3>
										<div class="inside">
											<?php if ( version_compare( get_bloginfo( 'version' ), '3.2', '>' ) ) : ?>
												<p><?php _e( 'Check the <strong>Help</strong> section in the top-right screen.', 'codepress-admin-columns' ); ?></p>
											<?php endif; ?>
											<p>
												<?php printf( __("For full documentation, bug reports, feature suggestions and other tips <a href='%s'>visit the Admin Columns website</a>", 'codepress-admin-columns' ), $this->get_url('documentation') ); ?>
											</p>
										</div>
									</div><!--plugin-support-->

								</div><!--.columns-right-inside-->
							</div><!--.columns-right-->

							<div class="columns-left">
								<div class="cpac-boxes">
									<?php if ( ! $storage_model->is_using_php_export() ) : ?>
										<div class="cpac-columns">

											<form method="post" action="">
												<?php wp_nonce_field( 'update-type', '_cpac_nonce'); ?>

												<input type="hidden" name="cpac_key" value="<?php echo $storage_model->key; ?>" />
												<input type="hidden" name="cpac_action" value="update_by_type" />

												<?php
												foreach ( $storage_model->columns as $column ) {
													$column->display();
												}
												?>
											</form>

										</div><!--.cpac-columns-->

										<div class="column-footer">
											<div class="order-message"><?php _e( 'Drag and drop to reorder', 'codepress-admin-columns' ); ?></div>

											<div class="button-container">
												<a href="javascript:;" class="add_column button button-primary">+ <?php _e( 'Add Column', 'codepress-admin-columns' );?></a><br/>
											</div>

										</div><!--.cpac-column-footer-->
									<?php endif; ?>
								</div><!--.cpac-boxes-->
							</div><!--.columns-left-->
							<div class="clear"></div>

							<div class="for-cloning-only" style="display:none">
								<?php
								foreach ( $storage_model->get_registered_columns() as $column ) {
									$column->display();
								}
								?>
							</div>
						</div><!--.columns-container-->
					<?php endforeach; // storage_models ?>

					<div class="clear"></div>
					<?php
					break; // case: general
				case 'settings' :
					$this->display_settings();
					break;
				case 'addons' :
					$this->tab_addons();
					break;
				case 'help' :
					//$this->tab_addons();
					break;
				default:

					/**
					 * Action to add tab contents
					 *
					 */
					do_action( 'cac/settings/tab_contents/tab=' . $current_tab );

			endswitch;
			?>
		</div><!--.wrap-->
	<?php
	}

	/**
	 * @since 2.2
	 */
	public function tab_addons() {

		$addon_groups = $this->cpac->addons()->get_addon_groups();
		$grouped_addons = $this->cpac->addons()->get_available_addons( true );
		?>
		<?php foreach ( $grouped_addons as $group_name => $addons ) : ?>
			<h3><?php echo $addon_groups[ $group_name ]; ?></h3>

			<ul class="cpac-addons">
				<?php foreach ( $addons as $addon_name => $addon ) : ?>
					<li>
						<div class="cpac-addon-content">
							<?php if ( ! empty( $addon['image'] ) ) : ?>
								<img src="<?php echo $addon['image']; ?>" />
							<?php else : ?>
								<h3><?php echo $addon['title']; ?></h3>
							<?php endif; ?>
						</div>
						<div class="cpac-addon-header">
							<h3><?php echo $addon['title']; ?></h3>
							<p><?php echo $addon['description']; ?></p>
						</div>
						<div class="cpac-addon-actions">
							<?php

							// Installed..
							if ( ( $plugin_basename = $this->cpac->addons()->get_installed_addon_plugin_basename( $addon_name ) ) ) : ?>
								<?php if ( is_plugin_active( $plugin_basename ) ) : ?>
									<?php $deactivation_url = wp_nonce_url( add_query_arg( array(
										'action' => 'deactivate',
										'plugin' => urlencode( $plugin_basename ),
										'cpac-redirect' => true
									), admin_url( 'plugins.php' ) ), 'deactivate-plugin_' . $plugin_basename ); ?>
									<a href="#" class="button button-disabled cpac-installed"><?php _e( 'Active', 'codepress-admin-columns' ); ?></a>
									<a href="<?php echo esc_attr( $deactivation_url ); ?>" class="button right"><?php _e( 'Deactivate', 'codepress-admin-columns' ); ?></a>
								<?php else : ?>
									<?php $activation_url = wp_nonce_url( add_query_arg( array(
										'action' => 'activate',
										'plugin' => urlencode( $plugin_basename ),
										'cpac-redirect' => true
									), admin_url( 'plugins.php' ) ), 'activate-plugin_' . $plugin_basename ); ?>
									<a href="#" class="button button-disabled cpac-installed"><?php _e( 'Installed', 'codepress-admin-columns' ); ?></a>
									<a href="<?php echo esc_attr( $activation_url ); ?>" class="button right"><?php _e( 'Activate', 'codepress-admin-columns' ); ?></a>
								<?php endif; ?>
							<?php

							// Not installed...
							else :

								// Got ACP?
								if ( class_exists('CAC_Addon_Pro') ) :
									$install_url = wp_nonce_url( add_query_arg( array(
										'action' => 'install',
										'plugin' => $addon_name,
									), $this->get_settings_url( 'addons' ) ), 'install-cac-addon' );
									?>
									<a href="<?php echo esc_attr( $install_url ); ?>" class="button"><?php _e( 'Download & Install', 'codepress-admin-columns' ); ?></a>
								<?php

								// Get ACP?
								else : ?>
									<a target="_blank" href="<?php echo esc_attr( $this->get_url('pricing') ); ?>" class="button"><?php _e( 'Get this add-on', 'codepress-admin-columns' ); ?></a>
								<?php endif; ?>
							<?php endif; ?>
						</div>
					</li>
				<?php endforeach; // addons ?>
			</ul>
		<?php endforeach; // grouped_addons ?>
		<?php
	}
}