Skip to content

Function

Add contextual help to settings pages.

tml_admin_add_settings_help_tabs( $screen )

Parameters

$screen
$srceen WP_Screen
The current screen object.

Source

function tml_admin_add_settings_help_tabs( $screen ) {
    global $plugin_page;

    $help_tabs     = array();
    $sidebar_links = array();

    if ( empty( $plugin_page ) || ! theme_my_login_admin()->has_page( $plugin_page ) ) {
        return;
    }

    // Core page
    if ( 'theme-my-login' === $plugin_page ) {
        $help_tabs['overview'] = array(
            'id'      => 'theme-my-login-overview',
            'title'   => __( 'Overview' ), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- reusing WP core's translated "Overview" string, not a TML-specific string.
            'content' => '<p>' . implode(
                '</p><p>',
                array(
                    __( 'Welcome to Theme My Login!', 'theme-my-login' ),
                    __( 'Below, you can configure how you would like users to register and log in to your site.', 'theme-my-login' ),
                    __( 'Additionally, you can change the slugs that are used to generate the URLs that represent specific actions.', 'theme-my-login' ),
                    __( 'You must click the Save Changes button at the bottom of the screen for new settings to take effect.' ), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- reusing WP core's translated string (see wp-admin/options-general.php), not a TML-specific string.
                )
            ) . '</p>',
        );

        $sidebar_links['documentation'] = array(
            'title' => __( 'View Documentation', 'theme-my-login' ),
            'url'   => 'https://docs.thememylogin.com',
        );

        $sidebar_links['support'] = array(
            'title' => __( 'Get Support', 'theme-my-login' ),
            'url'   => 'https://wordpress.org/support/plugin/theme-my-login',
        );

        // Licenses page
    } elseif ( 'theme-my-login-licenses' === $plugin_page ) {
        $help_tabs['overview'] = array(
            'id'      => 'theme-my-login-licenses-overview',
            'title'   => __( 'Overview' ), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- reusing WP core's translated "Overview" string, not a TML-specific string.
            'content' => '<p>' . implode(
                '</p><p>',
                array(
                    __( 'When you purchase extensions for Theme My Login, you will enter your license keys on this page.', 'theme-my-login' ),
                    __( 'After you enter your license keys and click the Save Changes button at the bottom of the screen, you will see a new button next to each field with a license in it.', 'theme-my-login' ),
                    __( 'If you have not yet activated your license, this button will say "Activate". Click this button to activate your license.', 'theme-my-login' ),
                    __( 'If you have already activated your license, this button will say "Deactivate". Click this button to deactivate your license.', 'theme-my-login' ),
                )
            ) . '</p>',
        );

        $sidebar_links['documentation'] = array(
            'title' => __( 'View Documentation', 'theme-my-login' ),
            'url'   => 'https://docs.thememylogin.com/article/59-how-do-i-install-an-extension',
        );
        $sidebar_links['support']       = array(
            'title' => __( 'Get Support', 'theme-my-login' ),
            'url'   => 'https://thememylogin.com/support',
        );

        // Extensions page
    } elseif ( 'theme-my-login-extensions' === $plugin_page ) {
        $help_tabs['overview'] = array(
            'id'      => 'theme-my-login-extensions-overview',
            'title'   => __( 'Overview' ), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- reusing WP core's translated "Overview" string, not a TML-specific string.
            'content' => '<p>' . implode(
                '</p><p>',
                array(
                    __( 'This page shows you all of the extensions available to purchase for Theme My Login.', 'theme-my-login' ),
                    __( 'Once you purchase an extension, you download it from your email receipt or your account page on our website. Then, you install it just like a normal WordPress plugin.', 'theme-my-login' ),
                )
            ) . '</p>',
        );

        $sidebar_links['documentation'] = array(
            'title' => __( 'View Documentation', 'theme-my-login' ),
            'url'   => 'https://docs.thememylogin.com/article/59-how-do-i-install-an-extension',
        );
        $sidebar_links['store']         = array(
            'title' => __( 'Go to the Extensions Store', 'theme-my-login' ),
            'url'   => 'https://thememylogin.com/extensions',
        );
        $sidebar_links['account']       = array(
            'title' => __( 'View your Theme My Login account', 'theme-my-login' ),
            'url'   => 'https://thememylogin.com/your-account',
        );

        // Extension page
    } else {
        $extension = tml_get_extension( $plugin_page );
    }

    if ( ! empty( $extension ) ) {
        $help_tabs['overview'] = array(
            'id'      => $plugin_page . '-overview',
            'title'   => __( 'Overview' ), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- reusing WP core's translated "Overview" string, not a TML-specific string.
            'content' => '<p>' . implode(
                '</p><p>',
                array(
                    sprintf(
                        /* translators: %s: The extension title. */
                        __( 'On this page, you can configure the settings for the Theme My Login %s extension.', 'theme-my-login' ),
                        $extension->get_title()
                    ),
                    // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- reusing WP core's translated string (see wp-admin/options-general.php), not a TML-specific string.
                    __( 'You must click the Save Changes button at the bottom of the screen for new settings to take effect.' ),
                )
            ) . '</p>',
        );

        $documentation_url = $extension->get_documentation_url();
        if ( $documentation_url ) {
            $sidebar_links['documentation'] = array(
                'title' => __( 'View Documentation', 'theme-my-login' ),
                'url'   => $documentation_url,
            );
        }

        $support_url = $extension->get_support_url();
        if ( $support_url ) {
            $sidebar_links['support'] = array(
                'title' => __( 'Get Support', 'theme-my-login' ),
                'url'   => $support_url,
            );
        }

        $settings_page = $extension->get_settings_page_args();
        if ( ! empty( $settings_page['help_tabs'] ) ) {
            $help_tabs = array_merge( $help_tabs, $settings_page['help_tabs'] );
        }
        if ( ! empty( $settings_page['help_sidebar_links'] ) ) {
            $sidebar_links = array_merge( $sidebar_links, $settings_page['help_sidebar_links'] );
        }
    }

    // Add the help tabs
    if ( ! empty( $help_tabs ) ) {
        foreach ( $help_tabs as $help_tab ) {
            $screen->add_help_tab( $help_tab );
        }
    }

    // Add the sidebar links
    if ( ! empty( $sidebar_links ) ) {
        $sidebar_content = '<p><strong>' . __( 'For more information:' ) . '</strong></p>'; // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- reusing WP core's translated "For more information:" string, not a TML-specific string.
        foreach ( $sidebar_links as $sidebar_link ) {
            $sidebar_content .= sprintf(
                '<p><a href="%s">%s</a></p>',
                $sidebar_link['url'],
                $sidebar_link['title']
            );
        }
        $screen->set_help_sidebar( $sidebar_content );
    }
}

Uses

Changelog

VersionDescription
7.0.5 Introduced.