diff --git a/includes/Data/Options.php b/includes/Data/Options.php index a33c01860..df9826886 100644 --- a/includes/Data/Options.php +++ b/includes/Data/Options.php @@ -48,6 +48,7 @@ final class Options { 'page_on_front' => 'page_on_front', 'theme_settings' => 'theme_settings', 'flow_preset' => 'flow_preset', + 'wpseo_social' => 'wpseo_social', ); /** diff --git a/includes/Data/Patterns.php b/includes/Data/Patterns.php index 86df2abca..c21363776 100644 --- a/includes/Data/Patterns.php +++ b/includes/Data/Patterns.php @@ -4,8 +4,16 @@ use NewfoldLabs\WP\Module\Onboarding\Data\Options; +/** + * Class Patterns + */ final class Patterns { + /** + * Retrieve Patterns for Theme Step. + * + * @return array + */ protected static function get_theme_step_patterns() { return array( 'yith-wonder' => array( @@ -96,12 +104,19 @@ protected static function get_theme_step_patterns() { 'shown' => true, ), ), - 'site-features' => SiteFeatures::get_site_features()[Data::current_flow()] + 'site-features' => SiteFeatures::get_site_features()[ Data::current_flow() ], ), ); } - public static function cleanup_wp_grammar( $content ) { + /** + * Sanitize the content by cleaning wp_grammar. + * + * @param string $content Data to clean + * + * @return string + */ + private static function cleanup_wp_grammar( $content ) { // Remove template-part if that exists $content = preg_replace( '/^$/m', '', $content ); @@ -115,6 +130,13 @@ public static function cleanup_wp_grammar( $content ) { return $content; } + /** + * Retrieve pattern from slug. + * + * @param array $pattern_slug Pattern Slug Data + * + * @return array|boolean + */ public static function get_pattern_from_slug( $pattern_slug ) { $block_patterns_registry = \WP_Block_Patterns_Registry::get_instance(); @@ -130,6 +152,14 @@ public static function get_pattern_from_slug( $pattern_slug ) { return false; } + /** + * Retrieve Theme Step Patterns from chosen Theme in Previous Step + * + * @param string $step Step from which Theme Step Pattern is required + * @param boolean $squash Flag set to retrieve the block pattern + * + * @return array|string + */ public static function get_theme_step_patterns_from_step( $step, $squash = false ) { $active_theme = ( \wp_get_theme() )->get( 'TextDomain' ); @@ -142,7 +172,7 @@ public static function get_theme_step_patterns_from_step( $step, $squash = false $block_patterns = array(); $block_patterns_squashed = ''; foreach ( array_keys( $pattern_slugs ) as $pattern_slug ) { - if ( $pattern_slugs[ $pattern_slug ]['active'] === true ) { + if ( true === $pattern_slugs[ $pattern_slug ]['active'] ) { $pattern_name = $active_theme . '/' . $pattern_slug; if ( $block_patterns_registry->is_registered( $pattern_name ) ) { $pattern = $block_patterns_registry->get_registered( $pattern_name ); @@ -166,6 +196,11 @@ public static function get_theme_step_patterns_from_step( $step, $squash = false return $squash ? $block_patterns_squashed : $block_patterns; } + /** + * Retrieve Pattern Count. + * + * @return array + */ public static function get_count_of_patterns() { $active_theme = ( \wp_get_theme() )->get( 'TextDomain' ); $theme_step_patterns = self::get_theme_step_patterns(); @@ -176,10 +211,10 @@ public static function get_count_of_patterns() { $theme_step_count = 0; $combine_styles = 1; foreach ( $patterns as $pattern => $pattern_data ) { - if ( isset( $pattern_data['shown'] ) && $pattern_data['shown'] === true ) { - $theme_step_count += 1; + if ( isset( $pattern_data['shown'] ) && true === $pattern_data['shown'] ) { + ++$theme_step_count; } - if ( isset( $pattern_data['combine'] ) && $pattern_data['combine'] === true ) { + if ( isset( $pattern_data['combine'] ) && true === $pattern_data['combine'] ) { $combine_styles = count( \WP_Theme_JSON_Resolver::get_style_variations() ) + 1; } } diff --git a/includes/Data/SiteFeatures.php b/includes/Data/SiteFeatures.php index a0e9afddf..4e290f47d 100644 --- a/includes/Data/SiteFeatures.php +++ b/includes/Data/SiteFeatures.php @@ -1,15 +1,20 @@ array(), + 'wp-setup' => array(), 'ecommerce' => array( 'jetpack' => array( 'slug' => 'jetpack', @@ -105,7 +110,12 @@ public static function get_site_features() ); } - public static function mark_initial_plugins() { + /** + * Based on the flow type initial site features are marked. + * + * @return array + */ + private static function mark_initial_plugins() { $flow = Data::current_flow(); $installed_plugins = Plugins::get_init(); @@ -121,6 +131,11 @@ public static function mark_initial_plugins() { return $site_features_marked; } + /** + * Retrieve marked site features + * + * @return array + */ public static function get() { return self::mark_initial_plugins(); } diff --git a/includes/RestApi/FlowController.php b/includes/RestApi/FlowController.php index 0f71346a3..363ebd113 100644 --- a/includes/RestApi/FlowController.php +++ b/includes/RestApi/FlowController.php @@ -13,14 +13,16 @@ class FlowController { /** - * @var string * This is the REST API namespace that will be used for our custom API + * + * @var string */ protected $namespace = 'newfold-onboarding/v1'; /** - * @var string * This is the REST endpoint + * + * @var string */ protected $rest_base = '/flow'; @@ -68,7 +70,8 @@ public function register_routes() { */ public function get_onboarding_flow_data( \WP_REST_Request $request ) { // check if data is available in the database if not then fetch the default dataset - if ( ! ( $result = $this->read_details_from_wp_options() ) ) { + $result = $this->read_details_from_wp_options(); + if ( ! $result ) { $result = Flows::get_data(); $result['createdAt'] = time(); // update default data if flow type is ecommerce @@ -101,7 +104,8 @@ public function save_onboarding_flow_data( \WP_REST_Request $request ) { ); } - if ( ! ( $flow_data = $this->read_details_from_wp_options() ) ) { + $flow_data = $this->read_details_from_wp_options(); + if ( ! $flow_data ) { $flow_data = Flows::get_data(); $flow_data['createdAt'] = time(); // update default data if flow type is ecommerce @@ -110,7 +114,8 @@ public function save_onboarding_flow_data( \WP_REST_Request $request ) { } foreach ( $params as $key => $param ) { - if ( $value = $this->array_search_key( $key, $flow_data ) === false ) { + $value = $this->array_search_key( $key, $flow_data ); + if ( false === $value ) { return new \WP_Error( 'wrong_param_provided', "Wrong Parameter Provided : $key", @@ -157,16 +162,16 @@ public function save_onboarding_flow_data( \WP_REST_Request $request ) { } /** - * check the current flow type and update default data if flowtype is ecommerce. + * Check the current flow type and update default data if flowtype is ecommerce. * - * @param default flow data. + * @param array $data default blueprint flow data. * * @return array */ - public function update_default_data_for_ecommerce( $data ) { + private function update_default_data_for_ecommerce( $data ) { // get current flow type $flow_type = Data::current_flow(); - if ( $flow_type == 'ecommerce' ) { + if ( 'ecommerce' === $flow_type ) { // update default data with ecommerce data $data['data']['topPriority']['priority1'] = 'selling'; $data['data']['siteType'] = array( @@ -177,37 +182,53 @@ public function update_default_data_for_ecommerce( $data ) { return $data; } - /* + /** * Read onboarding flow options from database + * + * @return array */ public function read_details_from_wp_options() { return \get_option( Options::get_option_name( 'flow' ) ); } - /* - * add onboarding flow options + /** + * Add onboarding flow options + * + * @param array $data default blueprint flow data. + * + * @return array */ - public function save_details_to_wp_options( $data ) { + private function save_details_to_wp_options( $data ) { return \add_option( Options::get_option_name( 'flow' ), $data ); } - /* - * update onboarding flow options + /** + * Update onboarding flow options + * + * @param array $data default blueprint flow data. + * + * @return array */ - public function update_wp_options_data_in_database( $data ) { + private function update_wp_options_data_in_database( $data ) { return \update_option( Options::get_option_name( 'flow' ), $data ); } - /* - * function to search for key in array recursively with case sensitive exact match + /** + * Function to search for key in array recursively with case sensitive exact match + * + * @param array $needle_key specific key in flow data. + * @param array $array WP Options Data. + * + * @return boolean */ - public function array_search_key( $needle_key, $array ) { + private function array_search_key( $needle_key, $array ) { foreach ( $array as $key => $value ) { if ( strcmp( $key, $needle_key ) === 0 ) { return true; } if ( is_array( $value ) ) { - if ( ( $result = $this->array_search_key( $needle_key, $value ) ) !== false ) { + $result = $this->array_search_key( $needle_key, $value ); + if ( false !== $result ) { return $result; } } @@ -215,6 +236,11 @@ public function array_search_key( $needle_key, $array ) { return false; } + /** + * Flow completion API for child theme generation, verify child theme and publish site pages + * + * @return \WP_REST_Response + */ public function complete() { $site_pages_publish_request = new \WP_REST_Request( 'POST', diff --git a/includes/RestApi/SettingsController.php b/includes/RestApi/SettingsController.php index 1663dbd4f..4d18cb1f6 100644 --- a/includes/RestApi/SettingsController.php +++ b/includes/RestApi/SettingsController.php @@ -5,8 +5,6 @@ use NewfoldLabs\WP\Module\Onboarding\Data\Options; use NewfoldLabs\WP\Module\Onboarding\Data\Config; use NewfoldLabs\WP\Module\Onboarding\WP_Config; -use NewfoldLabs\WP\Module\Onboarding\Data\Data; -use NewfoldLabs\WP\Module\Onboarding\Services\Webfonts; /** * Class SettingsController @@ -27,13 +25,6 @@ class SettingsController { */ protected $rest_base = '/settings'; - /** - * Yoast wp_options key - * - * @var string - */ - protected $yoast_wp_options_key = 'wpseo_social'; - /** * Array of defaults for the option. * @@ -82,6 +73,8 @@ class SettingsController { /** * Store for invalid urls + * + * @var array */ protected $invalid_urls = array(); @@ -143,18 +136,19 @@ public function update_item( \WP_REST_Request $request ) { foreach ( $params as $param_key => $param_value ) { if ( ! array_key_exists( $param_key, $this->defaults ) ) { $this->invalid_urls[] = $param_key; - unset($params[$param_key]); + unset( $params[ $param_key ] ); continue; } // check for proper url if ( in_array( $param_key, $this->social_urls_to_validate ) ) { - switch($param_key) { + switch ( $param_key ) { case 'twitter_site': - if( !empty($params['twitter_site'])) { - if( ( $twitter_id = $this->validate_twitter_id($params['twitter_site']) ) === false ) { + if ( ! empty( $params['twitter_site'] ) ) { + $twitter_id = $this->validate_twitter_id( $params['twitter_site'] ); + if ( ( $twitter_id ) === false ) { $this->invalid_urls[] = 'twitter_site'; - unset($params['twitter_site']); + unset( $params['twitter_site'] ); } else { $params['twitter_site'] = $twitter_id; } @@ -162,10 +156,10 @@ public function update_item( \WP_REST_Request $request ) { break; case 'other_social_urls': foreach ( $param_value as $param_key_osu => $param_url ) { - $param_value[ $param_key_osu ] = \sanitize_text_field( $param_url ); + $param_value[ $param_key_osu ] = \sanitize_text_field( $param_url ); if ( ! empty( $param_url ) && ! \wp_http_validate_url( $param_url ) ) { $this->invalid_urls[] = $param_key_osu; - unset($params[$param_key_osu]); + unset( $params[ $param_key_osu ] ); continue; } } @@ -174,7 +168,7 @@ public function update_item( \WP_REST_Request $request ) { $param[ $param_key ] = \sanitize_text_field( $param_value ); if ( ! empty( $param_value ) && ! \wp_http_validate_url( $param_value ) ) { $this->invalid_urls[] = $param_key; - unset($params[$param_key]); + unset( $params[ $param_key ] ); } break; } @@ -182,10 +176,10 @@ public function update_item( \WP_REST_Request $request ) { } $settings = array_merge( $settings, $params ); - \update_option( $this->yoast_wp_options_key, $settings ); + \update_option( Options::get_option_name( 'wpseo_social', false ), $settings ); - if(!empty($this->invalid_urls)) { - $error_keys = implode( ", ", $this->invalid_urls ); + if ( ! empty( $this->invalid_urls ) ) { + $error_keys = implode( ', ', $this->invalid_urls ); return new \WP_Error( 'invalid_urls', "Invalid url(s) provided for {$error_keys}.", @@ -202,18 +196,20 @@ public function update_item( \WP_REST_Request $request ) { */ public function get_current_settings() { + $social_data = \get_option( Options::get_option_name( 'wpseo_social', false ), false ); // incase yoast plugin is not installed then we need to save the values in the yoast_wp_options_key - if ( ( $social_data = \get_option( $this->yoast_wp_options_key ) ) === false ) { + if ( false === $social_data ) { // initialize an array with default values $social_data = $this->defaults; // update database - \add_option( $this->yoast_wp_options_key, $social_data ); + \add_option( Options::get_option_name( 'wpseo_social', false ), $social_data ); } + $twitter_handle = $this->validate_twitter_id( $social_data['twitter_site'] ); // add the full url for twitter cause only the handle is saved in the database - if( (!empty($social_data['twitter_site'])) && - ($twitter_handle = $this->validate_twitter_id($social_data['twitter_site'])) !== false ) { + if ( ! empty( $social_data['twitter_site'] ) && + ( false !== $twitter_handle ) ) { $social_data['twitter_site'] = 'https://www.twitter.com/' . $twitter_handle; } diff --git a/includes/RestApi/SitePagesController.php b/includes/RestApi/SitePagesController.php index 5f171f167..d13286d42 100644 --- a/includes/RestApi/SitePagesController.php +++ b/includes/RestApi/SitePagesController.php @@ -8,17 +8,21 @@ use NewfoldLabs\WP\Module\Onboarding\Data\Patterns; /** - * class SitePagesController + * Class SitePagesController */ class SitePagesController { /** + * The namespace of this controller's route. + * * @var string */ protected $namespace = 'newfold-onboarding/v1'; /** + * The endpoint base + * * @var string */ protected $rest_base = '/site-pages'; @@ -43,11 +47,11 @@ public function register_routes() { /** * Endpoint create_page * - * @param $request WP_REST_Request + * @return \WP_REST_Response|\WP_Error */ public function publish_site_pages() { $flow_data_option = \get_option( Options::get_option_name( 'flow' ), false ); - if ( $flow_data_option === false || ! isset( $flow_data_option['data'] ) ) { + if ( false === $flow_data_option || ! isset( $flow_data_option['data'] ) ) { return new \WP_Error( 'nfd_onboarding_error', 'Flow data does not exist to generate a child theme.', @@ -73,6 +77,13 @@ public function publish_site_pages() { ); } + /** + * Set the homepage pattern chosen + * + * @param string $homepage_pattern_slug Homepage Pattern + * + * @return boolean|\WP_Error + */ private function set_homepage( $homepage_pattern_slug ) { if ( empty( $homepage_pattern_slug ) ) { return true; @@ -90,7 +101,7 @@ private function set_homepage( $homepage_pattern_slug ) { $show_pages_on_front = \get_option( Options::get_option_name( 'show_on_front', false ) ); // Check if default homepage is posts - if ( $show_pages_on_front == 'posts' ) { + if ( 'posts' === $show_pages_on_front ) { \update_option( Options::get_option_name( 'show_on_front', false ), 'page' ); } @@ -105,6 +116,13 @@ private function set_homepage( $homepage_pattern_slug ) { } + /** + * Set the site page chosen + * + * @param array $site_pages_pattern_slugs Homepage Pattern + * + * @return boolean|\WP_Error + */ private function set_site_pages( $site_pages_pattern_slugs ) { if ( empty( $site_pages_pattern_slugs ) ) { return true; @@ -127,7 +145,16 @@ private function set_site_pages( $site_pages_pattern_slugs ) { return true; } - public function publish_page( $title, $content, $is_template_no_title = false ) { + /** + * Set the Publish Page + * + * @param string $title Site Page Title + * @param string $content Pattern Content + * @param boolean $is_template_no_title Check for Title + * + * @return int|\WP_Error + */ + private function publish_page( $title, $content, $is_template_no_title = false ) { $post = array( 'post_title' => $title, diff --git a/includes/RestApi/Themes/ThemeGeneratorController.php b/includes/RestApi/Themes/ThemeGeneratorController.php index 3865fb370..185fc48cc 100644 --- a/includes/RestApi/Themes/ThemeGeneratorController.php +++ b/includes/RestApi/Themes/ThemeGeneratorController.php @@ -12,20 +12,31 @@ */ class ThemeGeneratorController { /** + * The REST API namespace of this controller's route. + * * @var string */ protected $namespace = 'newfold-onboarding/v1'; /** + * The REST endpoint base + * * @var string */ protected $rest_base = '/themes'; /** + * The REST endpoint base + * * @var string */ protected $rest_extended_base = '/child/generate'; + /** + * Registers rest routes for this controller class. + * + * @return void + */ public function register_routes() { \register_rest_route( $this->namespace, @@ -48,7 +59,7 @@ public function register_routes() { public function generate_child_theme() { // Ensure that we have sufficient data to generate a child theme. $flow_data_option = \get_option( Options::get_option_name( 'flow' ), false ); - if ( $flow_data_option === false || ! isset( $flow_data_option['data'] ) ) { + if ( false === $flow_data_option || ! isset( $flow_data_option['data'] ) ) { return new \WP_Error( 'nfd_onboarding_error', 'Flow data does not exist to generate a child theme.', @@ -57,7 +68,7 @@ public function generate_child_theme() { } $flow_data = $this->validate_and_sanitize_flow_data( $flow_data_option['data'] ); - if ( $flow_data === false ) { + if ( false === $flow_data ) { return new \WP_Error( 'nfd_onboarding_error', 'Flow data is incomplete to generate a child theme.', @@ -87,7 +98,8 @@ public function generate_child_theme() { /* Activate the parent theme if it is not active. - This is necessary to register the parent theme's block patterns. */ + This is necessary to register the parent theme's block patterns. + */ $active_theme = ( \wp_get_theme() )->get( 'TextDomain' ); if ( $active_theme !== $parent_theme_slug ) { $this->activate_theme( $parent_theme_slug ); @@ -132,7 +144,7 @@ public function generate_child_theme() { ); $child_theme_written = $this->write_child_theme( $child_theme_data ); - if ( $child_theme_written !== true ) { + if ( true !== $child_theme_written ) { return new \WP_Error( 'nfd_onboarding_error', $child_theme_written, @@ -159,10 +171,22 @@ public function generate_child_theme() { ); } + /** + * Retrieve Site Url Hash Value + * + * @param integer $length hash length + * + * @return string + */ private function get_site_url_hash( $length = 8 ) { return substr( hash( 'sha256', site_url() ), 0, $length ); } + /** + * Retrieve Default Dashed Site Title + * + * @return array + */ private function get_dashed_site_title_defaults() { return array( 'welcome', 'wordpress-site' ); } @@ -170,7 +194,7 @@ private function get_dashed_site_title_defaults() { /** * Get the child theme stylesheet from flow data. * - * @param array $flow_data + * @param array $flow_data Flow Data * * @return string */ @@ -191,7 +215,7 @@ protected function get_child_theme_slug( $flow_data ) { /** * Activates a given theme. * - * @param string $theme WordPress slug for theme + * @param string $theme_slug WordPress slug for theme * * @return void */ @@ -202,17 +226,17 @@ protected function activate_theme( $theme_slug ) { /** * Generates the child theme.json from the relevant parent theme.json * - * @param array $flow_data - * @param string $parent_theme_dir + * @param array $flow_data Flow Data + * @param string $parent_theme_dir Parent Theme Directory * * @return boolean|array */ - protected function generate_child_theme_json( $flow_data, $parent_theme_dir ) { + private function generate_child_theme_json( $flow_data, $parent_theme_dir ) { global $wp_filesystem; $theme_data = \get_option( Options::get_option_name( 'theme_settings' ), false ); - if ( $theme_data !== false ) { + if ( false !== $theme_data ) { unset( $theme_data['settings']['styles'] ); unset( $theme_data['settings']['__unstableResolvedAssets'] ); unset( $theme_data['settings']['__experimentalFeatures'] ); @@ -229,7 +253,15 @@ protected function generate_child_theme_json( $flow_data, $parent_theme_dir ) { return $theme_json_data; } - public function generate_child_theme_stylesheet_comment( $parent_theme_slug, $child_theme_slug ) { + /** + * Generates the child theme.json style.css comment from the relevant parent theme slug + * + * @param array $parent_theme_slug Parent Theme Slug + * @param string $child_theme_slug Child Theme Slug + * + * @return string + */ + private function generate_child_theme_stylesheet_comment( $parent_theme_slug, $child_theme_slug ) { $current_brand = Data::current_brand(); $customer = \wp_get_current_user(); @@ -258,11 +290,11 @@ public function generate_child_theme_stylesheet_comment( $parent_theme_slug, $ch /** * Get the pattern for the theme part. * - * @param string $pattern_slug + * @param string $pattern_slug Patten Slug * * @return string|\WP_Error the pattern for the part. */ - protected function generate_theme_part_pattern( $pattern_slug ) { + private function generate_theme_part_pattern( $pattern_slug ) { $pattern = \WP_Block_Patterns_Registry::get_instance()->get_registered( $pattern_slug ); if ( ! $pattern ) { return new \WP_Error( @@ -278,7 +310,7 @@ protected function generate_theme_part_pattern( $pattern_slug ) { /** * Write the child theme to the themes directory. * - * @param array child_theme_data + * @param array $child_theme_data Child Theme Data * @var string parent_theme_slug * @var string child_theme_slug * @var string parent_theme_dir @@ -288,7 +320,7 @@ protected function generate_theme_part_pattern( $pattern_slug ) { * * @return string|boolean */ - protected function write_child_theme( $child_theme_data ) { + private function write_child_theme( $child_theme_data ) { $child_directory_created = $this->create_directory( $child_theme_data['child_theme_dir'] ); if ( ! $child_directory_created ) { return 'Error creating child directory.'; @@ -334,11 +366,11 @@ protected function write_child_theme( $child_theme_data ) { /** * Creates a directory if necessary. * - * @param string $dir + * @param string $dir Directory * * @return boolean */ - protected function create_directory( $dir ) { + private function create_directory( $dir ) { global $wp_filesystem; if ( ! $wp_filesystem->exists( $dir ) ) { @@ -351,24 +383,24 @@ protected function create_directory( $dir ) { /** * Writes $theme_json to a theme's theme.json file. * - * @param string $theme_dir - * @param string $theme_json + * @param string $theme_dir Theme Directory + * @param string $theme_json Theme json content * * @return boolean */ - protected function write_theme_json( $theme_dir, $theme_json ) { - return $this->write_to_filesystem( $theme_dir . '/' . 'theme.json', $theme_json ); + private function write_theme_json( $theme_dir, $theme_json ) { + return $this->write_to_filesystem( $theme_dir . '/theme.json', $theme_json ); } /** * Writes HTML template parts to the theme's parts directory. * - * @param string $theme_dir - * @param array $part_patterns + * @param string $theme_dir Theme Directory + * @param array $part_patterns HTML Template Part * * @return boolean */ - protected function write_template_parts( $theme_dir, $part_patterns ) { + private function write_template_parts( $theme_dir, $part_patterns ) { global $wp_filesystem; if ( ! $wp_filesystem->exists( $theme_dir . '/parts' ) ) { @@ -390,24 +422,23 @@ protected function write_template_parts( $theme_dir, $part_patterns ) { /** * Writes style.css for the child theme. * - * @param string $parent_theme_slug - * @param string $child_theme_slug - * @param string $child_theme_dir + * @param string $child_theme_stylesheet_comment Stylesheet comment of Child Theme + * @param string $child_theme_dir Child Theme Directory * * @return boolean */ - protected function write_child_stylesheet( $child_theme_stylesheet_comment, $child_theme_dir ) { + private function write_child_stylesheet( $child_theme_stylesheet_comment, $child_theme_dir ) { return $this->write_to_filesystem( $child_theme_dir . '/style.css', $child_theme_stylesheet_comment ); } /** * Checks if $flow_data has all the necessary data to generate a child theme. * - * @param array $flow_data + * @param array $flow_data Flow Data * * @return boolean */ - protected function validate_and_sanitize_flow_data( $flow_data ) { + private function validate_and_sanitize_flow_data( $flow_data ) { $current_flow = Data::current_flow(); if ( ! $flow_data['theme']['template'] ) { $current_flow = Data::current_flow(); @@ -429,12 +460,12 @@ protected function validate_and_sanitize_flow_data( $flow_data ) { * * [TODO] Generate the actual child theme screenshot. * - * @param string $parent_theme_dir - * @param string $child_theme_dir + * @param string $parent_theme_dir Parent Theme Directory + * @param string $child_theme_dir Child Theme Directory * * @return boolean */ - protected function generate_screenshot( $parent_theme_dir, $child_theme_dir ) { + private function generate_screenshot( $parent_theme_dir, $child_theme_dir ) { global $wp_filesystem; $screenshot_files = array( '/screenshot.png', '/screenshot.jpg' ); @@ -459,12 +490,12 @@ protected function generate_screenshot( $parent_theme_dir, $child_theme_dir ) { /** * Writes content to the specified file. * - * @param string $file - * @param string $content + * @param string $file Specific File where $content is to be written + * @param string $content Content to write to the $file * * @return boolean */ - protected function write_to_filesystem( $file, $content ) { + private function write_to_filesystem( $file, $content ) { global $wp_filesystem; return $wp_filesystem->put_contents( @@ -484,7 +515,7 @@ protected 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; } @@ -497,6 +528,13 @@ protected function connect_to_filesystem() { return true; } + /** + * To verify the valid child theme. + * + * @param array $child_theme_data Child Theme Data + * + * @return boolean + */ public function verify_child_theme( $child_theme_data ) { $child_theme_directory_exists = $this->verify_child_theme_directory( $child_theme_data['child_theme_dir'] ); if ( ! $child_theme_directory_exists ) { @@ -520,13 +558,28 @@ public function verify_child_theme( $child_theme_data ) { return true; } - public function verify_child_theme_directory( $child_theme_dir ) { + /** + * To verify the valid child theme directory. + * + * @param string $child_theme_dir Child Theme Directory + * + * @return boolean + */ + private function verify_child_theme_directory( $child_theme_dir ) { global $wp_filesystem; return $wp_filesystem->exists( $child_theme_dir ); } - public function verify_theme_json( $child_theme_json, $child_theme_dir ) { + /** + * To verify the valid child theme.json. + * + * @param string $child_theme_json Child Theme json + * @param string $child_theme_dir Child Theme Directory + * + * @return boolean + */ + private function verify_theme_json( $child_theme_json, $child_theme_dir ) { global $wp_filesystem; $theme_json_path = $child_theme_dir . '/theme.json'; @@ -542,7 +595,15 @@ public function verify_theme_json( $child_theme_json, $child_theme_dir ) { return true; } - public function verify_stylesheet( $child_theme_stylesheet_comment, $child_theme_dir ) { + /** + * To verify the valid style.css of the respective child theme + * + * @param string $child_theme_stylesheet_comment Child Theme stylesheet comment + * @param string $child_theme_dir Child Theme Directory + * + * @return boolean + */ + private function verify_stylesheet( $child_theme_stylesheet_comment, $child_theme_dir ) { global $wp_filesystem; $stylesheet_path = $child_theme_dir . '/style.css'; @@ -558,7 +619,14 @@ public function verify_stylesheet( $child_theme_stylesheet_comment, $child_theme return true; } - public function verify_child_theme_is_active( $child_theme_slug ) { + /** + * To verify the valid child theme is active. + * + * @param string $child_theme_slug Child Theme Slug + * + * @return boolean + */ + private function verify_child_theme_is_active( $child_theme_slug ) { $active_theme = ( \wp_get_theme() )->get( 'TextDomain' ); if ( $active_theme !== $child_theme_slug ) { return false;