diff --git a/inc/sites/installation.php b/inc/sites/installation.php index 2b4d6f8..8f1229a 100644 --- a/inc/sites/installation.php +++ b/inc/sites/installation.php @@ -15,6 +15,7 @@ use Figuren_Theater\Network\Users; use FT_CORESITES; use WP_Site; +use WP_User; use function add_action; use function apply_filters; use function check_admin_referer; @@ -124,7 +125,7 @@ function create_new__ft_site( WP_Site $new_site, array $args ): void { // Defined at wp-admin/network/site-new.php. check_admin_referer( 'add-blog', '_wpnonce_add-blog' ); - if ( isset( $_POST['ft_level'] ) && 0 < intval( $_POST['ft_level'] ) ) { + if ( isset( $_POST['ft_level'] ) && ( \is_string( $_POST['ft_level'] ) || \is_int( $_POST['ft_level'] ) ) && 0 < intval( $_POST['ft_level'] ) ) { $args['ft_level'] = (int) $_POST['ft_level']; } @@ -223,10 +224,13 @@ function set_imprint_page( WP_Site $new_site, array $args ): void { 'impressum_imprint_options', false ); - $remote_imprint_page_id = ( isset( $remote_impressum_imprint_options['page'] ) ) ? (int) $remote_impressum_imprint_options['page'] : false; + $remote_imprint_page_id = false; + if ( \is_array( $remote_impressum_imprint_options ) && isset( $remote_impressum_imprint_options['page'] ) && ( \is_string( $remote_impressum_imprint_options['page'] ) || \is_int( $remote_impressum_imprint_options['page'] ) ) ) { + $remote_imprint_page_id = (int) $remote_impressum_imprint_options['page']; + } // If we have nothing from remote, JUMP OUT. - if ( ! $remote_imprint_page_id ) { + if ( false === $remote_imprint_page_id ) { return; } @@ -239,17 +243,25 @@ function set_imprint_page( WP_Site $new_site, array $args ): void { // Run pulling. $imprint_page_id = $distributor->run(); - // Return on failure or set our option if everything was fine. + // Return on failure. if ( empty( $imprint_page_id ) || ! inc\helper::post_id_exists( (int) $imprint_page_id[0] ) ) { return; } // Prepare some data, which was collected during registration. - $person = get_userdata( $args['user_id'] ); + $person = get_userdata( (int) $args['user_id'] ); + + if ( ! $person instanceof WP_User ) { + return; + } // Get temporary data, collected during registration. $user_registration_data = $person->get( FeaturesRepo\TEMP_USER_META ); + if ( ! \is_array( $user_registration_data ) || ! isset( $user_registration_data['adr'] ) || empty( $user_registration_data['adr'] ) ) { + return; + } + $impressum_imprint_options = [ 'page' => (string) $imprint_page_id[0], 'country' => '', // Leave empty as it gets populated on save, if empty. @@ -284,20 +296,20 @@ function set_privacy_page(): void { // this is the one to pull. $ft_coresites_ids = array_flip( FT_CORESITES ); $remote_site_id = (int) $ft_coresites_ids['mein']; - $remote_policy_page_id = (int) get_blog_option( + $remote_policy_page_id = get_blog_option( $remote_site_id, 'wp_page_for_privacy_policy', false ); // If we have nothing from remote, JUMP OUT. - if ( ! $remote_policy_page_id ) { + if ( ! $remote_policy_page_id || ! ( \is_string( $remote_policy_page_id ) || \is_int( $remote_policy_page_id ) ) ) { return; } // Establish a connection and define pulling. - $distributor = new Sync\Pull( - [ $remote_policy_page_id ], + $distributor = new Sync\Pull( + [ \intval( $remote_policy_page_id ) ], $remote_site_id, 'page' ); diff --git a/phpstan.neon b/phpstan.neon index a1562e0..50b76e7 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -21,3 +21,18 @@ parameters: # Find a nicer way instead of ignoring this Error on every ft-module - '#Function Altis\\register_module not found\.#' - '#Function Figuren_Theater\\get_config not found\.#' + + # TODO https://github.com/figuren-theater/ft-onboarding/issues/29 Remove hard dependencies onto deprecated__Figuren_Theater__v2 + - '#Call to static method site\(\) on an unknown class Figuren_Theater\\FT\.#' + - '#Call to static method init\(\) on an unknown class Figuren_Theater\\FT_Query\.#' + - '#Call to static method id\(\) on an unknown class Figuren_Theater\\Network\\Users\\ft_bot\.#' + - '#Constant FT_CORESITES not found\.#' + - '#Access to constant NAME on an unknown class Figuren_Theater\\Network\\Admin_UI\\Color_Scheme\.#' + - '#Call to method run\(\) on an unknown class Figuren_Theater\\Network\\Sync\\Pull\.#' + - '#Instantiated class Figuren_Theater\\Network\\Sync\\Pull not found\.#' + - '#Instantiated class Figuren_Theater\\Network\\Post_Types\\Post_Type__ft_site not found\.#' + - '#Access to constant NAME on an unknown class Figuren_Theater\\Coresites\\Post_Types\\Post_Type__ft_level\.#' + - '#Call to static method post_id_exists\(\) on an unknown class Figuren_Theater\\inc\\helper\.#' + - '#Instantiated class Figuren_Theater\\inc\\Geo\\ft_geo_options_bridge not found\.#' + - '#Call to method update_option_ft_geo\(\) on an unknown class Figuren_Theater\\inc\\Geo\\ft_geo_options_bridge\.#' + - '#Constant Figuren_Theater\\FeaturesRepo\\TEMP_USER_META not found\.#' \ No newline at end of file