diff --git a/includes/Data/Brands.php b/includes/Data/Brands.php index d77c4754e..513a5c3f5 100644 --- a/includes/Data/Brands.php +++ b/includes/Data/Brands.php @@ -285,7 +285,7 @@ public static function get_brands() { /** * Sets the hosting brand for which Onboarding is active. * - * @param array $container The brand plugin container. + * @param object $container The brand plugin container. * @return void */ public static function set_current_brand( $container ) { diff --git a/includes/Data/Events.php b/includes/Data/Events.php index e9e92c6af..62a457d1c 100644 --- a/includes/Data/Events.php +++ b/includes/Data/Events.php @@ -1,21 +1,30 @@ array( - 'category' => 'Admin', - 'action' => 'pageview', + /** + * Contains a list of events with the key being the event slug. + * + * @var array + */ + protected static $events = array( + 'nfd-module-onboarding-event-pageview' => array( + 'category' => 'Admin', + 'action' => 'pageview', ), - ); + ); - public static function get_event( $event_slug ) { - return self::$events[ $event_slug ] ? self::$events[ $event_slug ] : false; - } + /** + * Retrieves the active theme color variations. + * + * @param array $event_slug Event data. + * @return array|boolean + */ + public static function get_event( $event_slug ) { + return self::$events[ $event_slug ] ? self::$events[ $event_slug ] : false; + } } diff --git a/includes/Data/Flows.php b/includes/Data/Flows.php index a04f56778..3e60bb629 100644 --- a/includes/Data/Flows.php +++ b/includes/Data/Flows.php @@ -167,7 +167,7 @@ public static function get_default_flow() { } /** - * Retrive all the known onboarding flows. + * Retrieve all the known onboarding flows. * * @return array A value of true for each key indicates that the flow has been approved * and a value of null indicates the flow has not been approved (or) has been temporarily disabled. diff --git a/includes/Data/Options.php b/includes/Data/Options.php index 7ce77ce63..085debc80 100644 --- a/includes/Data/Options.php +++ b/includes/Data/Options.php @@ -10,7 +10,6 @@ final class Options { * * @var string */ - protected static $prefix = 'nfd_module_onboarding_'; /** @@ -18,7 +17,6 @@ final class Options { * * @var array */ - protected static $options = array( 'redirect' => 'redirect', 'redirect_param' => 'redirect_param', diff --git a/includes/Data/Themes/Colors.php b/includes/Data/Themes/Colors.php index a00054c74..620f6e1cc 100644 --- a/includes/Data/Themes/Colors.php +++ b/includes/Data/Themes/Colors.php @@ -14,7 +14,7 @@ final class Colors { */ protected static $theme_colors = array( 'yith-wonder' => array( - 'tailored' => array( + 'tailored' => array( 'calm' => array( 'header-background' => '#1A4733', 'header-foreground' => '#FFFFFF', @@ -137,7 +137,7 @@ final class Colors { 'base' => '#FFFFFF', ), ), - 'custom-picker-grouping' => array( + 'custom-picker-grouping' => array( 'base' => array( 'header-foreground', 'header-titles', diff --git a/includes/Data/Themes/Fonts.php b/includes/Data/Themes/Fonts.php index 9eba3bcba..92d5a51b1 100644 --- a/includes/Data/Themes/Fonts.php +++ b/includes/Data/Themes/Fonts.php @@ -2,6 +2,9 @@ namespace NewfoldLabs\WP\Module\Onboarding\Data\Themes; +/** + * Contains custom font palettes for a given theme. + */ final class Fonts { /** diff --git a/includes/LoginRedirect.php b/includes/LoginRedirect.php index e69c7d76b..ff7c8c2d0 100644 --- a/includes/LoginRedirect.php +++ b/includes/LoginRedirect.php @@ -28,7 +28,7 @@ public static function sso( $original_redirect ) { */ public static function wplogin( $original_redirect, $requested_original_redirect, $user ) { // wp-login.php runs this filter on load and login failures - // We should only do a redirect with a succesful user login + // We should only do a redirect with a successful user login if ( ! ( $user instanceof \WP_User ) ) { return $original_redirect; } diff --git a/includes/Models/PriorityQueue.php b/includes/Models/PriorityQueue.php index da37798b9..c0fc47d08 100644 --- a/includes/Models/PriorityQueue.php +++ b/includes/Models/PriorityQueue.php @@ -7,11 +7,10 @@ class PriorityQueue extends \SplPriorityQueue { /** - * @param mixed $priority1 - * @param mixed $priority2 - * * Defines the logic to use when comparing two priorities. * + * @param mixed $priority1 First Priority Queue + * @param mixed $priority2 Second Priority Queue * @return int */ public function compare( $priority1, $priority2 ) { diff --git a/includes/Models/Theme.php b/includes/Models/Theme.php index 039fb9fdd..49bef74a9 100644 --- a/includes/Models/Theme.php +++ b/includes/Models/Theme.php @@ -7,12 +7,31 @@ */ class Theme implements \JsonSerializable { + /** + * Name of the Theme. + * + * @var string + */ private $theme_name; + + /** + * Theme image Path. + * + * @var string + */ private $theme_image; + + /** + * Status of a theme being a Newfold Theme. + * + * @var boolean + */ private $is_newfold_theme; /** - * @param string $theme_name + * Theme constructor. + * + * @param string $theme_name Theme Name. */ public function __construct( $theme_name ) { $this->theme_name = $theme_name; @@ -20,8 +39,9 @@ public function __construct( $theme_name ) { } /** - * @param string $theme_name + * Sets the Theme Name * + * @param string $theme_name name of the theme. * @return void */ public function set_theme_name( $theme_name ) { @@ -29,15 +49,18 @@ public function set_theme_name( $theme_name ) { } /** - * @return string $theme_name + * Retrieve the Theme Name + * + * @return string */ public function get_theme_name() { return $this->theme_name; } /** - * @param string $theme_image Path to theme screenshot image. + * Sets the Theme image path * + * @param string $theme_image Path to theme screenshot image. * @return void */ public function set_theme_image( $theme_image ) { @@ -45,15 +68,18 @@ public function set_theme_image( $theme_image ) { } /** - * @return $theme_image Path to theme screenshot image. + * Retrieve the path to theme screenshot image + * + * @return string */ public function get_theme_image() { return $this->theme_image; } /** - * @param boolean $is_newfold_theme + * Sets the status of a theme as a Newfold theme. * + * @param boolean $is_newfold_theme Determines if there is a Newfold theme * @return void */ public function set_is_newfold_theme( $is_newfold_theme ) { @@ -61,14 +87,18 @@ public function set_is_newfold_theme( $is_newfold_theme ) { } /** - * @return boolean $is_newfold_theme true if the theme author is Newfold Digital. + * Retrieve is_newfold_theme status - true if the theme author is Newfold Digital. + * + * @return boolean */ public function get_is_newfold_theme() { return $this->is_newfold_theme; } /** - * @return array JSON Serialize the data + * To JSON Serialize the Theme data + * + * @return array */ public function jsonSerialize() { return array( diff --git a/includes/ModuleController.php b/includes/ModuleController.php index 6de4298b2..93a830e95 100644 --- a/includes/ModuleController.php +++ b/includes/ModuleController.php @@ -37,7 +37,7 @@ public static function module_switcher() { $enable_onboarding = self::verify_onboarding_criteria( $customer_data ); - // Check if he is a Non-Ecom Cust and Disable Redirect and Module + // Check if he is a Non-Ecommerce Customer and Disable Redirect and Module if ( ! $enable_onboarding ) { // Check if the Module Does Exist diff --git a/includes/Mustache/Mustache.php b/includes/Mustache/Mustache.php index 8cdab9a7e..4c8dc9f00 100644 --- a/includes/Mustache/Mustache.php +++ b/includes/Mustache/Mustache.php @@ -6,9 +6,17 @@ */ class Mustache { + /** + * Mustache Engine. + * + * @var array + */ protected $mustache_engine; - function __construct() { + /** + * Setup mustache engine. + */ + public function __construct() { $this->mustache_engine = new \Mustache_Engine( array( 'loader' => new \Mustache_Loader_FilesystemLoader( dirname( __FILE__ ) . '/Templates' ), @@ -17,12 +25,13 @@ function __construct() { } /** - * @param string $template_name - * @param array $data - * + * Render respective template data. + * + * @param string $template_name Template Name + * @param array $data Data * @return string */ public function render_template( $template_name, $data ) { - return $this->mustache_engine->loadTemplate( $template_name )->render( $data ); + return $this->mustache_engine->loadTemplate( $template_name )->render( $data ); } } diff --git a/includes/Permissions.php b/includes/Permissions.php index 1ffa275a0..e014b657c 100644 --- a/includes/Permissions.php +++ b/includes/Permissions.php @@ -13,12 +13,23 @@ final class Permissions { const INSTALL_THEMES = 'install_themes'; const EDIT_THEMES = 'edit_themes'; + /** + * Retrieve Plugin Install Hash Value. + * + * @return string + */ public static function rest_get_plugin_install_hash() { return 'NFD_ONBOARDING_' . hash( 'sha256', NFD_ONBOARDING_VERSION . wp_salt( 'nonce' ) . site_url() ); } + /** + * Verify Plugin Install Hash Value. + * + * @param string $hash Hash Value. + * @return boolean + */ public static function rest_verify_plugin_install_hash( $hash ) { - return $hash === self::rest_get_plugin_install_hash(); + return self::rest_get_plugin_install_hash() === $hash; } /** @@ -27,7 +38,7 @@ public static function rest_verify_plugin_install_hash( $hash ) { * @return boolean */ public static function rest_is_authorized_admin() { - return \is_user_logged_in() && \current_user_can( Permissions::ADMIN ); + return \is_user_logged_in() && \current_user_can( self::ADMIN ); } /** @@ -39,10 +50,15 @@ public static function is_authorized_admin() { return \is_admin() && self::rest_is_authorized_admin(); } + /** + * Confirm logged-in user can manage themes. + * + * @return boolean + */ public static function rest_can_manage_themes() { return \is_user_logged_in() && - \current_user_can( Permissions::INSTALL_THEMES ) && - \current_user_can( Permissions::EDIT_THEMES ); + \current_user_can( self::INSTALL_THEMES ) && + \current_user_can( self::EDIT_THEMES ); } /** @@ -51,8 +67,7 @@ public static function rest_can_manage_themes() { * @return boolean */ public static function custom_post_authorized_admin() { - return \current_user_can('edit_posts') && \current_user_can(Permissions::ADMIN); + return \current_user_can( 'edit_posts' ) && \current_user_can( self::ADMIN ); } } // END \NewfoldLabs\WP\Module\Onboarding\Permissions() - diff --git a/includes/RestApi/BaseHiiveController.php b/includes/RestApi/BaseHiiveController.php index 7a9195e3b..c6e9f692c 100644 --- a/includes/RestApi/BaseHiiveController.php +++ b/includes/RestApi/BaseHiiveController.php @@ -7,10 +7,15 @@ abstract class BaseHiiveController extends \WP_REST_Controller { /** + * Hiive Base URL + * * @var string */ protected $url; + /** + * BaseHiiveController constructor. + */ public function __construct() { if ( ! defined( 'NFD_HIIVE_BASE_URL' ) ) { @@ -21,10 +26,11 @@ public function __construct() { } /** - * @param string $endpoint - * @param array $args + * Get data from the endpoint containing the specific Hiive response. * - * @return \WP_Error|string containing the Hiive response. + * @param string $endpoint Endpoint request to get specific response + * @param array $args Arguments determining response + * @return \WP_Error|string */ protected function get( $endpoint, $args = array() ) { $request = $this->url . $endpoint . '?' . http_build_query( $args ); diff --git a/includes/RestApi/EventsController.php b/includes/RestApi/EventsController.php index f55537bbd..03b31752f 100644 --- a/includes/RestApi/EventsController.php +++ b/includes/RestApi/EventsController.php @@ -9,90 +9,94 @@ */ class EventsController extends \WP_REST_Controller { - /** - * @var string - */ - protected $namespace = 'newfold-onboarding/v1'; + /** + * This is the REST API namespace that will be used for our custom API + * + * @var string + */ + protected $namespace = 'newfold-onboarding/v1'; - /** - * @var string - */ - protected $rest_base = '/events'; + /** + * This is the REST endpoint + * + * @var string + */ + protected $rest_base = '/events'; - /** - * Register REST routes for EventsController class. - * - * @return void - */ - public function register_routes() { - \register_rest_route( - $this->namespace, - $this->rest_base, - array( - array( - 'methods' => \WP_REST_Server::CREATABLE, - 'callback' => array( $this, 'send_event' ), - 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), - 'args' => $this->get_send_event_args(), - ), - ) - ); - } + /** + * Register REST routes for EventsController class. + * + * @return void + */ + public function register_routes() { + \register_rest_route( + $this->namespace, + $this->rest_base, + array( + array( + 'methods' => \WP_REST_Server::CREATABLE, + 'callback' => array( $this, 'send_event' ), + 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), + 'args' => $this->get_send_event_args(), + ), + ) + ); + } - /** - * Get args for the send_event endpoint. - * - * @return array - */ - public function get_send_event_args() { - return array( - 'slug' => array( - 'required' => true, - 'type' => 'string', - 'sanitize_callback' => 'sanitize_text_field', - ), - 'data' => array( - 'type' => 'object', - ), - ); - } + /** + * Get args for the send_event endpoint. + * + * @return array + */ + public function get_send_event_args() { + return array( + 'slug' => array( + 'required' => true, + 'type' => 'string', + 'sanitize_callback' => 'sanitize_text_field', + ), + 'data' => array( + 'type' => 'object', + ), + ); + } - /** - * Send events to the data module events API. - * - * @param \WP_REST_Request $request - * - * @return \WP_REST_Response|\WP_Error - */ - public function send_event( \WP_REST_Request $request ) { - $event = Events::get_event( $request->get_param( 'slug' ) ); + /** + * Send events to the data module events API. + * + * @param \WP_REST_Request $request Request model. + * + * @return \WP_REST_Response|\WP_Error + */ + public function send_event( \WP_REST_Request $request ) { + $event = Events::get_event( $request->get_param( 'slug' ) ); if ( ! $event ) { - return new \WP_Error( - 'event-error', - 'No such event found', - array( 'status' => 404 ) - ); - } + return new \WP_Error( + 'event-error', + 'No such event found', + array( 'status' => 404 ) + ); + } - $event['data'] = $request->get_param( 'data' ); + $event['data'] = $request->get_param( 'data' ); - if ( ! empty( $event['data'] ) && ! empty( $event['data']['stepID'] ) ) { - $event['data']['page'] = \admin_url( '/index.php?page=nfd-onboarding#' . $event['data']['stepID'] ); - } + if ( ! empty( $event['data'] ) && ! empty( $event['data']['stepID'] ) ) { + $event['data']['page'] = \admin_url( '/index.php?page=nfd-onboarding#' . $event['data']['stepID'] ); + } - $event_data_request = new \WP_REST_Request( - \WP_REST_Server::CREATABLE, - NFD_MODULE_DATA_EVENTS_API - ); - $event_data_request->set_body_params( $event ); - $response = \rest_do_request( $event_data_request ); - if ( $response->is_error() ) { - return $response->as_error(); - } + $event_data_request = new \WP_REST_Request( + \WP_REST_Server::CREATABLE, + NFD_MODULE_DATA_EVENTS_API + ); + $event_data_request->set_body_params( $event ); + $response = \rest_do_request( $event_data_request ); + if ( $response->is_error() ) { + return $response->as_error(); + } - return new \WP_REST_Response( - $response, - $response->status - ); - } + return new \WP_REST_Response( + $response, + $response->status + ); + } } diff --git a/includes/RestApi/PluginsController.php b/includes/RestApi/PluginsController.php index 8d75bb95d..750f5ae91 100644 --- a/includes/RestApi/PluginsController.php +++ b/includes/RestApi/PluginsController.php @@ -360,4 +360,3 @@ public function set_site_features( \WP_REST_Request $request ) { ); } } - diff --git a/includes/RestApi/RestApiFilter.php b/includes/RestApi/RestApiFilter.php index 4b56c9fd6..38cdfb5c3 100644 --- a/includes/RestApi/RestApiFilter.php +++ b/includes/RestApi/RestApiFilter.php @@ -77,7 +77,7 @@ public static function wp_onboarding_nav_menu_filter( $response, $args ) { } /** - * Modify the reponse to make sure it has the dummy pages. + * Modify the response to make sure it has the dummy pages. * * @param array $data - array containing navigation menu data * @param integer $index - array index from the pages list @@ -140,7 +140,7 @@ public static function is_request_from_onboarding_flow( \WP_REST_Request $reques } /** - * Modify the reponse to make sure it has the dummy pages. + * Modify the response to make sure it has the dummy pages. * * @param array $response - response array * @@ -170,9 +170,9 @@ public static function modify_get_pages_response( $response ) { } /** - * Modify the reponse to make sure it has the dummy pages. + * Modify the response to make sure it has the dummy pages. * - * @param array $page - array containing page attibutes + * @param array $page - array containing page attributes * @param integer $index - array index from the pages list * * @return array diff --git a/includes/RestApi/SiteImagesController.php b/includes/RestApi/SiteImagesController.php index 16bef0bba..a09c3da7a 100644 --- a/includes/RestApi/SiteImagesController.php +++ b/includes/RestApi/SiteImagesController.php @@ -9,16 +9,22 @@ class SiteImagesController extends BaseHiiveController { /** + * The namespace of this controller's route. + * * @var string */ protected $namespace = 'newfold-onboarding/v1'; /** + * This is the REST endpoint + * * @var string */ protected $rest_base = '/site-images'; /** + * Results per page + * * @var int */ protected $results_per_page = 25; diff --git a/includes/RestApi/Themes/PatternsController.php b/includes/RestApi/Themes/PatternsController.php index 5aac5f85c..87133a572 100644 --- a/includes/RestApi/Themes/PatternsController.php +++ b/includes/RestApi/Themes/PatternsController.php @@ -45,8 +45,9 @@ public function register_routes() { } /** - * * Checks the type of the patterns. + * + * @return array */ public function get_pattern_args() { return array( diff --git a/includes/RestApi/Themes/ThemeVariationsController.php b/includes/RestApi/Themes/ThemeVariationsController.php index 11e03cc86..1f75098ba 100644 --- a/includes/RestApi/Themes/ThemeVariationsController.php +++ b/includes/RestApi/Themes/ThemeVariationsController.php @@ -56,9 +56,13 @@ public function register_routes() { ); } + /** + * Get the patterns arguments. + * Retrieves the original numerous variations if true, else sends the recently saved theme settings in the DB. + * + * @return array + */ public function get_pattern_args() { - // These variable return the orginal numerous variations if true - // Else sends the recently saved theme settings in db return array( 'variations' => array( 'type' => 'boolean', @@ -67,8 +71,12 @@ public function get_pattern_args() { ); } + /** + * Set the pattern arguments to the latest modified Global Style that is to be saved in the DB. + * + * @return array + */ public function set_pattern_args() { - // This is the latest modified Global Style to be saved in the db return array( 'title' => array( 'type' => 'string', @@ -81,12 +89,24 @@ public function set_pattern_args() { ); } + /** + * Translate decoded json file. + * + * @param string $theme_json Theme content. + * @param string $domain Domain type. + * @return string + */ private static function translate( $theme_json, $domain = 'default' ) { $i18n_schema = wp_json_file_decode( __DIR__ . '/theme-i18n.json' ); return translate_settings_using_i18n_schema( $i18n_schema, $theme_json, $domain ); } + /** + * Translate the json decoded HTML Files and retrieve all the Theme Style Variations. + * + * @return array + */ private static function get_style_variations() { $variations = array(); $base_directory = get_stylesheet_directory() . '/styles'; @@ -112,7 +132,8 @@ private static function get_style_variations() { /** * Retrieves the active themes variations. * - * @return \array|\WP_Error + * @param \WP_REST_Request $request Request model. + * @return array|\WP_Error */ public function get_theme_variations( \WP_REST_Request $request ) { @@ -143,6 +164,7 @@ public function get_theme_variations( \WP_REST_Request $request ) { /** * Saves the custom active theme variations. * + * @param \WP_REST_Request $request Request model. * @return \WP_REST_Response|\WP_Error */ public function set_theme_variation( \WP_REST_Request $request ) { diff --git a/includes/Services/FlowService.php b/includes/Services/FlowService.php index dab38ca00..eb773e8c7 100644 --- a/includes/Services/FlowService.php +++ b/includes/Services/FlowService.php @@ -93,7 +93,7 @@ public static function update_flow_data( $params ) { $flow_data = array_replace_recursive( $flow_data, $params ); - // Update timestamp everytime the Onboarding flow data is updated. + // Update timestamp every time the Onboarding flow data is updated. $flow_data['updatedAt'] = time(); // Update Blog Information from Basic Info diff --git a/includes/Services/PluginUninstaller.php b/includes/Services/PluginUninstaller.php index 08d668376..f24ffe623 100644 --- a/includes/Services/PluginUninstaller.php +++ b/includes/Services/PluginUninstaller.php @@ -8,9 +8,14 @@ * Class PluginUninstaller * This class is responsible to Uninstall a specified plugin */ - class PluginUninstaller { + /** + * Deactivate a plugin if active and then Uninstall the specific plugin. + * + * @param string $plugin Plugin URL. + * @return \WP_REST_Response|\WP_Error + */ public static function uninstall( $plugin ) { $plugin_list = Plugins::get_squashed(); @@ -35,10 +40,9 @@ public static function uninstall( $plugin ) { } /** - * @param string $plugin - * * Checks if a plugin with the given slug exists. * + * @param string $plugin Plugin * @return boolean */ public static function exists( $plugin ) { @@ -53,10 +57,9 @@ public static function exists( $plugin ) { } /** - * @param string $plugin_path Path to the plugin's header file. - * * Determines if a plugin has already been installed. * + * @param string $plugin_path Path to the plugin's header file. * @return boolean */ public static function is_plugin_installed( $plugin_path ) { @@ -101,7 +104,7 @@ protected static function connect_to_filesystem() { // We want to ensure that the user has direct access to the filesystem. $access_type = \get_filesystem_method(); - if ( $access_type !== 'direct' ) { + if ( 'direct' !== $access_type ) { return false; } diff --git a/includes/Services/ThemeInstaller.php b/includes/Services/ThemeInstaller.php index e99ac470a..d4b8ed579 100644 --- a/includes/Services/ThemeInstaller.php +++ b/includes/Services/ThemeInstaller.php @@ -3,15 +3,26 @@ use NewfoldLabs\WP\Module\Onboarding\Data\Themes; +/** + * Class ThemeInstaller. + */ class ThemeInstaller { + + /** + * Install a whitelisted Theme based on the activation status. + * + * @param string $theme Theme URL from Themes.php. + * @param boolean $activate Whether to activate the theme after install. + * @return \WP_REST_Response|\WP_Error + */ public static function install( $theme, $activate ) { $theme_list = Themes::get(); - // Checks if the theme slug is an nfd slug. + // Checks if the theme slug is an nfd slug. if ( self::is_nfd_slug( $theme ) ) { - // Retrieve the theme stylesheet to determine if it has been already installed. + // Retrieve the theme stylesheet to determine if it has been already installed. $stylesheet = $theme_list['nfd_slugs'][ $theme ]['stylesheet']; - // Check if the theme already exists. + // Check if the theme already exists. if ( ! ( \wp_get_theme( $stylesheet ) )->exists() ) { $status = self::install_from_zip( $theme_list['nfd_slugs'][ $theme ]['url'], @@ -28,7 +39,7 @@ public static function install( $theme, $activate ) { ); } - // If specified then activate the theme even if it already installed. + // If specified then activate the theme even if it already installed. if ( $activate && ( ( \wp_get_theme() )->get( 'TextDomain' ) !== $stylesheet ) ) { $status = \switch_theme( $stylesheet ); } @@ -40,6 +51,14 @@ public static function install( $theme, $activate ) { ); } + /** + * Install theme from an custom zip url if not already installed. Activate and switch to the theme, if specified. + * + * @param string $url The ZIP URL to install the theme from. + * @param boolean $activate Whether to activate the plugin after install. + * @param string $stylesheet Theme Stylesheet Name. + * @return \WP_REST_Response|\WP_Error + */ public static function install_from_zip( $url, $activate, $stylesheet ) { require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/misc.php'; @@ -84,7 +103,7 @@ public static function install_from_zip( $url, $activate, $stylesheet ) { ); } - // Activate the theme if specified. + // Activate the theme if specified. if ( $activate && ( ( \wp_get_theme() )->get( 'TextDomain' ) !== $stylesheet ) ) { \switch_theme( $stylesheet ); } @@ -97,10 +116,9 @@ public static function install_from_zip( $url, $activate, $stylesheet ) { } /** - * @param string $theme Slug of the theme. - * * Checks if a given slug is a valid nfd_slug. Ref: includes/Data/Themes.php for nfd_slug. * + * @param string $theme Slug of the theme. * @return boolean */ public static function is_nfd_slug( $theme ) { @@ -112,10 +130,11 @@ public static function is_nfd_slug( $theme ) { } /** + * Retrieve Theme Stylesheet Name for a specified theme name and theme type. + * * @param mixed $theme Slug of the theme present under includes/Data/Themes.php. * @param mixed $theme_type Type of theme Ref: includes/Data/Themes.php for types of theme slugs. - * - * @return string The theme stylesheet name. + * @return string|boolean */ public static function get_theme_stylesheet( $theme, $theme_type ) { $theme_list = Themes::get(); @@ -123,8 +142,9 @@ public static function get_theme_stylesheet( $theme, $theme_type ) { } /** - * @param string $theme + * Retrieve Theme Type - approved NFD Slug/WP Slug. * + * @param string $theme Theme name * @return string Type of theme. Ref: includes/Data/Themes.php for the different types. */ public static function get_theme_type( $theme ) { @@ -135,10 +155,9 @@ public static function get_theme_type( $theme ) { } /** - * @param string $stylesheet The stylesheet of the theme. - * * Determines if a theme has already been installed. * + * @param string $stylesheet The stylesheet of the theme. * @return boolean */ public static function is_theme_installed( $stylesheet ) { @@ -146,10 +165,9 @@ public static function is_theme_installed( $stylesheet ) { } /** - * @param string $stylesheet The stylesheet of the theme. - * * Determines if a theme is already active. * + * @param string $stylesheet The stylesheet of the theme. * @return boolean */ public static function is_theme_active( $stylesheet ) { @@ -157,11 +175,10 @@ public static function is_theme_active( $stylesheet ) { } /** - * @param string $theme - * @param string $activate - * * Checks if a theme with the given slug and activation criteria already exists. * + * @param string $theme Theme name + * @param string $activate Activation Criteria * @return boolean */ public static function exists( $theme, $activate ) { diff --git a/includes/TaskManagers/PluginUninstallTaskManager.php b/includes/TaskManagers/PluginUninstallTaskManager.php index d4af9a7e1..754b282be 100644 --- a/includes/TaskManagers/PluginUninstallTaskManager.php +++ b/includes/TaskManagers/PluginUninstallTaskManager.php @@ -19,9 +19,17 @@ class PluginUninstallTaskManager { */ private static $retry_limit = 2; + /** + * Name of the PluginUninstallTask Queue. + * + * @var string + */ private static $queue_name = 'plugin_uninstall_queue'; - function __construct() { + /** + * PluginUninstallTaskManager constructor. + */ + public function __construct() { // Ensure there is a Ten second option in the cron schedules add_filter( 'cron_schedules', array( $this, 'add_ten_seconds_schedule' ) ); @@ -34,10 +42,21 @@ function __construct() { } } + /** + * Retrieve the Queue Name for the TaskManager to perform Plugin Uninstalls. + * + * @return string + */ public static function get_queue_name() { return self::$queue_name; } + /** + * Adds ten seconds option in the cron schedule. + * + * @param array $schedules Cron Schedule duration + * @return array + */ public function add_ten_seconds_schedule( $schedules ) { if ( ! array_key_exists( 'ten_seconds', $schedules ) || 10 !== $schedules['ten_seconds']['interval'] ) { $schedules['ten_seconds'] = array( @@ -50,7 +69,6 @@ public function add_ten_seconds_schedule( $schedules ) { } /** - * Queue out a PluginUninstallTask with the highest priority in the plugin uninstall queue and execute it. * * @return array|false @@ -58,12 +76,14 @@ public function add_ten_seconds_schedule( $schedules ) { public function uninstall() { /* Get the plugins queued up to be uninstalled, the PluginUninstall task gets - converted to an associative array before storing it in the option. */ + converted to an associative array before storing it in the option. + */ $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); /* Conversion of the max heap to an array will always place the PluginUninstallTask with the highest - priority at the beginning of the array */ + priority at the beginning of the array + */ $plugin_to_uninstall = array_shift( $plugins ); // Update the plugin uninstall queue. @@ -83,9 +103,10 @@ public function uninstall() { // If there is an error, then increase the retry count for the task. $plugin_uninstall_task->increment_retries(); - /* + /* If the number of retries have not exceeded the limit - then re-queue the task at the end of the queue to be retried. */ + then re-queue the task at the end of the queue to be retried. + */ if ( $plugin_uninstall_task->get_retries() <= self::$retry_limit ) { array_push( $plugins, $plugin_uninstall_task->to_array() ); @@ -98,21 +119,21 @@ public function uninstall() { } /** - * @param PluginUninstallTask $plugin_uninstall_task - * * Adds a new PluginUninstallTask to the Plugin Uninstall queue. * The Task will be inserted at an appropriate position in the queue based on it's priority. * + * @param PluginUninstallTask $plugin_uninstall_task Plugin Task Details * @return array|false */ public static function add_to_queue( PluginUninstallTask $plugin_uninstall_task ) { /* Get the plugins queued up to be uninstalled, the PluginUninstall task gets - converted to an associative array before storing it in the option. */ + converted to an associative array before storing it in the option. + */ $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); $position_in_queue = PluginInstallTaskManager::status( $plugin_uninstall_task->get_slug() ); - if ( $position_in_queue !== false && $position_in_queue !== 0 ) { + if ( false !== $position_in_queue && 0 !== $position_in_queue ) { PluginInstallTaskManager::remove_from_queue( $plugin_uninstall_task->get_slug() ); @@ -124,15 +145,16 @@ public static function add_to_queue( PluginUninstallTask $plugin_uninstall_task // Gets the specified path for the Plugin from the predefined list $plugin_path = $plugin_list[ $plugin_uninstall_task->get_slug() ]['path']; - if (!PluginUninstaller::is_plugin_installed($plugin_path)) + if ( ! PluginUninstaller::is_plugin_installed( $plugin_path ) ) { return true; + } $queue = new PriorityQueue(); foreach ( $plugins as $queued_plugin ) { - /* Check if there is an already existing PluginUninstallTask in the queue - for a given slug. */ + for a given slug. + */ if ( $queued_plugin['slug'] === $plugin_uninstall_task->get_slug() ) { return false; } @@ -148,6 +170,12 @@ public static function add_to_queue( PluginUninstallTask $plugin_uninstall_task return \update_option( Options::get_option_name( self::$queue_name ), $queue->to_array() ); } + /** + * Returns the status of given plugin slug - uninstalling/completed. + * + * @param string $plugin Plugin Slug + * @return string|false + */ public static function status( $plugin ) { $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); return array_search( $plugin, array_column( $plugins, 'slug' ) ); diff --git a/includes/TaskManagers/TaskManager.php b/includes/TaskManagers/TaskManager.php index e4b816b6c..5642b8203 100644 --- a/includes/TaskManagers/TaskManager.php +++ b/includes/TaskManagers/TaskManager.php @@ -3,15 +3,26 @@ use NewfoldLabs\WP\Module\Onboarding\Data\Options; +/** + * Class TaskManager + */ final class TaskManager { + /** + * List of Task Managers. + * + * @var array + */ protected $task_managers = array( 'NewfoldLabs\\WP\Module\\Onboarding\\TaskManagers\\PluginInstallTaskManager', 'NewfoldLabs\\WP\Module\\Onboarding\\TaskManagers\\PluginUninstallTaskManager', 'NewfoldLabs\\WP\Module\\Onboarding\\TaskManagers\\ThemeInstallTaskManager', ); - function __construct() { + /** + * TaskManager constructor. + */ + public function __construct() { foreach ( $this->task_managers as $task_manager ) { if ( ! empty( get_option( Options::get_option_name( $task_manager::get_queue_name() ), array() ) ) ) { new $task_manager(); diff --git a/includes/TaskManagers/ThemeInstallTaskManager.php b/includes/TaskManagers/ThemeInstallTaskManager.php index 86758ea0d..b981ce365 100644 --- a/includes/TaskManagers/ThemeInstallTaskManager.php +++ b/includes/TaskManagers/ThemeInstallTaskManager.php @@ -19,9 +19,17 @@ class ThemeInstallTaskManager { */ private static $retry_limit = 1; + /** + * Name of the ThemeInstallTaskManager Queue. + * + * @var string + */ private static $queue_name = 'theme_install_queue'; - function __construct() { + /** + * ThemeInstallTaskManager constructor. + */ + public function __construct() { // Ensure there is a ten second option in the cron schedules add_filter( 'cron_schedules', array( $this, 'add_ten_seconds_schedule' ) ); @@ -34,10 +42,21 @@ function __construct() { } } + /** + * Retrieve the Queue Name for the TaskManager to perform Theme installation. + * + * @return string + */ public static function get_queue_name() { return self::$queue_name; } + /** + * Adds ten seconds option in the cron schedule. + * + * @param array $schedules Cron Schedule duration + * @return array + */ public function add_ten_seconds_schedule( $schedules ) { if ( ! array_key_exists( 'ten_seconds', $schedules ) || 10 !== $schedules['ten_seconds']['interval'] ) { $schedules['ten_seconds'] = array( @@ -49,6 +68,11 @@ public function add_ten_seconds_schedule( $schedules ) { return $schedules; } + /** + * Retrieve status of init_list of plugins being queued. + * + * @return boolean + */ public static function queue_initial_installs() { // Checks if the init_list of themes have already been queued. if ( \get_option( Options::get_option_name( 'theme_init_status' ), 'init' ) !== 'init' ) { @@ -85,12 +109,14 @@ public static function queue_initial_installs() { public function install() { /* Get the theme install tasks queued up to be installed, the ThemeInstallTask gets - converted to an associative array before storing it in the option. */ + converted to an associative array before storing it in the option. + */ $themes = \get_option( Options::get_option_name( self::$queue_name ), array() ); /* Conversion of the max heap to an array will always place the ThemeInstallTask with the highest - priority at the beginning of the array */ + priority at the beginning of the array + */ $theme_to_install = array_shift( $themes ); // Recreate the ThemeInstallTask from the associative array. @@ -111,9 +137,10 @@ public function install() { // If there is an error, then increase the retry count for the task. $theme_install_task->increment_retries(); - /* + /* If the number of retries have not exceeded the limit - then re-queue the task at the end of the queue to be retried. */ + then re-queue the task at the end of the queue to be retried. + */ if ( $theme_install_task->get_retries() <= self::$retry_limit ) { array_push( $themes, $theme_install_task->to_array() ); } @@ -129,25 +156,25 @@ public function install() { } /** - * @param ThemeInstallTask $theme_install_task - * * Adds a new ThemeInstallTask to the Theme Install queue. * The Task will be inserted at an appropriate position in the queue based on it's priority. * + * @param ThemeInstallTask $theme_install_task Theme Install Task to add to the queue * @return array|false */ public static function add_to_queue( ThemeInstallTask $theme_install_task ) { /* Get the ThemeInstallTasks queued up to be installed, the ThemeInstallTask gets - converted to an associative array before storing it in the option. */ + converted to an associative array before storing it in the option. + */ $themes = \get_option( Options::get_option_name( self::$queue_name ), array() ); $queue = new PriorityQueue(); foreach ( $themes as $queued_theme ) { - /* Check if there is an already existing ThemeInstallTask in the queue - for a given slug and activation criteria. */ + for a given slug and activation criteria. + */ if ( $queued_theme['slug'] === $theme_install_task->get_slug() && $queued_theme['activate'] === $theme_install_task->get_activate() ) { return false; @@ -164,6 +191,12 @@ public static function add_to_queue( ThemeInstallTask $theme_install_task ) { return \update_option( Options::get_option_name( self::$queue_name ), $queue->to_array() ); } + /** + * Returns the status of given plugin slug - installing/completed. + * + * @param string $theme Theme Slug + * @return string|false + */ public static function status( $theme ) { $themes = \get_option( Options::get_option_name( self::$queue_name ), array() ); return array_search( $theme, array_column( $themes, 'slug' ) ); diff --git a/includes/Tasks/PluginInstallTask.php b/includes/Tasks/PluginInstallTask.php index f8cd72f51..b1911dfa0 100644 --- a/includes/Tasks/PluginInstallTask.php +++ b/includes/Tasks/PluginInstallTask.php @@ -8,37 +8,90 @@ */ class PluginInstallTask extends Task { - private $slug, $activate, $priority, $retries; + /** + * Plugin Slug. + * + * @var string + */ + private $slug; + + /** + * Plugin Activation Status. + * + * @var boolean + */ + private $activate; + + /** + * Task Priority. + * + * @var int + */ + private $priority; + + /** + * Task Installation Retries Count. + * + * @var int + */ + private $retries; /** + * PluginInstallTask constructor + * * @param string $slug The slug for the Plugin. Ref: includes/Data/Plugins.php for the slugs. * @param boolean $activate A value of true activates the plugin. * @param int $priority Priority of the task, higher the number higher the priority. * @param int $retries The number of times the Task has been retried */ - function __construct( $slug, $activate, $priority = 0, $retries = 0 ) { + public function __construct( $slug, $activate, $priority = 0, $retries = 0 ) { $this->slug = $slug; $this->activate = $activate; $this->priority = $priority; $this->retries = $retries; } + /** + * Retrieves Slug for the Plugin. + * + * @return string + */ public function get_slug() { return $this->slug; } + /** + * Retrieves Plugin Activation Status. + * + * @return boolean + */ public function get_activate() { return $this->activate; } + /** + * Retrieves Task Priority. + * + * @return int + */ public function get_priority() { return $this->priority; } + /** + * Retrieves Task Installation retry count. + * + * @return string + */ public function get_retries() { return $this->retries; } + /** + * Increments retry count. + * + * @return void + */ public function increment_retries() { $this->retries++; } @@ -65,5 +118,4 @@ public function to_array() { 'retries' => $this->retries, ); } - } diff --git a/includes/Tasks/PluginUninstallTask.php b/includes/Tasks/PluginUninstallTask.php index a0780cdfb..a59ce38fa 100644 --- a/includes/Tasks/PluginUninstallTask.php +++ b/includes/Tasks/PluginUninstallTask.php @@ -8,31 +8,72 @@ */ class PluginUninstallTask extends Task { - private $slug, $priority, $retries; + /** + * Plugin Slug. + * + * @var string + */ + private $slug; + + /** + * Task Priority. + * + * @var int + */ + private $priority; + + /** + * Task Retries Count. + * + * @var int + */ + private $retries; /** + * PluginUninstallTask constructor + * * @param string $slug The slug for the Plugin. Ref: includes/Data/Plugins.php for the slugs. * @param int $priority Priority of the task, higher the number higher the priority. * @param int $retries The number of times the Task has been retried */ - function __construct( $slug, $priority = 0, $retries = 0 ) { + public function __construct( $slug, $priority = 0, $retries = 0 ) { $this->slug = $slug; $this->priority = $priority; $this->retries = $retries; } + /** + * Retrieves Slug for the Plugin. + * + * @return string + */ public function get_slug() { return $this->slug; } + /** + * Retrieves Task Priority. + * + * @return int + */ public function get_priority() { return $this->priority; } + /** + * Retrieves Task Installation retry count. + * + * @return string + */ public function get_retries() { return $this->retries; } + /** + * Increments retry count. + * + * @return void + */ public function increment_retries() { $this->retries++; } diff --git a/includes/Tasks/ThemeInstallTask.php b/includes/Tasks/ThemeInstallTask.php index a3f980799..70bd1f409 100644 --- a/includes/Tasks/ThemeInstallTask.php +++ b/includes/Tasks/ThemeInstallTask.php @@ -7,37 +7,91 @@ * Task for installing a Theme. */ class ThemeInstallTask extends Task { - private $slug, $activate, $priority, $retries; + + /** + * Theme Slug. + * + * @var string + */ + private $slug; + + /** + * Theme Activation Status. + * + * @var boolean + */ + private $activate; + + /** + * Task Priority. + * + * @var int + */ + private $priority; + + /** + * Task Installation Retries Count. + * + * @var int + */ + private $retries; /** + * ThemeInstallTask constructor + * * @param string $slug The slug for the Theme. Ref: includes/Data/Themes.php for the slugs. * @param boolean $activate A value of true activates the theme. * @param int $priority Priority of the task, higher the number higher the priority. * @param int $retries The number of times the Task has been retried */ - function __construct( $slug, $activate, $priority = 0, $retries = 0 ) { + public function __construct( $slug, $activate, $priority = 0, $retries = 0 ) { $this->slug = $slug; $this->activate = $activate; $this->priority = $priority; $this->retries = $retries; } + /** + * Retrieves Slug for the Theme. + * + * @return string + */ public function get_slug() { return $this->slug; } + /** + * Retrieves Theme Activation Status. + * + * @return boolean + */ public function get_activate() { return $this->activate; } + /** + * Retrieves Task Priority. + * + * @return int + */ public function get_priority() { return $this->priority; } + /** + * Retrieves Task Installation retry count. + * + * @return string + */ public function get_retries() { return $this->retries; } + /** + * Increments retry count. + * + * @return void + */ public function increment_retries() { $this->retries++; } diff --git a/includes/WP_Admin.php b/includes/WP_Admin.php index 297dc4802..77e9dc846 100644 --- a/includes/WP_Admin.php +++ b/includes/WP_Admin.php @@ -109,7 +109,7 @@ public static function register_assets() { } /** - * Initialise Plugins and Themes if necessary. + * Initialize Plugins and Themes if necessary. * * @return void */ diff --git a/includes/WP_CLI.php b/includes/WP_CLI.php index 6213122f7..83dcd3726 100644 --- a/includes/WP_CLI.php +++ b/includes/WP_CLI.php @@ -5,11 +5,9 @@ * Register Commands with WP-CLI */ final class WP_CLI { - /** - * Tap WordPress Hooks - */ - public function __construct() - { - - } -} // END \NewfoldLabs\WP\Module\Onboarding\CLI() \ No newline at end of file + /** + * Tap WordPress Hooks + */ + public function __construct() { + } +} // END \NewfoldLabs\WP\Module\Onboarding\CLI() diff --git a/includes/WP_Config.php b/includes/WP_Config.php index 1ff861ffa..c12aa39d6 100644 --- a/includes/WP_Config.php +++ b/includes/WP_Config.php @@ -7,11 +7,16 @@ class WP_Config { /** + * WordPress Configuration + * * @var \WPConfigTransformer */ protected $wp_config; - function __construct() { + /** + * WP_Config constructor. + */ + public function __construct() { $this->wp_config = new \WPConfigTransformer( ABSPATH . 'wp-config.php' ); }