Skip to content

Commit

Permalink
Merge pull request #39 from newfold-labs/dynamic-resource-link
Browse files Browse the repository at this point in the history
making the resource link dynamic
  • Loading branch information
circlecube authored Jan 12, 2024
2 parents 91d6267 + 17b3830 commit 43a6142
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 16 deletions.
5 changes: 2 additions & 3 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use NewfoldLabs\WP\Module\HelpCenter\HelpCenter;
use NewfoldLabs\WP\ModuleLoader\Container;
use NewfoldLabs\WP\Module\HelpCenter\Data\Brands;
use function NewfoldLabs\WP\ModuleLoader\register;

if ( function_exists( 'add_action' ) ) {
Expand Down Expand Up @@ -33,9 +34,7 @@ function () {
new HelpCenter( $container );

// Define the brand
if ( ! defined( 'NFD_HELPCENTER_PLUGIN_BRAND' ) ) {
define( 'NFD_HELPCENTER_PLUGIN_BRAND', $container->plugin()->brand );
}
Brands::set_current_brand( $container );
},
'isActive' => true,
'isHidden' => true,
Expand Down
2 changes: 1 addition & 1 deletion build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'react', 'wp-api-fetch', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-polyfill'), 'version' => '47871efacaa34562e3f9');
<?php return array('dependencies' => array('lodash', 'react', 'wp-api-fetch', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-polyfill'), 'version' => '14909b5dc8e12284ee9c');
2 changes: 1 addition & 1 deletion build/index.js

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions includes/Data/Brands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace NewfoldLabs\WP\Module\HelpCenter\Data;

/**
* Contains Brand information.
*/
final class Brands
{

/**
* Brand specific data - Bluehost, HostGator
*
* @return array
*/
public static function get_brands()
{
return array(
'bluehost' => array(
'brand' => 'bluehost',
'name' => 'Bluehost',
'url' => 'https://bluehost.com',
'helpURL' => 'https://www.bluehost.com/help',
),
'hostgator-us' => array(
'brand' => 'hostgator',
'name' => 'HostGator',
'url' => 'https://www.hostgator.com',
'helpUrl' => 'https://www.hostgator.com/help',
),
'hostgator-br' => array(
'brand' => 'hostgator-br',
'name' => 'HostGator',
'url' => 'https://www.hostgator.com.br',
'helpUrl' => 'https://suporte.hostgator.com.br/hc/pt-br',
),
);
}

/**
* Sets the hosting brand.
*
* @param object $container The brand plugin container.
*/
public static function set_current_brand( $container ) {
if ( ! defined('NFD_HELPCENTER_PLUGIN_BRAND') ) {
$brand = $container->plugin()->brand;
if (empty($brand)) {
$brand = 'wordpress';
}

if (false !== strpos($brand, 'hostgator')) {
$region = strtolower($container->plugin()->region);
$brand = "hostgator-{$region}";
}

$brand = sanitize_title_with_dashes(str_replace('_', '-', $brand));

define('NFD_HELPCENTER_PLUGIN_BRAND', $brand);
}
}

/**
* Returns the resource link.
*
* @param string $brand_name The brand name for which the link is to be fetched.
* @return string
*/
public static function get_resource_link_for_brand( $brand_name ) {
$brands = self::get_brands();
if ( isset( $brands[ $brand_name ][ 'helpURL' ] ) ) {
return $brands[ $brand_name ][ 'helpURL' ];
}
return '';
}
}
10 changes: 8 additions & 2 deletions includes/HelpCenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use NewfoldLabs\WP\Module\HelpCenter\I18nLoader;
use NewfoldLabs\WP\ModuleLoader\Container;
use NewfoldLabs\WP\Module\HelpCenter\Data\Brands;

/**
* The class to initialize and load the module.
Expand Down Expand Up @@ -115,12 +116,17 @@ public function register_assets() {
\wp_enqueue_style(
'stylesheet',
NFD_HELPCENTER_PLUGIN_URL . 'vendor/newfold-labs/wp-module-help-center/build/index.css',
null, '1', 'screen'
array(), '1', 'screen'
);

\wp_add_inline_script(
self::$slug,
'var nfdHelpCenter =' . wp_json_encode( array( 'restUrl' => \get_home_url() . '/index.php?rest_route=', ) ) . ';',
'var nfdHelpCenter =' . wp_json_encode(
array(
'restUrl' => \get_home_url() . '/index.php?rest_route=',
'resourceLink' => Brands::get_resource_link_for_brand( NFD_HELPCENTER_PLUGIN_BRAND )
)
) . ';',
'before'
);
}
Expand Down
11 changes: 2 additions & 9 deletions src/components/NoResults.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { __ } from '@wordpress/i18n';
import { ReactComponent as NoResultIllustration } from '../icons/no-result.svg';
import ResourceLink from './ResourceLink';

const NoResults = () => {
return (
Expand All @@ -24,15 +25,7 @@ const NoResults = () => {
'wp-module-help-center'
) }
</p>
<p>
{ __(
'In the meantime, try searching our',
'wp-module-help-center'
) }{ ' ' }
<a href="https://www.bluehost.com/help">
{ __( 'Resource center.', 'wp-module-help-center' ) }
</a>
</p>
<ResourceLink />
<hr />
</div>
);
Expand Down
19 changes: 19 additions & 0 deletions src/components/ResourceLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { __ } from '@wordpress/i18n';

const ResourceLink = () => {
if ( window?.nfdHelpCenter?.resourceLink ) {
return (
<p>
{ __(
'In the meantime, try searching our',
'wp-module-help-center'
) }{ ' ' }
<a href={ window?.nfdHelpCenter?.resourceLink }>
{ __( 'Resource center.', 'wp-module-help-center' ) }
</a>
</p>
);
}
};

export default ResourceLink;

0 comments on commit 43a6142

Please sign in to comment.