class-ld-settings-page-help.php 13.9 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
<?php
/**
 * LearnDash Settings Page Overview.
 *
 * @since 4.4.0
 * @package LearnDash\Settings\Pages
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( class_exists( 'LearnDash_Settings_Page' ) && ! class_exists( 'LearnDash_Settings_Page_Help' ) ) {
	/**
	 * Class LearnDash Settings Page Overview.
	 *
	 * @since 4.4.0
	 */
	class LearnDash_Settings_Page_Help extends LearnDash_Settings_Page {

		/**
		 * Public constructor for class
		 *
		 * @since 4.4.0
		 */
		public function __construct() {
			$this->parent_menu_page_url  = 'admin.php?page=learndash-help';
			$this->menu_page_capability  = LEARNDASH_ADMIN_CAPABILITY_CHECK;
			$this->settings_page_id      = 'learndash-help';
			$this->settings_page_title   = esc_html__( 'LearnDash Help', 'learndash' );
			$this->settings_tab_title    = esc_html__( 'Help', 'learndash' );
			$this->settings_tab_priority = 100;

			if ( ! learndash_cloud_is_enabled() ) {
				add_filter( 'learndash_submenu', array( $this, 'submenu_item' ), 200 );

				add_filter( 'learndash_admin_tab_sets', array( $this, 'learndash_admin_tab_sets' ), 10, 3 );
				add_filter( 'learndash_header_data', array( $this, 'admin_header' ), 40, 3 );
				add_action( 'admin_head', array( $this, 'output_admin_inline_scripts' ) );

				parent::__construct();
			}
		}

		/**
		 * Control visibility of submenu items based on license status
		 *
		 * @since 4.4.0
		 *
		 * @param array $submenu Submenu item to check.
		 *
		 * @return array
		 */
		public function submenu_item( array $submenu ) : array {
			if ( ! isset( $submenu[ $this->settings_page_id ] ) ) {
				$submenu = array_merge(
					$submenu,
					array(
						$this->settings_page_id => array(
							'name'  => $this->settings_tab_title,
							'cap'   => $this->menu_page_capability,
							'link'  => $this->parent_menu_page_url,
							'class' => 'submenu-ldlms-help',
						),
					)
				);
			}

			return $submenu;
		}

		/**
		 * Filter the admin header data. We don't want to show the header panel on the Overview page.
		 *
		 * @since 4.4.0
		 *
		 * @param array  $header_data Array of header data used by the Header Panel React app.
		 * @param string $menu_key The menu key being displayed.
		 * @param array  $menu_items Array of menu/tab items.
		 *
		 * @return array
		 */
		public function admin_header( array $header_data = array(), string $menu_key = '', array $menu_items = array() ) : array {
			// Clear out $header_data if we are showing our page.
			return $menu_key === $this->parent_menu_page_url ? array() : $header_data;
		}

		/**
		 * Output inline scripts or styles in HTML head tag.
		 *
		 * @since 4.4.0
		 *
		 * @return void
		 */
		public function output_admin_inline_scripts() : void {
			?>
            <?php // phpcs:ignore?>
            <?php if ( isset( $_GET['page'] ) && in_array( $_GET['page'], [ 'learndash-help' ], true ) ) : ?>
				<style>
					body .notice {
						display: none;
					}
				</style>
			<?php endif; ?>
			<?php
		}

		/**
		 * Filter for page title wrapper.
		 *
		 * @since 4.4.0
		 *
		 * @return string
		 */
		public function get_admin_page_title() : string {
			/** This filter is documented in includes/settings/class-ld-settings-pages.php */
			return apply_filters( 'learndash_admin_page_title', '<h1>' . $this->settings_page_title . '</h1>' );
		}

		/**
		 * Enqueue support assets
		 *
		 * @since 4.4.0
		 *
		 * @return void
		 */
		public static function enqueue_support_assets() : void {
			wp_enqueue_style(
				'learndash-help',
				LEARNDASH_LMS_PLUGIN_URL . '/assets/css/help.css',
				array(),
				LEARNDASH_VERSION,
				'all'
			);

			wp_enqueue_script(
				'learndash-help',
				LEARNDASH_LMS_PLUGIN_URL . '/assets/js/help.js',
				array( 'jquery' ),
				LEARNDASH_VERSION,
				true
			);
		}

		/**
		 * Action function called when Add-ons page is loaded.
		 *
		 * @since 4.4.0
		 *
		 * @return void
		 */
		public function load_settings_page() : void {

			global $learndash_assets_loaded;

			self::enqueue_support_assets();

			$learndash_assets_loaded['styles']['learndash-admin-help-page-style'] = __FUNCTION__;

			$learndash_assets_loaded['scripts']['learndash-admin-help-page-script'] = __FUNCTION__;
		}

		/**
		 * Hide the tab menu items if on add-on page.
		 *
		 * @since 4.4.0
		 *
		 * @param array  $tab_set Tab Set.
		 * @param string $tab_key Tab Key.
		 * @param string $current_page_id ID of shown page.
		 *
		 * @return array
		 */
		public function learndash_admin_tab_sets( array $tab_set = array(), string $tab_key = '', string $current_page_id = '' ) : array {
			if ( ( ! empty( $tab_set ) ) && ( ! empty( $tab_key ) ) && ( ! empty( $current_page_id ) ) ) {
				if ( 'admin_page_learndash-help' === $current_page_id ) {
					?>
					<style> h1.nav-tab-wrapper { display: none; }</style>
					<?php
				}
			}
			return $tab_set;
		}

		/**
		 * Output page display HTML.
		 *
		 * @since 4.4.0
		 *
		 * @return void
		 */
		public function show_settings_page() : void {
			$categories = self::get_categories();

			SFWD_LMS::get_view(
				'support/help',
				array(
					'categories' => $categories,
				),
				true
			);
		}

		/**
		 * Get categories
		 *
		 * @since 4.4.0
		 *
		 * @return array<string, array<string, string>>
		 */
		public static function get_categories() : array {
			$categories = array(
				'getting-started'     => array(
					'id'          => 'getting-started',
					'helpScoutId' => '',
					'label'       => __( 'Getting Started', 'learndash' ),
                    // phpcs:ignore Generic.Files.LineLength.TooLong
					'description' => __( 'Not sure what to do next? Read our top articles to get more information.', 'learndash' ),
					'icon'        => 'getting-started',
				),
				'learndash-core'      => array(
					'id'          => 'learndash-core',
					'helpScoutId' => '',
					'label'       => __( 'LearnDash Core', 'learndash' ),
                    // phpcs:ignore Generic.Files.LineLength.TooLong
					'description' => __( 'Everything about LearnDash LMS core plugin.', 'learndash' ),
					'icon'        => 'core',
				),
				'add-ons'             => array(
					'id'          => 'add-ons',
					'helpScoutId' => '',
					'label'       => __( 'Add-Ons', 'learndash' ),
                    // phpcs:ignore Generic.Files.LineLength.TooLong
					'description' => __( 'Course Grid, Stripe, WooCommerce, Zapier, and other official add-ons documentations.', 'learndash' ),
					'icon'        => 'addons',
				),
				'users-and-groups'    => array(
					'id'          => 'users-and-groups',
					'helpScoutId' => '',
					'label'       => __( 'Users & Groups', 'learndash' ),
                    // phpcs:ignore Generic.Files.LineLength.TooLong
					'description' => __( 'Have questions about users & groups? Our articles may help.', 'learndash' ),
					'icon'        => 'users-groups',
				),
				'reporting'           => array(
					'id'          => 'reporting',
					'helpScoutId' => '',
					'label'       => __( 'Reporting', 'learndash' ),
                    // phpcs:ignore Generic.Files.LineLength.TooLong
					'description' => __( 'LearnDash reporting guides.', 'learndash' ),
					'icon'        => 'reporting',
				),
				'user-guides'         => array(
					'id'          => 'user-guides',
					'helpScoutId' => '',
					'label'       => __( 'User Guides', 'learndash' ),
                    // phpcs:ignore Generic.Files.LineLength.TooLong
					'description' => __( 'Collection of guides that will help you accomplish certain tasks.', 'learndash' ),
					'icon'        => 'user-guides',
				),
				'troubleshooting'     => array(
					'id'          => 'troubleshooting',
					'helpScoutId' => '',
					'label'       => __( 'Troubleshooting', 'learndash' ),
                    // phpcs:ignore Generic.Files.LineLength.TooLong
					'description' => __( 'Have issues? Follow our troubleshooting guides to resolve them.', 'learndash' ),
					'icon'        => 'troubleshooting',
				),
				'faqs'                => array(
					'id'          => 'faqs',
					'helpScoutId' => '',
					'label'       => __( 'FAQs', 'learndash' ),
                    // phpcs:ignore Generic.Files.LineLength.TooLong
					'description' => __( 'Have a question? See if it\'s already been answered.', 'learndash' ),
					'icon'        => 'faqs',
				),
				'account-and-billing' => array(
					'id'          => 'account-and-billing',
					'helpScoutId' => '',
					'label'       => __( 'Accounts & Billing', 'learndash' ),
                    // phpcs:ignore Generic.Files.LineLength.TooLong
					'description' => __( 'Accounts & Billing related articles.', 'learndash' ),
					'icon'        => 'accounts-billing',
				),
			);

			return $categories;
		}

		/**
		 * Get article categories.
		 *
		 * @since 4.4.0
		 *
		 * @param array<string> $exclude_categories Category keys that will excluded in the result.
		 *
		 * @return array<string, string>
		 */
		public static function get_articles_categories( array $exclude_categories = array() ) : array {
			$categories = array(
				'additional_resources' => __( 'Additional Resources', 'learndash' ),
				'build_courses'        => __( 'Build Courses', 'learndash' ),
				'sell_courses'         => __( 'Sell Your Courses', 'learndash' ),
				'manage_students'      => __( 'Manage Students', 'learndash' ),
			);

			if ( ! empty( $exclude_categories ) ) {
				$categories = array_filter(
					$categories,
					function ( $category ) use ( $exclude_categories ) {
						return ! in_array( $category, $exclude_categories, true );
					},
					ARRAY_FILTER_USE_KEY
				);
			}

			return $categories;
		}

		/**
		 * Get selected articles.
		 *
		 * @since 4.4.0
		 *
		 * @param string        $category           Category key the returned articles are from.
		 * @param array<string> $exclude_categories Excluded category keys the returned articles are from.
		 *
		 * @return array<int, array<string, array<int, string>|string>>
		 */
		public static function get_articles( string $category = null, array $exclude_categories = array() ) : array {
			$articles = array(
				array(
					'type'       => 'youtube_video',
					'title'      => __( 'Welcome to LearnDash', 'learndash' ),
					'youtube_id' => 'hcSTaMhZi64',
					'category'   => 'overview_video',
				),
				array(
					'type'     => 'vimeo_video',
					'title'    => __( 'A Brief Overview of LearnDash', 'learndash' ),
					'vimeo_id' => '797750743',
					'category' => 'overview_article',
				),
				array(
					'type'     => 'url',
					'title'    => __( 'LearnDash 101', 'learndash' ),
					'url'      => 'https://academy.learndash.com/courses/learndash-101/',
					'category' => 'additional_resources',
				),
				array(
					'type'     => 'url',
					'title'    => __( 'WordPress 101', 'learndash' ),
					'url'      => 'https://academy.learndash.com/courses/wordpress-101/',
					'category' => 'additional_resources',
				),
				array(
					'type'     => 'helpscout_action',
					'title'    => __( 'LearnDash Documentation', 'learndash' ),
					'action'   => 'open_doc',
					'keyword'  => '',
					'category' => 'additional_resources',
				),
				array(
					'type'         => 'article',
					'title'        => __( 'Getting Started', 'learndash' ),
					'helpscout_id' => '62a0e4f0e1d2cf0eac00f2bb',
					'category'     => 'additional_resources',
				),
				array(
					'type'     => 'helpscout_action',
					'title'    => __( 'Contact Support', 'learndash' ),
					'action'   => 'open_chat',
					'keyword'  => '',
					'category' => 'additional_resources',
				),
				array(
					'type'     => 'vimeo_video',
					'title'    => __( 'Creating Courses with the Course Builder [Video]', 'learndash' ),
					'vimeo_id' => '798775119',
					'category' => 'build_courses',
				),
				array(
					'type'     => 'vimeo_video',
					'title'    => __( 'Adding Content with Lessons & Topics [Video]', 'learndash' ),
					'vimeo_id' => '798793610',
					'category' => 'build_courses',
				),
				array(
					'type'     => 'vimeo_video',
					'title'    => __( 'Creating Quizzes [Video]', 'learndash' ),
					'vimeo_id' => '799349718',
					'category' => 'build_courses',
				),
				array(
					'type'     => 'vimeo_video',
					'title'    => __( 'PayPal Settings [Video]', 'learndash' ),
					'vimeo_id' => '799333129',
					'category' => 'sell_courses',
				),
				array(
					'type'     => 'vimeo_video',
					'title'    => __( 'Stripe Integration [Video]', 'learndash' ),
					'vimeo_id' => '799333097',
					'category' => 'sell_courses',
				),
				array(
					'type'         => 'article',
					'title'        => __( 'WooCommerce Integration [Article]', 'learndash' ),
					'helpscout_id' => '6216b293aca5bb2b753c5c7f',
					'category'     => 'sell_courses',
				),
				array(
					'type'     => 'vimeo_video',
					'title'    => __( 'Course Access Settings [Video]', 'learndash' ),
					'vimeo_id' => '798788916',
					'category' => 'sell_courses',
				),
				array(
					'type'     => 'vimeo_video',
					'title'    => __( 'Setting Up User Registration [Video]', 'learndash' ),
					'vimeo_id' => '799330885',
					'category' => 'manage_students',
				),
				array(
					'type'         => 'article',
					'title'        => __( 'Adding a User Profile Page', 'learndash' ),
					'helpscout_id' => '6216c2961173d072c69fb37a',
					'category'     => 'manage_students',
				),
				array(
					'type'         => 'article',
					'title'        => __( 'LearnDash Login & Registration [Guide]', 'learndash' ),
					'helpscout_id' => '6217ffea1173d072c69fba4d',
					'category'     => 'manage_students',
				),
			);

			if ( ! empty( $category ) ) {
				$articles = array_values(
					array_filter(
						$articles,
						function ( $article ) use ( $category ) {
							return $article['category'] === $category;
						}
					)
				);
			}

			if ( ! empty( $exclude_categories ) ) {
				$articles = array_values(
					array_filter(
						$articles,
						function ( $article ) use ( $exclude_categories ) {
							return ! in_array( $article['category'], $exclude_categories, true );
						}
					)
				);
			}

			return $articles;
		}
	}
}

add_action(
	'learndash_settings_pages_init',
	function() {
		LearnDash_Settings_Page_Help::add_page_instance();
	}
);