';
// WP Admin link (if enabled and user has permission).
if ( $wp_admin && \mainwp_current_user_can( 'dashboard', 'access_wpadmin_on_child_sites' ) ) {
$admin_url = MainWP_Site_Open::get_open_site_url( $website->id, '', false );
$html .= '
';
} elseif ( $wp_admin ) {
$html .= '
';
}
// Site name with dashboard link.
$html .= '
' . $site_name . '';
// Site URL.
$html .= '
';
$html .= '
';
if ( $print_content ) {
echo $html; // phpcs:ignore -- ok.
return '';
}
return $html;
}
/**
* Generate a sortable BIGINT for WordPress versions.
* Newer versions produce larger numbers.
* Ordering matches WP core version_compare().
*
* @param string $version Version value.
*/
public function wp_versions_order_num( $version ) {
$v = strtolower( trim( $version ) );
// 1) Normalize WordPress aliases.
$v = str_replace(
array( '-alpha', '-beta', '-rc' ),
array( '-a', '-b', '-rc' ),
$v
);
// nightly / dev / trunk → dev.
if ( preg_match( '/-(nightly|dev|trunk)/', $v ) ) {
$v = preg_replace( '/-.+$/', '-dev', $v );
}
// unknown tags → dev.
if ( preg_match( '/-[a-z]+/', $v ) && ! preg_match( '/-(a|b|rc|dev)/', $v ) ) {
$v = preg_replace( '/-.+$/', '-dev', $v );
}
// 2) Extract numeric base version.
$base = explode( '-', $v, 2 )[0];
$parts = array_map( 'intval', explode( '.', $base ) );
if ( count( $parts ) < 4 ) {
$parts = array_pad( $parts, 4, 0 );
}
$versionNum =
( $parts[0] << 24 ) |
( $parts[1] << 16 ) |
( $parts[2] << 8 ) |
$parts[3];
// 3) Release channel rank (lower = newer).
$rank = 1; // stable.
if ( strpos( $v, '-rc' ) !== false ) {
$rank = 2;
} elseif ( strpos( $v, '-b' ) !== false ) {
$rank = 3;
} elseif ( strpos( $v, '-a' ) !== false ) {
$rank = 4;
} elseif ( strpos( $v, '-dev' ) !== false ) {
$rank = 5;
}
// 4) Prerelease / build number.
$build = 0;
if ( preg_match( '/rc(\d+)/', $v, $m ) ) {
$build = (int) $m[1];
} elseif ( preg_match( '/b(\d+)/', $v, $m ) ) { // NOSONAR - same above ok.
$build = (int) $m[1];
} elseif ( preg_match( '/a(\d+)/', $v, $m ) ) { // NOSONAR - same above ok.
$build = (int) $m[1];
}
// 5) Compose sortable BIGINT.
return ( $versionNum << 32 )
| ( $rank << 29 )
| min( $build, ( 1 << 29 ) - 1 );
}
/**
* Method handle gen_rand_id().
*
* @param string $str Input string.
* @param bool $more_entropy More entropy False if a robust prefix is required, default false.
* @return string Random ID 8 characters.
*/
public static function gen_rand_id( $str = '', $more_entropy = false ) {
return hash( 'crc32b', uniqid( $str, $more_entropy ? true : false ) );
}
/**
* Decode and validate JSON array.
*
* @param mixed $data Data to decode.
*/
public static function get_decoded_array( $data ) {
$decoded = ! empty( $data ) ? json_decode( $data, true ) : array();
return is_array( $decoded ) ? $decoded : array();
}
/**
* Method get_use_cron()
*
* @return bool Whether use cron.
*/
public static function get_use_cron() {
return ( get_option( 'mainwp_wp_cron' ) === false ) || ( (int) get_option( 'mainwp_wp_cron' ) === 1 ) ? 1 : 0;
}
}