Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
},
"minimum-stability": "dev",
"require": {
"codeinwp/themeisle-sdk": "^3.3.65",
"codeinwp/themeisle-sdk": "^3.3.70",
"tubalmartin/cssmin": "^4.1",
"wptt/webfont-loader": "^1.1",
"sabberworm/php-css-parser": "^8.4",
Expand Down
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions otter-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,47 @@ function () {
}
);

/*
* Opts into the SDK Support Hub: one Help button on Otter's screens and the
* deactivation window. The dashboard and Form Submissions screens already fire
* `themeisle_internal_page`, so no `pages` list is needed.
*/
add_filter(
'otter_blocks_support_hub_metadata',
function () {
return array(
// The SDK reads this while loading Otter, before Otter Pro's Licenser adds the
// product_otter_license_status filter, so read the stored license directly.
'is_pro' => defined( 'OTTER_PRO_BASEFILE' ) && class_exists( '\ThemeisleSDK\Modules\Licenser' ) && \ThemeisleSDK\Modules\Licenser::is_valid( OTTER_PRO_BASEFILE ),
'links' => array(
array(
'icon' => 'book-alt',
'text' => __( 'Documentation', 'otter-blocks' ),
'url' => \ThemeIsle\GutenbergBlocks\Pro::get_docs_url(),
),
array(
'icon' => 'groups',
'text' => __( 'Community Forum', 'otter-blocks' ),
'url' => 'https://wordpress.org/support/plugin/otter-blocks/',
),
),
);
}
);

/*
* Otter also fires `themeisle_internal_page` in the block editor, which would put
* the Help button on every post, site and widget editor. Keep it to Otter's screens.
*/
add_filter(
'otter_blocks_hide_support_hub',
function ( $hide ) {
global $pagenow;

return $hide || in_array( $pagenow, array( 'post.php', 'post-new.php', 'site-editor.php', 'widgets.php' ), true );
}
);

add_filter(
'themeisle_sdk_compatibilities/' . basename( OTTER_BLOCKS_PATH ),
function ( $compatibilities ) {
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ Sure, Otter is compatible with any WordPress theme.

### Where can I get help? ###

If you encounter any difficulties or if you have questions about Otter, you can create a ticket on our [support forum](https://wordpress.org/support/plugin/otter-blocks/). Also, feel free to check our [documentation](https://docs.themeisle.com/article/1478-otter-blocks-documentation) to find out more about the features within the plugin and how to use it to its full potential.
If you encounter any difficulties or if you have questions about Otter, you can ask our support team from the **Help** button on the Otter dashboard, or create a ticket on our [support forum](https://wordpress.org/support/plugin/otter-blocks/). Also, feel free to check our [documentation](https://docs.themeisle.com/article/1478-otter-blocks-documentation) to find out more about the features within the plugin and how to use it to its full potential.

### What are the Patterns and how can I use them? ###

Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ Sure, Otter is compatible with any WordPress theme.

= Where can I get help? =

If you encounter any difficulties or if you have questions about Otter, you can create a ticket on our [support forum](https://wordpress.org/support/plugin/otter-blocks/). Also, feel free to check our [documentation](https://docs.themeisle.com/article/1478-otter-blocks-documentation) to find out more about the features within the plugin and how to use it to its full potential.
If you encounter any difficulties or if you have questions about Otter, you can ask our support team from the **Help** button on the Otter dashboard, or create a ticket on our [support forum](https://wordpress.org/support/plugin/otter-blocks/). Also, feel free to check our [documentation](https://docs.themeisle.com/article/1478-otter-blocks-documentation) to find out more about the features within the plugin and how to use it to its full potential.

= What are the Patterns and how can I use them? =

Expand Down
34 changes: 34 additions & 0 deletions src/blocks/test/e2e/blocks/dashboard.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,38 @@ test.describe( 'Dashboard', () => {
await countdownCard.getByRole( 'checkbox' ).click();
await expect( countdownCard.getByRole( 'checkbox' ) ).toBeChecked();
});

test( 'free sidebar opens the Help panel and keeps the community forum', async({ admin, otterUtils, page }) => {
// Global setup stubs a valid Pro license, which shows Contact Pro Support instead.
await otterUtils.deactivatePro();

try {
await admin.visitAdminPage( 'admin.php?page=otter' );

const contact = page.locator( '.otter-info-links' ).getByRole( 'link', { name: 'Contact Support' });

await expect( contact ).toHaveAttribute( 'data-ti-support', 'dashboard' );
await expect( page.locator( '.otter-info-links' ).getByRole( 'link', { name: 'Community Forum' }) ).toHaveAttribute( 'href', 'https://wordpress.org/support/plugin/otter-blocks/' );

await contact.click();

await expect( page.locator( '.ti-support-panel' ) ).toBeVisible();
} finally {
await otterUtils.activatePro();
}
});

test( 'licensed Pro sidebar keeps Contact Pro Support', async({ page }) => {
await expect( page.locator( '.otter-info-links' ).getByRole( 'link', { name: 'Contact Pro Support' }) ).toHaveAttribute( 'href', 'https://store.themeisle.com/' );
await expect( page.locator( '.otter-info-links' ).getByRole( 'link', { name: 'Contact Support' }) ).toHaveCount( 0 );
});

test( 'Help launcher shows on the dashboard but not in the block editor', async({ admin, page }) => {
await expect( page.locator( '.ti-support-launcher' ) ).toBeVisible();

await admin.createNewPost();

// The SDK prints this container in admin_footer whenever the hub loads.
await expect( page.locator( '#ti-support-hub' ) ).toHaveCount( 0 );
});
});
14 changes: 10 additions & 4 deletions src/dashboard/components/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ const Sidebar = ({
setTab
}) => {
const isProLicenseActive = Boolean( window.otterObj.hasPro ) && 'valid' === window.otterObj?.license?.valid;

const supportLink = isProLicenseActive ? 'https://store.themeisle.com/' : 'https://wordpress.org/support/plugin/otter-blocks';
const supportLabel = isProLicenseActive ? __( 'Contact Pro Support', 'otter-blocks' ) : __( 'Support', 'otter-blocks' );
const forumLink = 'https://wordpress.org/support/plugin/otter-blocks/';

return (
<Fragment>
Expand Down Expand Up @@ -122,7 +120,15 @@ const Sidebar = ({
title={ __( 'Useful links', 'otter-blocks' ) }
>
<ul className="otter-info-links">
<li><a href={ supportLink } target="_blank" rel="noreferrer">{ supportLabel }</a></li>
{ isProLicenseActive ? (
<li><a href="https://store.themeisle.com/" target="_blank" rel="noreferrer">{ __( 'Contact Pro Support', 'otter-blocks' ) }</a></li>
) : (
<Fragment>
{ /* The SDK Support Hub opens its Help panel for [data-ti-support] links; without it, the link opens the forum. */ }
<li><a href={ forumLink } target="_blank" rel="noreferrer" data-ti-support="dashboard">{ __( 'Contact Support', 'otter-blocks' ) }</a></li>
<li><a href={ forumLink } target="_blank" rel="noreferrer">{ __( 'Community Forum', 'otter-blocks' ) }</a></li>
</Fragment>
) }
<li><a href="https://github.com/Codeinwp/otter-blocks/discussions" target="_blank" rel="noreferrer">{ __( 'Feature request', 'otter-blocks' ) }</a></li>
<li><a href="https://wordpress.org/support/plugin/otter-blocks/reviews/#new-post" target="_blank" rel="noreferrer">{ __( 'Leave a review', 'otter-blocks' ) }</a></li>
</ul>
Expand Down
94 changes: 94 additions & 0 deletions tests/test-support-hub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
/**
* Tests for the metadata Otter hands to the Themeisle SDK Support Hub.
*
* @package gutenberg-blocks
*/

/**
* Support Hub opt-in tests.
*/
class Test_Support_Hub extends WP_UnitTestCase {

/**
* The filter returns the keys Otter opts into, and nothing else.
*/
public function test_metadata_has_the_agreed_keys() {
$data = apply_filters( 'otter_blocks_support_hub_metadata', array() );

$this->assertIsArray( $data );
$this->assertSame( array( 'is_pro', 'links' ), array_keys( $data ) );
}

/**
* The footer links point to Otter's docs and wordpress.org forum.
*/
public function test_links_point_to_otter() {
$links = apply_filters( 'otter_blocks_support_hub_metadata', array() )['links'];

$this->assertSame(
array(
'https://docs.themeisle.com/otter-page-builder-blocks-extensions/otter-blocks-documentation',
'https://wordpress.org/support/plugin/otter-blocks/',
),
wp_list_pluck( $links, 'url' )
);
foreach ( $links as $link ) {
$this->assertNotEmpty( $link['icon'] );
$this->assertNotEmpty( $link['text'] );
}
}

/**
* Messages are tagged as Pro only while the stored Pro license is valid, whatever
* the order in which the SDK loads Otter and Otter Pro.
*/
public function test_is_pro_reads_the_stored_pro_license() {
if ( ! defined( 'OTTER_PRO_BASEFILE' ) ) {
define( 'OTTER_PRO_BASEFILE', dirname( __DIR__ ) . '/plugins/otter-pro/otter-pro.php' );
}
// The test bootstrap loads Composer before WordPress, so the SDK's load.php skips itself.
$sdk = dirname( __DIR__ ) . '/vendor/codeinwp/themeisle-sdk/src/';
foreach ( array( 'Loader.php', 'Product.php', 'Common/Abstract_module.php', 'Modules/Licenser.php' ) as $file ) {
require_once $sdk . $file;
}
// No Licenser filter is registered, as when Otter loads before Otter Pro.
remove_all_filters( 'product_otter_license_status' );

update_option( 'otter_pro_license_data', (object) array( 'license' => 'expired' ) );
$this->assertFalse( apply_filters( 'otter_blocks_support_hub_metadata', array() )['is_pro'] );

update_option( 'otter_pro_license_data', (object) array( 'license' => 'valid' ) );
$this->assertTrue( apply_filters( 'otter_blocks_support_hub_metadata', array() )['is_pro'] );
}

/**
* The Help button stays off the block editors, which also count as Otter screens, and shows on Otter's own screens.
*
* @dataProvider admin_screens
*
* @param string $pagenow Admin page file.
* @param bool $hidden Whether the Help button is hidden there.
*/
public function test_hub_is_hidden_only_in_block_editors( $pagenow, $hidden ) {
$GLOBALS['pagenow'] = $pagenow; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited

$this->assertSame( $hidden, apply_filters( 'otter_blocks_hide_support_hub', false ) );
}

/**
* Admin pages and whether the Help button is hidden on them.
*
* @return array<string, array{0: string, 1: bool}>
*/
public function admin_screens() {
return array(
'post editor' => array( 'post.php', true ),
'new post' => array( 'post-new.php', true ),
'site editor' => array( 'site-editor.php', true ),
'widget editor' => array( 'widgets.php', true ),
'Otter screen' => array( 'admin.php', false ),
'post list' => array( 'edit.php', false ),
);
}
}
Loading