content = ''; $response->status = Response::STATUS_SUCCESS; try { // Check permission if ( ! current_user_can( UserModel::ROLE_ADMINISTRATOR ) ) { throw new Exception( __( 'You do not have permission to perform this action.', 'learnpress' ) ); } $notices = [ self::html_check_wp_remote( $data ), self::html_check_plugin_base( $data ), self::html_lp_upgrade_db( $data ), self::html_lp_permalink( $data ), self::html_lp_setup_wizard( $data ), self::html_lp_addons_new_version( $data ), self::html_addons_need_extend( $data ), self::html_lp_beta_version( $data ), ]; $response->content = implode( '', array_filter( $notices ) ); } catch ( Throwable $exception ) { $response->status = Response::STATUS_ERROR; $response->content = Template::print_message( $exception->getMessage(), Response::STATUS_ERROR, false ); } return $response; } /** * Render a notice when wp_remote_get is unavailable. * * @param array $data Request arguments. * * @return string */ public static function html_check_wp_remote( array $data = [] ): string { $result = AdminNoticeService::check_wp_remote(); if ( ! is_wp_error( $result ) ) { return ''; } $message = sprintf( '
%s
', sprintf( 'wp_remote: %s. %s', $result->get_error_message(), esc_url( admin_url( 'site-health.php' ) ), esc_html__( 'Check Site Health', 'learnpress' ) ) ); return Template::print_message( $message, 'error', false ); } /** * Render a notice when the LearnPress plugin base directory is wrong. * * @param array $data Request arguments. * * @return string */ public static function html_check_plugin_base( array $data = [] ): string { if ( ! AdminNoticeService::check_plugin_base() ) { return ''; } $message = sprintf( '
%s
', sprintf( /* translators: 1: expected plugin basename wrapped in strong, 2: current plugin basename wrapped in strong */ __( 'The LearnPress plugin base directory must be %1$s (case-sensitive) to ensure all functions work properly and are fully operational (currently %2$s).', 'learnpress' ), 'learnpress/learnpress.php', '' . LP_PLUGIN_BASENAME . '' ) ); return Template::print_message( $message, 'warning', false ); } /** * Render a notice to upgrade the LearnPress database. * * @param array $data Request arguments. * * @return string */ public static function html_lp_upgrade_db( array $data = [] ): string { if ( ! LP_Updater::instance()->check_lp_db_need_upgrade() ) { return ''; } $message = sprintf( '
%s
', sprintf( '%s
%s
', __( 'LearnPress update – We need to update your database to the latest version.', 'learnpress' ), admin_url( 'admin.php?page=learn-press-tools&tab=database&action=upgrade-db' ), esc_html__( 'Go to Update', 'learnpress' ) ) ); return Template::print_message( $message, 'warning', false ); } /** * Render a notice when permalink structure is not enabled. * * @param array $data Request arguments. * * @return string */ public static function html_lp_permalink( array $data = [] ): string { $permalink_structure = get_option( 'permalink_structure' ); if ( ! empty( $permalink_structure ) ) { return ''; } $message = sprintf( '
%s
', sprintf( 'LearnPress requires permalink option Post name is enabled. Please enable it here to ensure that all functions work properly.', admin_url( 'options-permalink.php' ) ) ); return Template::print_message( $message, 'warning', false ); } /** * Render a notice to run the LearnPress setup wizard. * * @param array $data Request arguments. * * @return string */ public static function html_lp_setup_wizard( array $data = [] ): string { if ( get_option( 'learn_press_setup_wizard_completed', false ) || LP_Settings::is_admin_notice_dismissed( 'lp-setup-wizard' ) ) { return ''; } $message = sprintf( '
%s
', sprintf( '%s%s%s

', __( 'LearnPress LMS is ready to set up', 'learnpress' ), admin_url( 'index.php?page=lp-setup' ), __( 'Quick Setup', 'learnpress' ), self::html_button_dismiss( 'lp-setup-wizard' ) ) ); return Template::print_message( $message, 'success', false ); } /** * Render a notice for new versions of LearnPress add-ons. * * @param array $data Request arguments. * * @return string */ public static function html_lp_addons_new_version( array $data = [] ): string { /*if ( LP_Settings::is_admin_notice_dismissed( 'lp-addons-new-version' ) ) { return ''; }*/ $addons = AddonService::instance()->list_addon_new_version(); if ( empty( $addons ) ) { return ''; } $addons_html_arr = []; foreach ( $addons as $addon ) { $addons_html_arr[] = sprintf( '%s', admin_url( 'admin.php?page=learn-press-addons&tab=update' ), $addon->name ); } $addons_html = implode( ', ', $addons_html_arr ); $message = sprintf( '
%s
', count( $addons ), sprintf( '%s: %s', __( 'New version available', 'learnpress' ), $addons_html ) ); return Template::print_message( $message, 'info', false ); } /** * Render add-on licenses need extend notice. * * @param array $data Request arguments. * * @return string * @since 4.4.9 * @version 1.0.0 */ public static function html_addons_need_extend( array $data = [] ): string { if ( LP_Settings::is_admin_notice_dismissed( 'lp-addons-purchased-extend' ) || ! AddonService::instance()->check_addons_purchased_need_extend() ) { return ''; } $message = sprintf( '
%s
', sprintf( '%1$s %3$s%4$s', esc_html__( 'You have LearnPress Add-on licenses that need to be extended.', 'learnpress' ), esc_url( admin_url( 'admin.php?page=learn-press-addons&tab=license' ) ), esc_html__( 'Check now!', 'learnpress' ), self::html_button_dismiss( 'lp-addons-purchased-extend' ) ) ); return Template::print_message( $message, 'info', false ); } /** * Render a notice for a new LearnPress beta version. * * @param array $data Request arguments. * * @return string */ public static function html_lp_beta_version( array $data = [] ): string { $lp_beta_version_info = AdminNoticeService::check_lp_beta_version(); if ( ! $lp_beta_version_info instanceof stdClass ) { return ''; } $admin_notices_dismiss = get_option( 'lp_admin_notices_dismiss', [] ); if ( isset( $admin_notices_dismiss['lp-beta-version'] ) || ! AddonService::instance()->check_addons_purchased_need_extend() ) { return ''; } $version = $lp_beta_version_info->version ?? ''; $link_download = $lp_beta_version_info->link_download ?? ''; $link_feedback = $lp_beta_version_info->link_feedback ?? ''; $link_changelog = $lp_beta_version_info->link_changelog ?? ''; $description = __( 'This version of the LearnPress software is under development. Please do not install, run, or test this version of LearnPress on production or mission-critical websites. Instead, it is recommended that you test Beta version on a staging site.', 'learnpress' ); $title = sprintf( /* translators: %s: beta version number */ __( 'LearnPress %s Beta is available', 'learnpress' ), esc_html( $version ) ); $message = sprintf( '
%s
', sprintf( '

%1$s

%2$s

%4$s %6$s %8$s

%9$s', esc_html( $title ), esc_html( $description ), esc_url( $link_download ), __( 'Download', 'learnpress' ), esc_url( $link_feedback ), __( 'Feedback', 'learnpress' ), esc_url( $link_changelog ), __( 'Changelog', 'learnpress' ), self::html_button_dismiss( 'lp-beta-version' ) ) ); return Template::print_message( $message, 'info', false ); } /** * Render a dismiss button for a notice. * * @param string $key Notice key. * * @return string */ public static function html_button_dismiss( string $key ): string { $data_send = wp_json_encode( array( 'args' => array( 'dismiss' => $key ), /** @use self::dismiss_notice */ 'callback' => array( 'class' => AdminNotesTemplate::class, 'method' => 'dismiss_notice', ), ) ); return sprintf( ' ', esc_attr( $key ), esc_attr( $data_send ), esc_attr__( 'Are you sure you want to dismiss this notice?', 'learnpress' ), esc_attr__( 'Dismiss notice', 'learnpress' ) ); } /** * Dismiss an admin notice. * * @param array $data Request arguments. * * @return stdClass */ public static function dismiss_notice( array $data = [] ): stdClass { $content = new stdClass(); $content->content = ''; $content->status = Response::STATUS_SUCCESS; $content->message = ''; try { if ( ! current_user_can( UserModel::ROLE_ADMINISTRATOR ) ) { throw new Exception( __( 'You do not have permission to perform this action.', 'learnpress' ) ); } $key = sanitize_key( $data['dismiss'] ?? '' ); if ( empty( $key ) ) { throw new Exception( __( 'The notice key is invalid.', 'learnpress' ) ); } $admin_notices_dismiss = LP_Settings::get_admin_notices_dismiss(); $admin_notices_dismiss[ $key ] = $key; update_option( 'lp_admin_notices_dismiss', $admin_notices_dismiss ); $content->message = __( 'Note Dismissed!', 'learnpress' ); } catch ( Throwable $exception ) { $content->status = Response::STATUS_ERROR; $content->message = $exception->getMessage(); } return $content; } }