Skip to content

Commit

Permalink
Clean up plugin code to pass phpcs checks
Browse files Browse the repository at this point in the history
  • Loading branch information
bradp committed Dec 5, 2023
1 parent a54adc5 commit 04bb07f
Show file tree
Hide file tree
Showing 21 changed files with 152 additions and 143 deletions.
4 changes: 2 additions & 2 deletions bluehost-wordpress-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@
'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();
$pass_nfd_check = $nfd_plugins_check->check_plugin_requirements();

// Check PHP version before initializing to prevent errors if plugin is incompatible.
if ( $pass_nfd_check && version_compare( PHP_VERSION, '5.3', '>=' ) ) {
require dirname( __FILE__ ) . '/bootstrap.php';
require __DIR__ . '/bootstrap.php';
}
11 changes: 10 additions & 1 deletion inc/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ public function __construct() {
}
}

/**
* Add Bluehost data to runtime.
*
* @param array $sdk - array of data to be passed to runtime.
*
* @return array
*/
public static function add_to_runtime( $sdk ) {
include_once BLUEHOST_PLUGIN_DIR . '/inc/Data.php';

Expand Down Expand Up @@ -136,6 +143,8 @@ public static function render() {
/**
* Load Page Scripts & Styles.
*
* @param string $hook Page hook.
*
* @return void
*/
public static function assets( $hook ) {
Expand All @@ -154,7 +163,7 @@ public static function assets( $hook ) {
\wp_register_script(
'bluehost-script',
BLUEHOST_BUILD_URL . '/index.js',
array_merge( $asset['dependencies'], [ 'nfd-runtime' ] ),
array_merge( $asset['dependencies'], array( 'nfd-runtime' ) ),
$asset['version'],
true
);
Expand Down
4 changes: 2 additions & 2 deletions inc/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
final class Data {


/**
* Data loaded onto window.NewfoldRuntime
*
Expand All @@ -22,7 +23,7 @@ public static function runtime() {
global $bluehost_module_container;

$runtime = array(
'plugin' => array(
'plugin' => array(
'url' => BLUEHOST_BUILD_URL,
'version' => BLUEHOST_PLUGIN_VERSION,
'assets' => BLUEHOST_PLUGIN_URL . 'assets/',
Expand All @@ -32,5 +33,4 @@ public static function runtime() {

return $runtime;
}

}
19 changes: 9 additions & 10 deletions inc/LoginRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ class LoginRedirect {
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_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' ) );
}

/**
* Get default redirect URL.
*
* @param string $url
* @param string $url Default redirect URL.
*
* @return string
*/
Expand Down Expand Up @@ -67,7 +67,7 @@ public static function on_login_redirect( $redirect_to, $requested_redirect_to,

if ( self::is_user( $user ) ) {
// If no redirect is defined and the user is an administrator, redirect to the Bluehost dashboard.
if ( (empty( $requested_redirect_to ) || admin_url( '/' ) === $requested_redirect_to ) && self::is_administrator( $user ) ) {
if ( ( empty( $requested_redirect_to ) || admin_url( '/' ) === $requested_redirect_to ) && self::is_administrator( $user ) ) {
return self::get_bluehost_dashboard_url();
}

Expand All @@ -80,14 +80,14 @@ public static function on_login_redirect( $redirect_to, $requested_redirect_to,
return $redirect_to;
}

/**
* Disable Yoast onboarding redirect.
*/
public static function disable_yoast_onboarding_redirect() {
if ( class_exists( 'WPSEO_Options' ) ) {
/**
* Disable Yoast onboarding redirect.
*/
public static function disable_yoast_onboarding_redirect() {
if ( class_exists( 'WPSEO_Options' ) ) {
\WPSEO_Options::set( 'should_redirect_after_install_free', false );
}
}
}

/**
* Check if we have a valid user.
Expand Down Expand Up @@ -130,7 +130,6 @@ public static function is_bluehost_redirect( $redirect ) {
public static function get_bluehost_dashboard_url() {
return admin_url( 'admin.php?page=bluehost#/home' );
}

}

LoginRedirect::init();
3 changes: 0 additions & 3 deletions inc/RestApi/CachingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public function register_routes() {
'permission_callback' => array( $this, 'check_permission' ),
)
);

}

/**
Expand All @@ -52,7 +51,6 @@ public function purge_all() {
'status' => 'success',
'message' => 'Cache purged',
);

}

/**
Expand All @@ -67,5 +65,4 @@ public function check_permission() {

return true;
}

}
3 changes: 0 additions & 3 deletions inc/RestApi/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function register_routes() {
),
)
);

}

/**
Expand Down Expand Up @@ -189,7 +188,6 @@ public function get_current_settings() {
);

return $settings;

}

/**
Expand All @@ -204,5 +202,4 @@ public function check_permission() {

return true;
}

}
83 changes: 42 additions & 41 deletions inc/YoastAI.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,60 @@
*
* @package Bluehost
*/
class YoastAI
{
/*
* Initialize the Yoast AI class.
*/
public static function init()
{
add_action( 'init', array( __CLASS__, 'on_yoast_plugin_activation' ) );
add_filter( 'http_request_args', array( __CLASS__,'modify_http_request_args' ), 10, 2 );
}
class YoastAI {

/*
* Register Yoast plugin activation hook to enable the Yoast AI generator on new activations.
*/
public static function on_yoast_plugin_activation()
{
register_activation_hook( 'wordpress-seo/wp-seo.php', array( __CLASS__, 'enable_on_new_activations' ) );
}
/**
* Initialize the Yoast AI class.
*/
public static function init() {
add_action( 'init', array( __CLASS__, 'on_yoast_plugin_activation' ) );
add_filter( 'http_request_args', array( __CLASS__, 'modify_http_request_args' ), 10, 2 );
}

/*
* Filter Yoast SEO default settings to enable AI on new installations/activations
*/
public static function enable_on_new_activations()
{
add_filter(
'wpseo_option_wpseo_defaults',
function ( $defaults ) {
if ( ! is_array( $defaults ) || ! isset( $defaults['enable_ai_generator'] ) ) {
return $defaults;
}
$defaults['enable_ai_generator'] = true;
return $defaults;
}
);
}
/**
* Register Yoast plugin activation hook to enable the Yoast AI generator on new activations.
*/
public static function on_yoast_plugin_activation() {
register_activation_hook( 'wordpress-seo/wp-seo.php', array( __CLASS__, 'enable_on_new_activations' ) );
}

/*
* Add a custom header to outbound Yoast AI requests for Bluehost customers.
*/
public static function modify_http_request_args( $parsed_args, $url )
{
$parsed_url = parse_url( $url );
/**
* Filter Yoast SEO default settings to enable AI on new installations/activations
*/
public static function enable_on_new_activations() {
add_filter(
'wpseo_option_wpseo_defaults',
function ( $defaults ) {
if ( ! is_array( $defaults ) || ! isset( $defaults['enable_ai_generator'] ) ) {
return $defaults;
}
$defaults['enable_ai_generator'] = true;
return $defaults;
}
);
}

/**
* Add a custom header to outbound Yoast AI requests for Bluehost customers.
*
* @param array $parsed_args HTTP request arguments.
* @param string $url URL of the request.
*
* @return array Array of HTTP request arguments.
*/
public static function modify_http_request_args( $parsed_args, $url ) {
$parsed_url = wp_parse_url( $url );
if ( ! is_array( $parsed_url ) ) {
return $parsed_args;
}
if ( $parsed_url['host'] !== 'ai.yoa.st' ) {
if ( 'ai.yoa.st' !== $parsed_url['host'] ) {
return $parsed_args;
}
if ( is_array( $parsed_args['headers'] ) ) {
$parsed_args['headers']['X-Yst-Cohort'] = 'Bluehost';
}
return $parsed_args;
}
}
}

YoastAI::init();
16 changes: 8 additions & 8 deletions inc/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ function bluehost_setup() {
if ( empty( $install_date ) ) {
update_option( 'mm_install_date', date( 'M d, Y' ) ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
$event = array(
't' => 'event',
'ec' => 'plugin_status',
'ea' => 'installed',
'el' => 'Install date: ' . get_option( 'mm_install_date', date( 'M d, Y' ) ), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
'keep' => false,
't' => 'event',
'ec' => 'plugin_status',
'ea' => 'installed',
'el' => 'Install date: ' . get_option( 'mm_install_date', date( 'M d, Y' ) ), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
'keep' => false,
);
$events = get_option( 'mm_cron', array() );
$events['hourly'][ $event['ea'] ] = $event;
Expand All @@ -80,10 +80,10 @@ function bluehost_setup() {
/**
* Filter the date used in data module
*
* @param string $install_date value from hook
* @param string $install_date value from hook
* @return int
*/
function bluehost_install_date_filter( $install_date ) {
function bluehost_install_date_filter( $install_date ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
return bluehost_get_plugin_install_date();
}
add_filter( 'nfd_install_date_filter', __NAMESPACE__ . '\\bluehost_install_date_filter' );
Expand All @@ -97,7 +97,7 @@ function bluehost_install_date_filter( $install_date ) {
*
* @return mixed
*/
function site_launched( $new_option, $old_option ) {
function site_launched( $new_option, $old_option ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
update_option( 'mm_coming_soon', $new_option );
return $new_option;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ function jetpack_construction() {
return true;
}
}
add_filter( 'jetpack_is_under_construction_plugin', __NAMESPACE__ . '\\jetpack_construction' );
add_filter( 'jetpack_is_under_construction_plugin', __NAMESPACE__ . '\\jetpack_construction' );
12 changes: 6 additions & 6 deletions inc/partners.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ function aioseo_upgrade_affiliate_link( $url ) {

/**
* Enable Sharing with WooCommerce
*
* @param string $plugin the plugin
*
* @param string $plugin the plugin
* @param boolean $network_activation flag is network activated
*
*
* @return void
*/
function plugin_activated( $plugin, $network_activation ) {
switch( $plugin ) {
function plugin_activated( $plugin, $network_activation ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
switch ( $plugin ) {
case 'woocommerce/woocommerce.php':
// Enable the usage tracking option by default https://woocommerce.com/usage-tracking/
update_option( 'woocommerce_allow_tracking', 'yes' );
break;
}
}

add_action( 'activated_plugin', __NAMESPACE__ . '\\plugin_activated', 10, 2 );
add_action( 'activated_plugin', __NAMESPACE__ . '\\plugin_activated', 10, 2 );
11 changes: 5 additions & 6 deletions inc/plugin-nfd-compat-check.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class NFD_Plugin_Compat_Check {
* @param string $file Plugin file
*/
public function __construct( $file ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
include_once ABSPATH . '/wp-admin/includes/plugin.php';
// require_once ABSPATH . '/wp-includes/option.php';
$this->slug = $this->get_plugin_slug( $file );
$this->name = $this->get_plugin_name( $file );
Expand All @@ -78,7 +78,7 @@ public function __construct( $file ) {
/**
* Get the plugin name from the plugin file headers
*
* @param string $file Plugin file
* @param string $file Plugin file
* @return string
*/
public function get_plugin_name( $file ) {
Expand All @@ -89,7 +89,7 @@ public function get_plugin_name( $file ) {
/**
* Get the plugin slug from the plugin path
*
* @param string $file Plugin file
* @param string $file Plugin file
* @return string
*/
public function get_plugin_slug( $file ) {
Expand Down Expand Up @@ -157,7 +157,7 @@ public function check_incompatible_plugins() {
$error->add(
'nfd_plugin_incompatible',
sprintf(
/* translators: 1: plugin name 2: incompatible plugin name */
/* translators: 1: plugin name 2: incompatible plugin name */
__( '"%1$s" has self-deactivated. It is incompatible with "%2$s".', 'wp-plugin-bluehost' ),
$this->name,
$incompatible_name
Expand All @@ -184,7 +184,7 @@ public function check_legacy_plugins() {
$error->add(
'nfd_plugin_legacy',
sprintf(
/* translators: 1: legacy plugin name 2: plugin name */
/* translators: 1: legacy plugin name 2: plugin name */
__( '"%1$s" has been deactivated. It is incompatible with "%2$s".', 'wp-plugin-bluehost' ),
$legacy_name,
$this->name
Expand Down Expand Up @@ -238,5 +238,4 @@ public function admin_notices() {
}
delete_option( 'nfd_plugins_compat_check_conflicts' );
}

}
Loading

0 comments on commit 04bb07f

Please sign in to comment.