*/ public static function rows(): array { $rows = [ [ 'label' => __( 'Plugin version', 'flexa-local-services' ), 'value' => FXLC_VERSION, 'state' => 'ok', ], [ 'label' => __( 'WordPress', 'flexa-local-services' ), 'value' => (string) get_bloginfo( 'version' ), 'state' => 'ok', ], [ // WordPress refuses to activate the plugin below the version in // its header, so reaching this screen means PHP is adequate. 'label' => __( 'PHP', 'flexa-local-services' ), 'value' => PHP_VERSION, 'state' => 'ok', ], self::schema_row(), self::tables_row(), self::permalinks_row(), ]; /** @var list $filtered */ $filtered = apply_filters( 'fxlc_system_status', $rows ); return $filtered; } /** * @return array{label:string,value:string,state:string,hint?:string} */ private static function schema_row(): array { $stored = (int) get_option( Migrator::VERSION_OPTION, 0 ); $ok = Migrator::DB_VERSION === $stored; return [ 'label' => __( 'Database schema', 'flexa-local-services' ), 'value' => $ok /* translators: %d: database schema version number. */ ? sprintf( __( 'Version %d', 'flexa-local-services' ), $stored ) /* translators: 1: installed schema version, 2: expected schema version. */ : sprintf( __( 'Version %1$d, expected %2$d', 'flexa-local-services' ), $stored, Migrator::DB_VERSION ), 'state' => $ok ? 'ok' : 'warn', 'hint' => $ok ? '' : __( 'Reload any admin page to run the upgrade.', 'flexa-local-services' ), ]; } /** * @return array{label:string,value:string,state:string,hint?:string} */ private static function tables_row(): array { global $wpdb; $missing = []; foreach ( self::TABLES as $table ) { $name = $wpdb->prefix . $table; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- SHOW TABLES has no WP API, and a cached answer is worthless here: the screen exists to say whether the tables are there now. $found = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $name ) ); if ( $name !== $found ) { $missing[] = $table; } } if ( [] === $missing ) { return [ 'label' => __( 'Database tables', 'flexa-local-services' ), 'value' => sprintf( /* translators: %d: number of database tables. */ _n( '%d table in place', '%d tables in place', count( self::TABLES ), 'flexa-local-services' ), count( self::TABLES ) ), 'state' => 'ok', ]; } return [ 'label' => __( 'Database tables', 'flexa-local-services' ), 'value' => implode( ', ', $missing ), 'state' => 'error', 'hint' => __( 'Deactivate and reactivate the plugin to recreate them.', 'flexa-local-services' ), ]; } /** * Plain permalinks leave the CPT archives unreachable and push every REST * call through the query-string route, which some hosts strip. * * @return array{label:string,value:string,state:string,hint?:string} */ private static function permalinks_row(): array { $structure = (string) get_option( 'permalink_structure', '' ); return [ 'label' => __( 'Permalinks', 'flexa-local-services' ), 'value' => '' !== $structure ? $structure : __( 'Plain', 'flexa-local-services' ), 'state' => '' !== $structure ? 'ok' : 'warn', 'hint' => '' !== $structure ? '' : __( 'Switch Settings, Permalinks to any option other than Plain so service and area pages get clean URLs.', 'flexa-local-services' ), ]; } }