get_var( $wpdb->prepare( 'SELECT GET_LOCK(%s, %d)', $name, 0 ) ); if ( null === $result ) { return null; } if ( '1' === (string) $result ) { return static function () use ( $wpdb, $name ): void { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Advisory locks must not be cached. $wpdb->get_var( $wpdb->prepare( 'SELECT RELEASE_LOCK(%s)', $name ) ); }; } } return false; } /** * The lock name of one slot. Advisory locks are server-wide, so the name * carries this site's database, table prefix and blog. * * @param int $slot Slot number, from 1. * @return string */ public static function lockName( int $slot ): string { global $wpdb; $prefix = isset( $wpdb ) && is_object( $wpdb ) && isset( $wpdb->prefix ) ? (string) $wpdb->prefix : ''; return 'aipt_chat_' . sha1( ( defined( 'DB_NAME' ) ? \DB_NAME : '' ) . ':' . $prefix . ':' . ( function_exists( 'get_current_blog_id' ) ? (int) \get_current_blog_id() : 0 ) ) . '_' . $slot; } }