Skip to content

Commit

Permalink
Apply code standards fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bradp committed Dec 5, 2023
1 parent 6f76277 commit 901c9ab
Show file tree
Hide file tree
Showing 31 changed files with 177 additions and 186 deletions.
9 changes: 5 additions & 4 deletions bluehost-wordpress-plugin.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php
/**
* Bluehost WordPress Plugin
* Bluehost WordPress Plugin.
*
* @package WPPluginBluehost
*
* @author Newfold Digital
* @copyright Copyright 2023 by Newfold Digital - All rights reserved.
* @license GPL-2.0-or-later
Expand Down Expand Up @@ -69,15 +70,15 @@
require_once BLUEHOST_PLUGIN_DIR . '/inc/plugin-nfd-compat-check.php';
$nfd_plugins_check = new NFD_Plugin_Compat_Check( BLUEHOST_PLUGIN_FILE );
// Defer to Incompatible plugin, self-deactivate
$nfd_plugins_check->incompatible_plugins = array();
$nfd_plugins_check->incompatible_plugins = [];
// Deactivate legacy plugin
$nfd_plugins_check->legacy_plugins = array(
$nfd_plugins_check->legacy_plugins = [
'The MOJO Marketplace' => 'mojo-marketplace-wp-plugin/mojo-marketplace.php',
'The MOJO Plugin' => 'wp-plugin-mojo/wp-plugin-mojo.php',
'The HostGator Plugin' => 'wp-plugin-hostgator/wp-plugin-hostgator.php',
'The Web.com Plugin' => 'wp-plugin-web/wp-plugin-web.php',
'The Crazy Domains Plugin' => 'wp-plugin-web/wp-plugin-crazy-domains.php',
);
];
$pass_nfd_check = $nfd_plugins_check->check_plugin_requirements();

// Check PHP version before initializing to prevent errors if plugin is incompatible.
Expand Down
28 changes: 14 additions & 14 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php
/**
* Plugin bootstrap file
* Plugin bootstrap file.
*
* @package WPPluginBluehost
*/

namespace Bluehost;

use WP_Forge\WPUpdateHandler\PluginUpdater;
use WP_Forge\UpgradeHandler\UpgradeHandler;
use NewfoldLabs\WP\ModuleLoader\Container;
use NewfoldLabs\WP\ModuleLoader\Plugin;
use WP_Forge\UpgradeHandler\UpgradeHandler;
use WP_Forge\WPUpdateHandler\PluginUpdater;
use function NewfoldLabs\WP\ModuleLoader\container as setContainer;

// Composer autoloader
Expand All @@ -28,9 +28,9 @@
* Initialize coming soon module via container
*/
$bluehost_module_container = new Container(
array(
'cache_types' => array( 'browser', 'skip404' ),
)
[
'cache_types' => [ 'browser', 'skip404' ],
]
);

// Set plugin to container
Expand All @@ -39,13 +39,13 @@
$bluehost_module_container->service(
function () {
return new Plugin(
array(
[
'id' => 'bluehost',
'file' => BLUEHOST_PLUGIN_FILE,
'brand' => get_option( 'mm_brand', 'bluehost' ),
'install_date' => get_option( 'bluehost_plugin_install_date' ),
'site_id' => \NewfoldLabs\WP\Module\CustomerBluehost\SiteMeta::get_id(),
)
]
);
}
)
Expand All @@ -57,12 +57,12 @@ function () {
);

// properly get branding links depending on market
$wordpress_hosting_page = ( get_option( 'mm_brand' ) === 'Bluehost_India' ) ? 'https://www.bluehost.in?utm_source=coming-soon-template&amp;utm_medium=bluehost_plugin' : 'https://bluehost.com?utm_source=coming-soon-template&amp;utm_medium=bluehost_plugin';
$my_panel = ( get_option( 'mm_brand' ) === 'Bluehost_India' ) ? 'https://my.bluehost.in/web-hosting/cplogin' : 'https://my.bluehost.com/web-hosting/cplogin';
$wordpress_hosting_page = ( 'Bluehost_India' === get_option( 'mm_brand' ) ) ? 'https://www.bluehost.in?utm_source=coming-soon-template&amp;utm_medium=bluehost_plugin' : 'https://bluehost.com?utm_source=coming-soon-template&amp;utm_medium=bluehost_plugin';
$my_panel = ( 'Bluehost_India' === get_option( 'mm_brand' ) ) ? 'https://my.bluehost.in/web-hosting/cplogin' : 'https://my.bluehost.com/web-hosting/cplogin';
// Set coming soon values
$bluehost_module_container->set(
'comingsoon',
array(
[
'admin_app_url' => admin_url( 'admin.php?page=bluehost#/home' ),
'template_h1' => __( 'Coming Soon!', 'wp-plugin-bluehost' ),
'template_h2' => __( 'A New WordPress Site', 'wp-plugin-bluehost' ),
Expand Down Expand Up @@ -91,22 +91,22 @@ function () {
'</a>'
),
'template_styles' => esc_url( BLUEHOST_PLUGIN_URL . 'assets/styles/coming-soon.css' ),
)
]
);
setContainer( $bluehost_module_container );

// Set up the updater endpoint and map values
$updateurl = 'https://hiive.cloud/workers/release-api/plugins/bluehost/bluehost-wordpress-plugin'; // Custom API GET endpoint
$pluginUpdater = new PluginUpdater( BLUEHOST_PLUGIN_FILE, $updateurl );
$pluginUpdater->setDataMap(
array(
[
'version' => 'version.latest',
'download_link' => 'download',
'last_updated' => 'updated',
'requires' => 'requires.wp',
'requires_php' => 'requires.php',
'tested' => 'tested.wp',
)
]
);
$pluginUpdater->setDataOverrides(
[
Expand Down
52 changes: 22 additions & 30 deletions inc/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Bluehost;

/**
* \Bluehost\Admin
* \Bluehost\Admin.
*/
final class Admin {

Expand All @@ -17,21 +17,21 @@ final class Admin {
*/
public function __construct() {
/* Add Page to WordPress Admin Menu. */
\add_action( 'admin_menu', array( __CLASS__, 'page' ) );
\add_action( 'admin_menu', [ __CLASS__, 'page' ] );
/* Load Page Scripts & Styles. */
\add_action( 'admin_enqueue_scripts', array( __CLASS__, 'assets' ) );
\add_action( 'admin_enqueue_scripts', [ __CLASS__, 'assets' ] );
/* Load i18 files */
\add_action( 'init', array( __CLASS__, 'load_text_domain' ), 100 );
\add_action( 'init', [ __CLASS__, 'load_text_domain' ], 100 );
/* Add Links to WordPress Plugins list item. */
\add_filter( 'plugin_action_links_wp-plugin-bluehost/wp-plugin-bluehost.php', array( __CLASS__, 'actions' ) );
\add_filter( 'plugin_action_links_wp-plugin-bluehost/wp-plugin-bluehost.php', [ __CLASS__, 'actions' ] );
/* Add inline style to hide subnav link */
\add_action( 'admin_head', array( __CLASS__, 'admin_nav_style' ) );
\add_action( 'admin_head', [ __CLASS__, 'admin_nav_style' ] );

\add_filter( 'newfold-runtime', array( __CLASS__, 'add_to_runtime' ) );
\add_filter( 'newfold_runtime', array( __CLASS__, 'add_to_runtime' ) );
\add_filter( 'newfold-runtime', [ __CLASS__, 'add_to_runtime' ] );
\add_filter( 'newfold_runtime', [ __CLASS__, 'add_to_runtime' ] );

if ( isset( $_GET['page'] ) && strpos( filter_input( INPUT_GET, 'page', FILTER_UNSAFE_RAW ), 'bluehost' ) >= 0 ) { // phpcs:ignore
\add_action( 'admin_footer_text', array( __CLASS__, 'add_brand_to_admin_footer' ) );
\add_action( 'admin_footer_text', [ __CLASS__, 'add_brand_to_admin_footer' ] );
}
}

Expand All @@ -56,20 +56,20 @@ public static function add_to_runtime( $sdk ) {
* @return array
*/
public static function subpages() {
return array(
return [
'bluehost#/home' => __( 'Home', 'wp-plugin-bluehost' ),
'bluehost#/store' => __( 'Store', 'wp-plugin-bluehost' ),
'bluehost#/marketplace' => __( 'Marketplace', 'wp-plugin-bluehost' ),
'bluehost#/performance' => __( 'Performance', 'wp-plugin-bluehost' ),
'bluehost#/settings' => __( 'Settings', 'wp-plugin-bluehost' ),
'bluehost#/staging' => __( 'Staging', 'wp-plugin-bluehost' ),
'bluehost#/help' => __( 'Help', 'wp-plugin-bluehost' ),
);
];
}

/**
* Add inline script to admin screens
* - hide extra link in subnav
* - hide extra link in subnav.
*/
public static function admin_nav_style() {
echo '<style>';
Expand All @@ -81,8 +81,6 @@ public static function admin_nav_style() {

/**
* Add WordPress Page to Appearance submenu.
*
* @return void
*/
public static function page() {
$bluehost_icon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiIHZpZXdCb3g9IjAgMCA0MCA0MCI+CiAgICA8cGF0aCBmaWxsPSIjYTdhYWFkIiBkPSJNNCA0aDguOTMzdjguOTIzSDRWNFptMTEuNTMgMGg4Ljk0djguOTIzaC04Ljk0VjRabTExLjUzMSAwSDM2djguOTIzaC04LjkzOVY0Wk00IDE1LjUzOGg4LjkzM3Y4LjkyNEg0di04LjkyNFptMTEuNTMgMGg4Ljk0djguOTI0aC04Ljk0di04LjkyNFptMTEuNTMxIDBIMzZ2OC45MjRoLTguOTM5di04LjkyNFpNNCAyNy4wNzdoOC45MzNWMzZINHYtOC45MjNabTExLjUzIDBoOC45NFYzNmgtOC45NHYtOC45MjNabTExLjUzMSAwSDM2VjM2aC04LjkzOXYtOC45MjNaIi8+Cjwvc3ZnPg==';
Expand All @@ -92,7 +90,7 @@ public static function page() {
__( 'Bluehost', 'wp-plugin-bluehost' ),
'manage_options',
'bluehost',
array( __CLASS__, 'render' ),
[ __CLASS__, 'render' ],
$bluehost_icon,
0
);
Expand All @@ -106,16 +104,14 @@ public static function page() {
$title,
'manage_options',
$route,
array( __CLASS__, 'render' )
[ __CLASS__, 'render' ]
);
}
}
}

/**
* Render DOM element for React to load onto.
*
* @return void
*/
public static function render() {
global $wp_version;
Expand Down Expand Up @@ -144,8 +140,6 @@ public static function render() {
* Load Page Scripts & Styles.
*
* @param string $hook Page hook.
*
* @return void
*/
public static function assets( $hook ) {

Expand All @@ -163,7 +157,7 @@ public static function assets( $hook ) {
\wp_register_script(
'bluehost-script',
BLUEHOST_BUILD_URL . '/index.js',
array_merge( $asset['dependencies'], array( 'nfd-runtime' ) ),
array_merge( $asset['dependencies'], [ 'nfd-runtime' ] ),
$asset['version'],
true
);
Expand All @@ -177,7 +171,7 @@ public static function assets( $hook ) {
\wp_register_style(
'bluehost-style',
BLUEHOST_BUILD_URL . '/index.css',
array( 'wp-components' ),
[ 'wp-components' ],
$asset['version']
);

Expand All @@ -193,18 +187,16 @@ public static function assets( $hook ) {
\wp_localize_script(
'newfold-plugin',
'nfdplugin',
array(
[
'restApiUrl' => \esc_url_raw( \get_home_url() . '/index.php?rest_route=' ),
'restApiNonce' => \wp_create_nonce( 'wp_rest' ),
)
]
);
\wp_enqueue_script( 'newfold-plugin' );
}

/**
* Load text domain for plugin
*
* @return void
* Load text domain for plugin.
*/
public static function load_text_domain() {

Expand All @@ -230,16 +222,16 @@ public static function load_text_domain() {
*/
public static function actions( $actions ) {
return array_merge(
array(
[
'overview' => '<a href="' . \admin_url( 'admin.php?page=bluehost#/home' ) . '">' . __( 'Home', 'wp-plugin-bluehost' ) . '</a>',
'settings' => '<a href="' . \admin_url( 'admin.php?page=bluehost#/settings' ) . '">' . __( 'Settings', 'wp-plugin-bluehost' ) . '</a>',
),
],
$actions
);
}

/**
* Filter WordPress Admin Footer Text "Thank you for creating with..."
* Filter WordPress Admin Footer Text "Thank you for creating with...".
*
* @param string $footer_text footer text
*
Expand Down
11 changes: 5 additions & 6 deletions inc/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,22 @@
*/
final class Data {


/**
* Data loaded onto window.NewfoldRuntime
* Data loaded onto window.NewfoldRuntime.
*
* @return array
*/
public static function runtime() {
global $bluehost_module_container;

$runtime = array(
'plugin' => array(
$runtime = [
'plugin' => [
'url' => BLUEHOST_BUILD_URL,
'version' => BLUEHOST_PLUGIN_VERSION,
'assets' => BLUEHOST_PLUGIN_URL . 'assets/',
'brand' => $bluehost_module_container->plugin()->brand,
),
);
],
];

return $runtime;
}
Expand Down
12 changes: 6 additions & 6 deletions inc/LoginRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Bluehost;

/**
* Class LoginRedirect
* Class LoginRedirect.
*
* @package Bluehost
*/
Expand All @@ -13,11 +13,11 @@ class LoginRedirect {
* Initialize the login redirect functionality.
*/
public static function init() {
add_action( 'login_redirect', array( __CLASS__, 'on_login_redirect' ), 10, 3 );
add_action( 'login_init', array( __CLASS__, 'on_login_init' ), 10, 3 );
add_action( 'admin_init', array( __CLASS__, 'disable_yoast_onboarding_redirect' ), 2 );
add_filter( 'login_form_defaults', array( __CLASS__, 'filter_login_form_defaults' ) );
add_filter( 'newfold_sso_success_url_default', array( __CLASS__, 'get_default_redirect_url' ) );
add_action( 'login_redirect', [ __CLASS__, 'on_login_redirect' ], 10, 3 );
add_action( 'login_init', [ __CLASS__, 'on_login_init' ], 10, 3 );
add_action( 'admin_init', [ __CLASS__, 'disable_yoast_onboarding_redirect' ], 2 );
add_filter( 'login_form_defaults', [ __CLASS__, 'filter_login_form_defaults' ] );
add_filter( 'newfold_sso_success_url_default', [ __CLASS__, 'get_default_redirect_url' ] );
}

/**
Expand Down
Loading

0 comments on commit 901c9ab

Please sign in to comment.